Xcode,Parse – 处理远程通知

我正在尝试按照Parse指南来处理我以Json格式发送的通知,但我遇到了问题,这是我的代码
func application(application: UIApplication,didFinishLaunchingWithOptions launchOptions: NSDictionary!) -> Bool {
        // Override point for customization after application launch.
        Parse.setApplicationId("MyAppId",clientKey: "MyAppClientKey")

        var notificationType: UIUserNotificationType = UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.sound

        var settings: UIUserNotificationSettings = UIUserNotificationSettings(forTypes: notificationType,categories: nil)
        UIApplication.sharedApplication().registerUserNotificationSettings(settings)
        UIApplication.sharedApplication().registerForRemoteNotifications()

if let launchOptions = launchOptions {
    var notificationPayload: NSDictionary = launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey] as NSDictionary!
    println(launchOptions)

    var url = notificationPayload["url"] as String

    var Feed: FeedTableViewController = FeedTableViewController()
    Feed.messages.insert(url,atIndex: 0)
    Feed.sections.insert("section",atIndex: 0)
    }


        return true
    }

该应用程序现在不会崩溃,但我所做的更改不会发生.
Json代码

{
    "aps": {
         "badge": 10,"alert": "Test","sound": "cat.caf"
    },"url": "http://www.google.com"
}

解决方法

我猜你的问题在这里
launchOptions(UIApplicationLaunchOptionsRemoteNotificationKey) as NSDictionary

我不确定你在期待什么,但据我所知,在字典上没有这样的方法.您可能正在寻找下标语法.像这样的东西:

launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey] as NSDictionary

获取嵌套在键下的launchOptions字典中的字典:UIApplicationLaunchOptionsRemoteNotificationKey.

话虽这么说,launchOptions可能是零,你应该在你的代码添加该检查,并尝试记录launchOptions并在此处发布结果.

您可以检查launchOptions是否为零:

if let launchOpts = launchOptions {
    var notificationPayload: NSDictionary = launchOpts.objectForKey(UIApplicationLaunchOptionsRemoteNotificationKey) as NSDictionary
}

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...