【发布时间】:2017-02-04 18:46:41
【问题描述】:
我正在通过苹果推送通知开发 iOS 推送通知功能,现在我在我的应用程序处于后台或前台时收到适当的通知,但是我想在我的应用程序处于后台时处理远程通知,基本上当我的应用程序运行时在后台它只是显示来自有效负载的警报消息。实际上我只是想自定义我的远程通知。
代码:
- (BOOL)application:(UIApplication )application didFinishLaunchingWithOptions:(NSDictionary )launchOptions {
// Override point for customization after application launch.
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
{
// [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
[[UIApplication sharedApplication] registerForRemoteNotifications];
}
else
{
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
(UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)];
}
return YES;
}
- (void)application:(UIApplication *)application
didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
NSLog(@"Did Register for Remote Notifications with Device Token (%@)", error);
}
- (void)application:(UIApplication )application didRegisterForRemoteNotificationsWithDeviceToken:(NSData )deviceToken {
NSLog(@"Did Register for Remote Notifications with Device Token (%@)", deviceToken);
}
-(void)application:(UIApplication )application didReceiveRemoteNotification:(NSDictionary )userInfo fetchCompletionHandler:(void (UIBackgroundFetchResult))completionHandler
{
NSDictionary * aps=[userInfo valueForKey"aps"];
NSLog(@"did recevie %@",aps);
NSLog(@"userinfo details %@",[aps valueForKey"alert"]);
}
【问题讨论】:
-
您在测试设备中使用的是哪个版本的 iOS?
-
对于 iOS 10 及更高版本你必须做一些其他的事情
-
它在 ios 10.0 中
标签: ios objective-c push-notification