2016-04-25 115 views
0

我一直在嘗試創建一個Tinder克隆應用程序。現在我必須登錄到我的Facebook帳戶,抓住我的個人資料,並顯示我的顯示圖片。Swift和iOS9中的Facebook登錄問題

我導入了最新的FBSDK,確認我的plist(Plist screenshot)正確,並使用graphRequest函數來拉我的個人資料圖片,但我不斷收到以下錯誤。

-canOpenURL: failed for URL: "fbauth2:/" - error: "(null)"

我已經打掃我的身材,重新啓動我的模擬器,重新啓動我的機器,完全註釋掉我解析的代碼。

我已經取消了所有的解析代碼(我通過Heroku部署),以免簡化代碼。

我已經谷歌搜索了這個問題,並搜索堆棧溢出和github超過2周,還沒有找到解決方案。

我看了一下這個問題是怎麼紅鯡魚因與iOS 9

我想知道我做錯了Facebook的SDK集成的意見。我是編碼新手,需要一些幫助。我現在想要實現的就是登錄到我的Facebook帳戶(我可以這樣做),授權我的應用程序(我也可以這樣做)並在UiImageView中查看我的個人資料圖片(我不能這麼做)。這樣我就可以隨着我的課程繼續構建應用程序。

/** 
* Copyright (c) 2015-present, Parse, LLC. 
* All rights reserved. 
* 
* This source code is licensed under the BSD-style license found in the 
* LICENSE file in the root directory of this source tree. An additional grant 
* of patent rights can be found in the PATENTS file in the same directory. 
*/ 

//current project 02-04-16 

import UIKit 
import Parse 
import Bolts 
import FBSDKCoreKit 
import FBSDKLoginKit 
import ParseFacebookUtilsV4 


// If you want to use any of the UI components, uncomment this line 
// import ParseUI 

// deleted parseFacebookUtils and added ParseFacebookUtilsV4 so that PFFacebookUtils.intializeFacebookWithLaunchOptions would work. Replace parseFacebookUtils if needed to go back to old code (19-04-16). 

@UIApplicationMain 
class AppDelegate: UIResponder, UIApplicationDelegate { 

    var window: UIWindow? 

    //-------------------------------------- 
    // MARK: - UIApplicationDelegate 
    //-------------------------------------- 



    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 
     // Enable storing and querying data from Local Datastore. 
     // Remove this line if you don't want to use Local Datastore features or want to use cachePolicy. 

//  Parse.enableLocalDatastore() 
//   
//  let parseConfiguration = ParseClientConfiguration(block: { (ParseMutableClientConfiguration) -> Void in 
//    
//   ParseMutableClientConfiguration.applicationId = "tinder9121hughglass1234" 
//   ParseMutableClientConfiguration.clientKey = "sam123456hibabina" 
//   ParseMutableClientConfiguration.server = "https://tinder-sam2.herokuapp.com//parse" 


      PFFacebookUtils.initializeFacebookWithApplicationLaunchOptions(launchOptions) 



//   Uncomment these lines if you want to enable Parse 
//   PFUser.enableAutomaticUser() 
//    
// 
//   PFUser.logOut() 

//   let defaultACL = PFACL(); 


      //this is the current project 23-03-16 


//   PFUser.enableAutomaticUser() 
//   Parse.setApplicationId("tinder9121hughglass1234", clientKey: "sam123456hibabina") 



      //this code has been // temporarily 05-04-16 *** 

//    
//   let fbLoginManager : FBSDKLoginManager = FBSDKLoginManager() 
//   fbLoginManager.logInWithReadPermissions(["public_profile"], handler: { (result, error) in 
//    
//     
//   }) 
//    
//   PFUser.enableAutomaticUser() 
//    
//    

//  }) 

//   edited again here! 
//  let PFObject = PFUser.currentUser() 
// 
//  PFUser.enableAutomaticUser() 
// 
//  let acl = PFACL() 
//  acl.publicReadAccess = true 
//  acl.publicWriteAccess = true 
//  PFObject?.ACL = acl 

//  let defaultACL = PFACL(); 

     // If you would like all objects to be private by default, remove this line. 
//  defaultACL.publicReadAccess = true 

//  PFACL.setDefaultACL(defaultACL, withAccessForCurrentUser: true) 

     if application.applicationState != UIApplicationState.Background { 
      // Track an app open here if we launch with a push, unless 
      // "content_available" was used to trigger a background push (introduced in iOS 7). 
      // In that case, we skip tracking here to avoid double counting the app-open. 

      let preBackgroundPush = !application.respondsToSelector("backgroundRefreshStatus") 
      let oldPushHandlerOnly = !self.respondsToSelector("application:didReceiveRemoteNotification:fetchCompletionHandler:") 
      var noPushPayload = false; 
      if let options = launchOptions { 
       noPushPayload = options[UIApplicationLaunchOptionsRemoteNotificationKey] != nil; 
      } 
      if (preBackgroundPush || oldPushHandlerOnly || noPushPayload) { 
       PFAnalytics.trackAppOpenedWithLaunchOptions(launchOptions) 
      } 
     } 

     // 
     // Swift 1.2 
     // 
     //  if application.respondsToSelector("registerUserNotificationSettings:") { 
     //   let userNotificationTypes = UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound 
     //   let settings = UIUserNotificationSettings(forTypes: userNotificationTypes, categories: nil) 
     //   application.registerUserNotificationSettings(settings) 
     //   application.registerForRemoteNotifications() 
     //  } else { 
     //   let types = UIRemoteNotificationType.Badge | UIRemoteNotificationType.Alert | UIRemoteNotificationType.Sound 
     //   application.registerForRemoteNotificationTypes(types) 
     //  } 

     // 
     // Swift 2.0 
     // 
     //  if #available(iOS 8.0, *) { 
     //   let types: UIUserNotificationType = [.Alert, .Badge, .Sound] 
     //   let settings = UIUserNotificationSettings(forTypes: types, categories: nil) 
     //   application.registerUserNotificationSettings(settings) 
     //   application.registerForRemoteNotifications() 
     //  } else { 
     //   let types: UIRemoteNotificationType = [.Alert, .Badge, .Sound] 
     //   application.registerForRemoteNotificationTypes(types) 
     //  } 

     return FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions) 

    } 

    //-------------------------------------- 
    // MARK: Push Notifications 
    //-------------------------------------- 

    func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) { 
     let installation = PFInstallation.currentInstallation() 
     installation.setDeviceTokenFromData(deviceToken) 
     installation.saveInBackground() 

     PFPush.subscribeToChannelInBackground("") { (succeeded: Bool, error: NSError?) in 
      if succeeded { 
       print("ParseStarterProject successfully subscribed to push notifications on the broadcast channel.\n"); 
      } else { 
       print("ParseStarterProject failed to subscribe to push notifications on the broadcast channel with error = %@.\n", error) 
      } 
     } 
    } 

    func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) { 
     if error.code == 3010 { 
      print("Push notifications are not supported in the iOS Simulator.\n") 
     } else { 
      print("application:didFailToRegisterForRemoteNotificationsWithError: %@\n", error) 
     } 
    } 

    func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) { 
     PFPush.handlePush(userInfo) 
     if application.applicationState == UIApplicationState.Inactive { 
      PFAnalytics.trackAppOpenedWithRemoteNotificationPayload(userInfo) 
     } 
    } 
    /////////////////////////////////////////////////////////// 
    // Uncomment this method if you want to use Push Notifications with Background App Refresh 
    /////////////////////////////////////////////////////////// 
    // func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) { 
    //  if application.applicationState == UIApplicationState.Inactive { 
    //   PFAnalytics.trackAppOpenedWithRemoteNotificationPayload(userInfo) 
    //  } 
    // } 

    //-------------------------------------- 
    // MARK: Facebook SDK Integration 
    //-------------------------------------- 

    /////////////////////////////////////////////////////////// 
    // Uncomment this method if you are using Facebook 
    /////////////////////////////////////////////////////////// 
    // func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject?) -> Bool { 
    //  return FBAppCall.handleOpenURL(url, sourceApplication:sourceApplication, session:PFFacebookUtils.session()) 
    // } 

    func applicationDidBecomeActive(application: UIApplication) { 

     FBSDKAppEvents.activateApp() 
    } 
    func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, 
     annotation: AnyObject) -> Bool { 

     return FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation) 

    } 
} 

回答

0

嘗試加入這一行到您的Info.plist<string>fbauth2</string>

Info.plist

+0

三江源奏效停止錯誤消息。現在讓應用程序顯示我的個人資料圖片。謝謝! – user2873543