我已将我的应用设置为与 GCM 配合使用。
我已成功添加代码以将 GCM 集成到我的应用程序中。
现在我有两种方法来处理推送通知:
- Default Method
- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo {
NSLog(@"Notification received: %@", userInfo);
// This works only if the app started the GCM service
[[GCMService sharedInstance] appDidReceiveMessage:userInfo];
}
GCM 方法
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))handler { NSLog(@"Notification received: %@", userInfo); // This works only if the app started the GCM service [[GCMService sharedInstance] appDidReceiveMessage:userInfo]; // Handle the received message // Invoke the completion handler passing the appropriate UIBackgroundFetchResult value // ... }
现在我很困惑应该在哪里处理我的Notificaiton
。
我应该在哪里检查应用程序
状态并调用我的方法来处理它。
我是否应该在这两个方法中都编写方法。
最佳答案
我不熟悉 GCM,但是您列出的两种通知方法是标准的 UIApplicationDelegate 方法并处理不同的场景。
application:didReceiveRemoteNotification:
在应用程序打开并且您收到普通推送通知时调用。您通过通知中心收到提醒的类型。
application:didReceiveRemoteNotification:fetchCompletionHandler:
当服务器让应用程序知道有东西要下载时调用。您检查 userInfo 以了解要下载的内容,启动下载并在 NewData/NoData/Failed 时调用处理程序 (UIBackgroundFetchResult)
不确定 GCM 使用这两种方法做什么,但根据这些信息您应该能够弄清楚。
关于ios - 使用 GCM ios 9 时我应该在哪里处理推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35955111/