2016-03-29 39 views
1

我收到来自Urban Airship的自定义信息推送通知。它显示在日志中,但我试图获取对象,以便我可以解析数据以存储特定值,例如“quest_id”的1。我该如何去取回物体,或者我可以在哪里找到?任何建议或见解将不胜感激。如何从Urban Airship(Objective-c)获取发送到iOS设备的推送对象?

enter image description here

+0

因此,您希望在收到通知后拦截通知? –

+0

@ Fullmetal_Alchemist_Fan是的,先生! –

+0

你看 - - (void)应用程序:(UIApplication *)应用程序didReceiveRemoteNotification:(NSDictionary *)在您的应用程序委托中的userInfo委托方法?如果您已经正确地向APNS注册了设备,那么这是您可以找到传入有效负载的位置。 –

回答

1

根据您在的Info.plist作出的推送通知的配置,你应该实现在AppDelegate.swift以下方法:

func application(application:didReceiveRemoteNotification:) 

application(application:didReceiveRemoteNotification:fetchCompletionHandler:) 

这里是一个基本的例子哟ü可以做到这一点:

func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject: AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) { 
    if let questID = userInfo["quest_id"] as? Int { 
    print(questID) // prints 1 
    } 
    if let question = userInfo["question"] as? String { 
    print(question) // prints "What is threading?" 
    } 
    completionHandler(UIBackgroundFetchResult.NoData) 
} 
0

你就必须实现(无效)申请:(UIApplication的*)应用程序didReceiveRemoteNotification:(NSDictionary的*)USERINFO方法UIApplicationDelegate.This方法定义将被称为收到推送通知时。然后,您可以使用userInfo字典它将包含所有推送信息

相关问题