我发现了一个非常简单的解决方案,而不使用框架。
我只是下面的代码添加到方法的最后didFinishLaunchingWithOptions(return语句前右):
if (launchOptions != nil)
{
NSDictionary* dictionary = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (dictionary != nil)
{
NSLog(@"Launched from push notification: %@", dictionary);
[self addMessageFromRemoteNotification:dictionary updateUI:NO];
}
}
另外,我加入到我的AppDelegate.m这种新方法,得到从推送消息有效载荷:
- (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo
{
NSLog(@"Received notification: %@", userInfo);
[self addMessageFromRemoteNotification:userInfo updateUI:YES];
}
(在上面的NSLog调用会告诉你什么是推送消息中)
最后一步,我添加了这个监听器,我想和有效载荷什么都:
- (void)addMessageFromRemoteNotification:(NSDictionary*)userInfo updateUI:(BOOL)updateUI
{
// do what ever you want with userInfo
}
如果你想要做一个额外的JavaScript调用这个信息,我建议使用:
[self.viewController.webView stringByEvaluatingJavaScriptFromString:@"callSomeJSFunction()"];
当然,如果你愿意,你也可以将参数作为字符串传递给JS函数。