Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

ios - didReceiveRemoteNotification not called in Background Mode

I am working on push notifications and the data I receive is in JSON format. How can I parse the JSON data, which is shown in the Notification Center below:

I only need the description

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

if your app in background/foreground mode call this method

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler

if you used the above method you will face the following error in console

application:didReceiveRemoteNotification:fetchCompletionHandler:], but you still need to add "remote-notification" to the list of your supported UIBackgroundModes in your Info.plist.

To Resolve this issue

follow the image of steps

enter image description here

if your app in foreground mode call this method

- (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo

choice 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
}
}

Swift

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
}
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...