![](/img/trans.png)
[英]Twitter signin error in react-native-twitter-signin in iOS only
[英]Exception when initializing react-native-twitter-signin
感謝上面的 Rahul Mishra 提供了他的代碼,我找到了解決方案。 我犯了一個錯誤RNTwitterSignIn.init(Constants.TWITTER_COMSUMER_KEY, Constants.TWITTER_CONSUMER_SECRET
在異步函數中調用RNTwitterSignIn.init(Constants.TWITTER_COMSUMER_KEY, Constants.TWITTER_CONSUMER_SECRET
。這對 android 有效,但對 ios 沒有任何反應。但是在我用他的代碼更改了代碼之后,這使我意識到了我的錯誤。謝謝再次
這是我的 react-native-twitter-signin 的完整代碼,它適用於 iOS 和 android:我在下面的代碼中調用的類的頂部:
const { RNTwitterSignIn } = NativeModules
const Constants = {
//Dev Parse keys
TWITTER_COMSUMER_KEY: "************************",
TWITTER_CONSUMER_SECRET: "********************************************************"
}
這是我的查看文件按鈕:
<TouchableOpacity onPress={() => this.twitterSignIn()}>
<Image style={styles.socialBtn} source={require('../images/twitter.png')}/>
</TouchableOpacity>
我在這里調用 twitterSignIn 函數:
twitterSignIn = () => {
const fcmSocialToken = this.state.tokenFcm;
RNTwitterSignIn.init(Constants.TWITTER_COMSUMER_KEY, Constants.TWITTER_CONSUMER_SECRET)
RNTwitterSignIn.logIn()
.then(loginData => {
const { authToken, authTokenSecret } = loginData
if (authToken && authTokenSecret) {
// You can use this data here and move next
}
})
.catch(error => {
console.log(error)
}
)
}
對於 iOS,您需要更新 info.plist:
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>twitterkit-YCZNs*********</string>
<string>fb**********</string>
</array>
</dict>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>com.googleusercontent.apps.************</string>
</array>
</dict>
</array>
如果有任何問題,請告訴我。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.