ios - 解析 ios 9 Swift 2 - 应用程序委托(delegate)错误

标签 ios swift parse-platform

对于 iOS 9 Swift 2 xcode 7.1,Parse 的文档代码目前不是最新的吗?最后两个函数都有错误提示“定义与先前值冲突”

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

    Parse.setApplicationId("key",
        clientKey: "key")

    // Register for Push Notitications
    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 pushPayload = false
        if let options = launchOptions {
            pushPayload = options[UIApplicationLaunchOptionsRemoteNotificationKey] != nil
        }
        if (preBackgroundPush || oldPushHandlerOnly || pushPayload) {
            PFAnalytics.trackAppOpenedWithLaunchOptions(launchOptions)
        }
    }

    func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
        // Store the deviceToken in the current Installation and save it to Parse
        let installation = PFInstallation.currentInstallation()
        installation.setDeviceTokenFromData(deviceToken)
        installation.saveInBackground()
    }

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

    func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
        PFPush.handlePush(userInfo)
        if application.applicationState == UIApplicationState.Inactive {
            PFAnalytics.trackAppOpenedWithRemoteNotificationPayload(userInfo)
        }
    }

最佳答案

最后 3 个函数应该在 didFinishLaunchingWithOptions 函数之外。

关于ios - 解析 ios 9 Swift 2 - 应用程序委托(delegate)错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33602689/

相关文章:

ios - 对不同的页面 View 使用相同的 ViewController Swift

ios - CloudKit:查询索引(recordID.recordName)

ios - 如何计算iOS应用程序启动时间

ios - 为什么不写optional mark就可以声明一个变量?

ios - 如何回到 Root View Controller

swift - 从 Parse 下载后无法流式传输视频

ios - 如何从不同的 swift 文件调用函数

swift - 在解析中存储引号

ios - bolt 异步框架方法无法识别

ios - 检查应用程序是否通过 iOS 上的今日小部件启动...?