Xcode,Parse – 处理远程通知

前端之家收集整理的这篇文章主要介绍了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"
}
@H_301_10@解决方法
我猜你的问题在这里:
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相关文章