iOS应用程序在后台显示通知,但不在前台显示iphone 4s&;操作系统版本9.3
应用程序在未运行状态、后台状态下接收远程通知,并在前台状态下使用本地拦截概念获取通知(获取远程通知时触发本地通知)。但当应用程序位于前台且iOS版本为9.3时,它不会接收远程通知 我的代码在这里:iOS应用程序在后台显示通知,但不在前台显示iphone 4s&;操作系统版本9.3,ios,objective-c,iphone,apple-push-notifications,Ios,Objective C,Iphone,Apple Push Notifications,应用程序在未运行状态、后台状态下接收远程通知,并在前台状态下使用本地拦截概念获取通知(获取远程通知时触发本地通知)。但当应用程序位于前台且iOS版本为9.3时,它不会接收远程通知 我的代码在这里: - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { NSLog(@"Called"); NSL
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
NSLog(@"Called");
NSLog(@"Response - > %@",userInfo);
UILocalNotification* localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:1];
localNotification.alertBody = [[userInfo valueForKey:@"aps"] valueForKey:@"alert"];
localNotification.timeZone = [NSTimeZone defaultTimeZone];
localNotification.applicationIconBadgeNumber = 0;
}
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler
{
NSLog( @"Handle push from foreground" );
// custom code to handle push while app is in the foreground
NSLog(@"%@", notification.request.content.userInfo);
completionHandler(UNNotificationPresentationOptionAlert);
}
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler
{
NSLog( @"Handle push from background or closed" );
// if you set a member variable in didReceiveRemoteNotification, you will know if this is from closed or background
NSLog(@"%@", response.notification.request.content.userInfo);
NSInteger countNoti = [[[response.notification.request.content.userInfo valueForKey:@"aps"] valueForKey:@"badge"] integerValue];
if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateActive ) {
UILocalNotification* localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:1];
localNotification.alertBody = [[response.notification.request.content.userInfo valueForKey:@"aps"] valueForKey:@"alert"];
localNotification.timeZone = [NSTimeZone defaultTimeZone];
localNotification.applicationIconBadgeNumber = countNoti;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
}
}
调用了DidReceiveMemotentification,但未显示通知。
谢谢。我想您还没有在AppDelegate文件中实现iOS9推送通知方法 目标-C
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
Swift
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any])
当应用程序处于活动状态时,您可以在上述功能中安排本地通知。显示通知 我想这不是你的错。。我也有同样的问题。。我认为firebase不支持以下内容10@Mansi当应用程序位于前台时,不会显示通知,但您将在DidReceiveNotification操作中获得AppDelegate类的通知,在此您将通过AlertView处理通知。是的,我知道alert view可以解决我的问题,但我不想要警报视图。@AkshayDegadaI认为当应用程序位于前台时,iOS 9不会像iOS 10那样显示任何通知,我认为当应用程序位于前台时,没有任何方式显示通知。也许Darshitvadoria是对的。