通知的处理是在客户端完成的,您想要做的当然是可能的。从此处链接的推送通知的 Bluemix 文档中获取
静音通知不会出现在设备屏幕上。这些通知由应用程序在后台接收,它会唤醒应用程序长达 30 秒以执行指定的后台任务。用户可能不知道通知到达。要处理静默推送通知,请在 appDelegate.m 中实现以下方法。
// For Objective C
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))handler
{
NSNumber *contentAvailable = userInfo[@"aps"][@"content-available"];
if([contentAvailable intValue]== 1){
[[IMFPushClient sharedInstance] application:application didReceiveRemoteNotification:userInfo];
//Perform background task
NSLog(@"Received a silent push..");
NSLog(@"userInfo: %@", userInfo.description);
_appDelegateVC.result.text = userInfo.description;
handler(UIBackgroundFetchResultNewData);
}
else{
//Normal Notification
[[IMFPushAppManager get] notificationReceived:userInfo];
NSLog(@"Received a normal notification.");
NSLog(@"userInfo: %@", userInfo.description);
_appDelegateVC.result.text = userInfo.description;
handler(UIBackgroundFetchResultNoData);
}
//Success
}
服务器为静默通知发送的 contentAvailable 值等于 1。