kri*_*hna 4 iphone objective-c apple-push-notifications ios swift
我正在处理推送通知,我收到的数据是JSON格式.如何解析JSON数据,如下面的通知中心所示:
如果你的应用程序在后台/前台模式下调用此方法
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler
Run Code Online (Sandbox Code Playgroud)
如果您使用上述方法,您将在控制台中遇到以下错误
application:didReceiveRemoteNotification:fetchCompletionHandler:],但您仍需要将"remote-notification"添加到Info.plist中支持的UIBackgroundModes列表中.
解决此问题
按照步骤的图像
如果你的app在前台模式下调用此方法
- (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo
Run Code Online (Sandbox Code Playgroud)
选择no-2
- (void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
UIApplicationState state = [application applicationState];
// user tapped notification while app was in background
if (state == UIApplicationStateInactive || state == UIApplicationStateBackground) {
// go to screen relevant to Notification content
} else {
// App is in UIApplicationStateActive (running in foreground)
// perhaps show an UIAlertView
}
}
Run Code Online (Sandbox Code Playgroud)
迅速
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
var state: UIApplicationState = application.applicationState()
// user tapped notification while app was in background
if state == .Inactive || state == .Background {
// go to screen relevant to Notification content
}
else {
// App is in UIApplicationStateActive (running in foreground)
// perhaps show an UIAlertView
}
}
Run Code Online (Sandbox Code Playgroud)