1、在苹果开发者后台将Sign in with Apple 打开;
开发者网址:https://developer.apple.com
2、在Xcode里面设置一下
3、将一下代码导入IOS项目:
具体代码在GitHub:https://github.com/JonsonHI/SignWithApple(原作者)
4、如上操作,都已经完成则在RN代码,所需位置引入一下模块:
import { requireNativeComponent} from 'react-native';
//导入封装好的方法
var NativeView = requireNativeComponent('SignWithApple');
5、js代码进行调用:
{Utils.size.os === 'ios' ?
<View style={{flex: 1, justifyContent: 'flex-end', paddingLeft: 10,paddingRight:10,paddingBottom: 150,}}>
<TouchableOpacity style={{JustifyContent: 'center', alignItems: 'center', }}>
<NativeView
style={{width: 260, height:60}}
onClick={(info)=>{
if(info.nativeEvent.success){
alert(info.nativeEvent.success)
}else if(info.nativeEvent.error){
alert(info.nativeEvent.error)
}
}}
>
<Image style={styles.appleIcon} source={require('../Image/Login/icon_login.png')}/> //可换成自己的图
</NativeView>
</TouchableOpacity>
</View>
:
null
}
6、最终实现效果如下:
7、详细可参考文档:https://www.jianshu.com/p/6dec7972267b
8、作者是个好人,解决了个官方文档没有的大问题哦????