我正在安装一个facebook登录来解析。https://www.parse.com/docs/ios/guide#users-facebook-users上的解析网站说:
您还需要进行两处代码更改。首先,在初始化Parse SDK之后,将以下代码添加到应用程序中:didFinishLaunchingWithOptions: method。
// Import this header into your Swift bridge header file
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <ParseFacebookUtilsV4/PFFacebookUtils.h>
// AppDelegate.swift
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
Parse.setApplicationId("parseAppId", clientKey:"parseClientKey")
PFFacebookUtils.initializeFacebookWithLaunchOptions(launch Options)
}AppDelegate.swift中的parsestaterproject表示:
// If you are using Facebook, uncomment and add your FacebookAppID to your bundle's plist as
// described here: https://developers.facebook.com/docs/getting- started/facebook-sdk-for-ios/
// Uncomment the line inside ParseStartProject- Bridging-Header and the following line here:
//PFFacebookUtils.initializeFacebook()我已经尝试了两个*.initializeFacebook选项,但都给出了相同的错误:'PFFacebookUtils.Type‘没有名为'initializeFacebook ...’的成员。
我的代码是:
// AppDelegate.swift
//
// Copyright 2011-present Parse Inc. All rights reserved.
//
import UIKit
import Bolts
import Parse
// If you want to use any of the UI components, uncomment this line
// import ParseUI
// If you want to use Crash Reporting - uncomment this line
// import ParseCrashReporting
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
//--------------------------------------
// MARK: - UIApplicationDelegate
//--------------------------------------
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
Parse.enableLocalDatastore()
// ********************************************************** ******************
// Uncomment this line if you want to enable Crash Reporting
// ParseCrashReporting.enable()
Parse.setApplicationId("RETRACTED_FOR_SECURITY", clientKey: "RETRACTED_FOR_SECURITY")
// var pushSettings: UIUserNotificationSettings = UIUserNotificationSettings(forTypes: .Alert, categories: nil)
// application.registerForRemoteNotifications(pushSettings)
// application.registerForRemoteNotifications()
//
// If you are using Facebook, uncomment and add your FacebookAppID to your bundle's plist as
// described here: https://developers.facebook.com/docs/getting-started/facebook-sdk-for-ios/
// Uncomment the line inside ParseStartProject-Bridging-Header and the following line here:
//PFFacebookUtils.initializeFacebook()
PFFacebookUtils.initializeFacebookWithLaunchOptions(launchOptions)
// ****************************************************************************
PFUser.enableAutomaticUser()
let defaultACL = PFACL();
// If you would like all objects to be private by default, remove this line.
defaultACL.setPublicReadAccess(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)
}
}
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)
}
return true
}
//--------------------------------------
// MARK: Push Notifications
//--------------------------------------
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
let installation = PFInstallation.currentInstallation()
installation.setDeviceTokenFromData(deviceToken)
installation.saveInBackground()
PFPush.subscribeToChannelInBackground("", block: { (succeeded: Bool, error: NSError?) -> Void in
if succeeded {
println("ParseStarterProject successfully subscribed to push notifications on the broadcast channel.");
} else {
println("ParseStarterProject failed to subscribe to push notifications on the broadcast channel with error = %@.", error)
}
})
}
func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) {
if error.code == 3010 {
println("Push notifications are not supported in the iOS Simulator.")
} else {
println("application:didFailToRegisterForRemoteNotificationsWithError: %@", 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 application(application: UIApplication,
openURL url: NSURL,
sourceApplication: String?,
annotation: AnyObject?) -> Bool {
return FBSDKApplicationDelegate.sharedInstance().application(application,
openURL: url,
sourceApplication: sourceApplication,
annotation: annotation)
}
func applicationDidBecomeActive(application: UIApplication) {
FBSDKAppEvents.activateApp()
}
}我的app-bridging h文件是:
// ParseStarterProject-Bridging-Header.h
//
// Copyright 2011-present Parse Inc. All rights reserved.
//
#define ParseStarterProject_Bridging_Header_h
#define ParseStarterProject_Bridging_Header_h
// If you are using Facebook, uncomment this line to get automatic import of the header inside your project.
//#import <ParseFacebookUtils/PFFacebookUtils.h>
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <ParseFacebookUtilsV4/PFFacebookUtils.h>
#endif发布于 2015-05-22 01:47:45
我找到了。应该是: PFFacebookUtils.initializeFacebookWithApplicationLaunchOptions(launchOptions).但请注意,虽然这解决了这个错误,但上面的代码仍然导致另一个错误,我将在另一个线程中发布该错误:链接器命令失败,退出代码为1(使用-v查看调用)-
https://stackoverflow.com/questions/30367061
复制相似问题