React Native Facebook 登录按钮使 iOS 模拟器中的应用程序崩溃
React Native Facebook login button crashes app in iOS Simulator
我正在尝试使用 FBSDK 在我的 React Native iOS 应用程序中设置 Facebook 登录。该按钮呈现,但单击时会使 iOS 模拟器中的应用程序崩溃。它甚至不在远程调试器中记录任何错误。
我在 xcode 中将 FBSDKCoreKit.framework 和 FBSDKLoginKit.framework 添加到我的项目中,并遵循 this guide 如何修改我的 info.plist
和 AppDelegate.m
我的按钮代码有问题吗?
import React, { Component } from 'react'
import { View } from 'react-native'
import FBSDK from 'react-native-fbsdk'
const { LoginButton } = FBSDK
import styles from '../styles'
export default class Login extends Component {
constructor (props) {
super(props)
this.onLoginFinished = this.onLoginFinished.bind(this)
}
onLoginFinished (error, result) {
if (error) {
console.log(error)
alert("Login failed with error: " + error);
} else if (result.isCancelled) {
alert("Login was cancelled");
} else {
alert("Login was successful with permissions: " + result)
}
}
render () {
return (
<View style={styles.container}>
<LoginButton
publishPermissions={["public_profile"]}
onLoginFinished={this.onLoginFinished}
onLogoutFinished={() => alert("User logged out")}
/>
</View>
)
}
}
编辑
根据 Andreyco
的评论添加来自 运行 react-native log-ios
的日志
<Error>: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Read permissions are not permitted to be requested with publish or manage permissions.'
*** First throw call stack:
(
0 CoreFoundation 0x00000001102ce34b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000010f1dc21e objc_exception_throw + 48
2 CoreFoundation 0x00000001102ce299 -[NSException raise] + 9
3 FunDates 0x000000010e860c05 -[FBSDKLoginManager logInWithPublishPermissions:fromViewController:handler:] + 228
4 FunDates 0x000000010e85d523 -[FBSDKLoginButton _buttonPressed:] + 1662
5 UIKit 0x000000011284b5b8 -[UIApplication sendAction:to:from:forEvent:] + 83
6 UIKit 0x00000001129d0edd -[UIControl sendAction:to:forEvent:] + 67
7 UIKit 0x00000001129d11f6 -[UIControl _sendActionsForEvents:withEvent:] + 444
8 UIKit 0x00000001129d00f2 -[UIControl touchesEnded:withEvent:] + 668
9 UIKit 0x00000001128b8ce1 -[UIWindow _sendTouchesForEvent:] + 2747
10 UIKit 0x00000001128ba3cf -[UIWindow sendEvent:] + 4011
11 UIKit 0x000000011286763f -[UIApplication sendEvent:] + 371
12 UIKit 0x000000011305971d __dispatchPreprocessedEventFromEventQueue + 3248
13 UIKit 0x00000001130523c7 __handleEventQueue + 4879
14 CoreFoundation 0x0000000110273311 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
15 CoreFoundation 0x000000011025859c __CFRunLoopDoSources0 + 556
16 CoreFoundation 0x0000000110257a86 __CFRunLoopRun + 918
17 CoreFoundation 0x0000000110257494 CFRunLoopRunSpecific + 420
18 GraphicsServices 0x0000000116095a6f GSEventRunModal + 161
19 UIKit 0x0000000112849964 UIApplicationMain + 159
20 FunDates 0x000000010e69f9bf main + 111
21 libdyld.dylib 0x000000011421668d start + 1
22 ??? 0x0000000000000001 0x0 + 1
)
我需要将 publishPermissions
更改为 readPermissions
<LoginButton
readPermissions={["public_profile email"]}
onLoginFinished={this.loginFinished.bind(this)}
onLogoutFinished={() => alert("User logged out")}
/>
我正在尝试使用 FBSDK 在我的 React Native iOS 应用程序中设置 Facebook 登录。该按钮呈现,但单击时会使 iOS 模拟器中的应用程序崩溃。它甚至不在远程调试器中记录任何错误。
我在 xcode 中将 FBSDKCoreKit.framework 和 FBSDKLoginKit.framework 添加到我的项目中,并遵循 this guide 如何修改我的 info.plist
和 AppDelegate.m
我的按钮代码有问题吗?
import React, { Component } from 'react'
import { View } from 'react-native'
import FBSDK from 'react-native-fbsdk'
const { LoginButton } = FBSDK
import styles from '../styles'
export default class Login extends Component {
constructor (props) {
super(props)
this.onLoginFinished = this.onLoginFinished.bind(this)
}
onLoginFinished (error, result) {
if (error) {
console.log(error)
alert("Login failed with error: " + error);
} else if (result.isCancelled) {
alert("Login was cancelled");
} else {
alert("Login was successful with permissions: " + result)
}
}
render () {
return (
<View style={styles.container}>
<LoginButton
publishPermissions={["public_profile"]}
onLoginFinished={this.onLoginFinished}
onLogoutFinished={() => alert("User logged out")}
/>
</View>
)
}
}
编辑
根据 Andreyco
的评论添加来自 运行react-native log-ios
的日志
<Error>: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Read permissions are not permitted to be requested with publish or manage permissions.'
*** First throw call stack:
(
0 CoreFoundation 0x00000001102ce34b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000010f1dc21e objc_exception_throw + 48
2 CoreFoundation 0x00000001102ce299 -[NSException raise] + 9
3 FunDates 0x000000010e860c05 -[FBSDKLoginManager logInWithPublishPermissions:fromViewController:handler:] + 228
4 FunDates 0x000000010e85d523 -[FBSDKLoginButton _buttonPressed:] + 1662
5 UIKit 0x000000011284b5b8 -[UIApplication sendAction:to:from:forEvent:] + 83
6 UIKit 0x00000001129d0edd -[UIControl sendAction:to:forEvent:] + 67
7 UIKit 0x00000001129d11f6 -[UIControl _sendActionsForEvents:withEvent:] + 444
8 UIKit 0x00000001129d00f2 -[UIControl touchesEnded:withEvent:] + 668
9 UIKit 0x00000001128b8ce1 -[UIWindow _sendTouchesForEvent:] + 2747
10 UIKit 0x00000001128ba3cf -[UIWindow sendEvent:] + 4011
11 UIKit 0x000000011286763f -[UIApplication sendEvent:] + 371
12 UIKit 0x000000011305971d __dispatchPreprocessedEventFromEventQueue + 3248
13 UIKit 0x00000001130523c7 __handleEventQueue + 4879
14 CoreFoundation 0x0000000110273311 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
15 CoreFoundation 0x000000011025859c __CFRunLoopDoSources0 + 556
16 CoreFoundation 0x0000000110257a86 __CFRunLoopRun + 918
17 CoreFoundation 0x0000000110257494 CFRunLoopRunSpecific + 420
18 GraphicsServices 0x0000000116095a6f GSEventRunModal + 161
19 UIKit 0x0000000112849964 UIApplicationMain + 159
20 FunDates 0x000000010e69f9bf main + 111
21 libdyld.dylib 0x000000011421668d start + 1
22 ??? 0x0000000000000001 0x0 + 1
)
我需要将 publishPermissions
更改为 readPermissions
<LoginButton
readPermissions={["public_profile email"]}
onLoginFinished={this.loginFinished.bind(this)}
onLogoutFinished={() => alert("User logged out")}
/>