【发布时间】:2017-04-27 04:44:32
【问题描述】:
在 iOS 10 中使用 FCM 推送通知:
这是通过我们自己的 API 推送通知后被调用的 snipper:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
// If you are receiving a notification message while your app is in the background,
// this callback will not be fired till the user taps on the notification launching the application.
// TODO: Handle data of notification
[[FIRMessaging messaging] appDidReceiveMessage:userInfo];
if (userInfo[kGCMMessageIDKey]) {
NSLog(@"Message ID: %@", userInfo[kGCMMessageIDKey]);
}
completionHandler(UIBackgroundFetchResultNewData);
if(application.applicationState == UIApplicationStateBackground){
[[TWMessageBarManager sharedInstance] showMessageWithTitle:@"Bacgkround"
description:@"Wassup"
type:TWMessageBarMessageTypeSuccess callback:^{
}];
}
else if(application.applicationState == UIApplicationStateActive){
[[TWMessageBarManager sharedInstance] showMessageWithTitle:@"Active"
description:@"Wassup"
type:TWMessageBarMessageTypeSuccess callback:^{
}];
}
else if(application.applicationState == UIApplicationStateInactive){
[[TWMessageBarManager sharedInstance] showMessageWithTitle:@"InActive"
description:@"Wassup"
type:TWMessageBarMessageTypeSuccess callback:^{
}];
}
}
当应用程序处于活动状态时,将调用上述方法并执行 UIApplicationStateActive 案例,并且我正在使用 3rd 方库显示一个弹出窗口。当我按下主页按钮并推送通知时,会调用上述方法并执行 UIApplicationStateBackground 但我不确定如何以横幅的形式显示通知?
这是我必须处理通知的方法吗?如果是,我该如何处理 Background 和 Inactive 状态?
【问题讨论】:
标签: ios objective-c firebase firebase-cloud-messaging uiapplication