iOS Facebook登录崩溃
我正在使用FBSDK 4.32.0,它在iOS 11.3版本中不断崩溃,请帮助我,我尝试过不同的设备,它们有不同的iOS版本,不幸的是,所有的版本都崩溃了,下面是我的代码iOS Facebook登录崩溃,ios,swift,fbsdk,Ios,Swift,Fbsdk,我正在使用FBSDK 4.32.0,它在iOS 11.3版本中不断崩溃,请帮助我,我尝试过不同的设备,它们有不同的iOS版本,不幸的是,所有的版本都崩溃了,下面是我的代码 @IBAction func didTapLogainAction(_ sender: Any) { let fbLoginManager : FBSDKLoginManager = FBSDKLoginManager() fbLoginManager.logIn(withReadPermissions
@IBAction func didTapLogainAction(_ sender: Any) {
let fbLoginManager : FBSDKLoginManager = FBSDKLoginManager()
fbLoginManager.logIn(withReadPermissions: ["email"], from: self) { (result, error) in
if (error == nil){
let fbloginresult : FBSDKLoginManagerLoginResult = result!
if fbloginresult.grantedPermissions != nil {
if(fbloginresult.grantedPermissions.contains("email")) {
if((FBSDKAccessToken.current()) != nil){
FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "id, name, first_name, last_name, picture.type(large), email"]).start(completionHandler: { (connection, result, error) -> Void in
if (error == nil){
let dict = result as! [String : AnyObject]
let alrt = UIAlertController(title: "Success", message: "Logged in", preferredStyle: .alert)
let alrtDon = UIAlertAction(title: "Done", style: .default, handler: {(alert: UIAlertAction!) in
print("Perfect")
})
alrt.addAction(alrtDon)
self.present(alrt, animated: true, completion: nil)
FBSDKLoginManager().logOut()
self.LoginViaFacebook(dict: dict as NSDictionary)
}
})
}
}
}
}
}
}
试试这个代码。这对我有用。更多信息
导入FacebookLogin
导入FacebookCore
导入FBSDKCoreKit
//马克:用Facebook登录
func loginWithFacebook(controllerName:UIViewController,完成:@escaping(uIsAccess:Bool,uResponse:Any,uCheckInternet:String)->Void)
{
/*这里有三件事是必须的
1.FacebookAppId
2.FaceBook显示名称
3.将URL架构添加到infor plist文件中。
CfBundleUrlTypeCfBundleTypeRoleEditorCfBundleUrlSchemes
-----------------------FB123123---------------------
*/
FBSDKSettings.setAppID(FacebookAppID)
FBSDKSettings.setDisplayName(FacebookDisplayName)
让loginManager=loginManager()
登录(readPermissions:[.publicProfile,.email],viewController:controllerName){(loginResult)在
如果loginResult.self!=nil{
let request=GraphRequest(graphPath:/me),参数:[“字段”:“id、电子邮件、姓名、姓氏、图片、年龄范围、性别、区域设置、链接、时区、更新的时间、验证的地址、生日”]、accessToken:accessToken.current、httpMethod:.GET、apiVersion:FacebookCore.GraphaDriversion.defaultVersion)
request.start{(响应、结果)在
打印(结果)
切换结果{
成功案例(let value):
如果value.dictionaryValue!=nil{
完成(true,value.dictionaryValue!,“”)
}否则
{
完成(假,“,”)
}
案例。失败(let错误):
完成(false,“\(错误)”,“”)
}
}
}否则
{
完成(假,“,”)
}
}
}
在“AppDelegate”文件中,替换函数
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
// your code here
return true
}
借
它适合我。在appdelegate复制中,首先粘贴此代码
AppDelegate.swift File
import FBSDKCoreKit
import FBSDKLoginKit
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
return true
}
func application(_ application: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
let handled: Bool = FBSDKApplicationDelegate.sharedInstance().application(application, open: url, sourceApplication: options[.sourceApplication] as? String, annotation: options[.annotation])
return handled
}
现在将其粘贴到Viewcontroller上,并链接到按钮操作
@IBAction func loginWithFB(_ sender: Any) {
// let loginManager = FBSDKLoginManager()
//
// loginManager.logIn(withReadPermissions:["public_profile","user_friends","email"], from: self) {
// loginResult,error in
//
// print("completion handler called")
// }
let loginManager = FBSDKLoginManager()
loginManager.logIn(withReadPermissions: [ "public_profile" ,"email" ], from: self) { loginResult,error in
if error != nil {
print("error")
}else if(loginResult?.isCancelled)!{
print("result cancelled")
}else {
print("success")
FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "id, name, first_name, last_name, email"]).start(completionHandler: { (connection, result, error) -> Void in
if (error == nil){
let fbDetails = result as! NSDictionary
print(fbDetails)
}else{
print(error?.localizedDescription ?? "Not found")
}
})
}
}
}
如果您遇到问题,请仍然告诉我是否显示与此相关的碰撞报告?
AppDelegate.swift File
import FBSDKCoreKit
import FBSDKLoginKit
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
return true
}
func application(_ application: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
let handled: Bool = FBSDKApplicationDelegate.sharedInstance().application(application, open: url, sourceApplication: options[.sourceApplication] as? String, annotation: options[.annotation])
return handled
}
@IBAction func loginWithFB(_ sender: Any) {
// let loginManager = FBSDKLoginManager()
//
// loginManager.logIn(withReadPermissions:["public_profile","user_friends","email"], from: self) {
// loginResult,error in
//
// print("completion handler called")
// }
let loginManager = FBSDKLoginManager()
loginManager.logIn(withReadPermissions: [ "public_profile" ,"email" ], from: self) { loginResult,error in
if error != nil {
print("error")
}else if(loginResult?.isCancelled)!{
print("result cancelled")
}else {
print("success")
FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "id, name, first_name, last_name, email"]).start(completionHandler: { (connection, result, error) -> Void in
if (error == nil){
let fbDetails = result as! NSDictionary
print(fbDetails)
}else{
print(error?.localizedDescription ?? "Not found")
}
})
}
}
}