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
}

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...