<small id='oW6up'></small><noframes id='oW6up'>

<i id='oW6up'><tr id='oW6up'><dt id='oW6up'><q id='oW6up'><span id='oW6up'><b id='oW6up'><form id='oW6up'><ins id='oW6up'></ins><ul id='oW6up'></ul><sub id='oW6up'></sub></form><legend id='oW6up'></legend><bdo id='oW6up'><pre id='oW6up'><center id='oW6up'></center></pre></bdo></b><th id='oW6up'></th></span></q></dt></tr></i><div id='oW6up'><tfoot id='oW6up'></tfoot><dl id='oW6up'><fieldset id='oW6up'></fieldset></dl></div>
  • <legend id='oW6up'><style id='oW6up'><dir id='oW6up'><q id='oW6up'></q></dir></style></legend>

    <tfoot id='oW6up'></tfoot>

      <bdo id='oW6up'></bdo><ul id='oW6up'></ul>

      1. 应用程序在 iOS 10 中处于后台时未收到推送通知

        时间:2023-07-29

      2. <legend id='0gkJK'><style id='0gkJK'><dir id='0gkJK'><q id='0gkJK'></q></dir></style></legend>

        <small id='0gkJK'></small><noframes id='0gkJK'>

            <tfoot id='0gkJK'></tfoot>
              <bdo id='0gkJK'></bdo><ul id='0gkJK'></ul>
              <i id='0gkJK'><tr id='0gkJK'><dt id='0gkJK'><q id='0gkJK'><span id='0gkJK'><b id='0gkJK'><form id='0gkJK'><ins id='0gkJK'></ins><ul id='0gkJK'></ul><sub id='0gkJK'></sub></form><legend id='0gkJK'></legend><bdo id='0gkJK'><pre id='0gkJK'><center id='0gkJK'></center></pre></bdo></b><th id='0gkJK'></th></span></q></dt></tr></i><div id='0gkJK'><tfoot id='0gkJK'></tfoot><dl id='0gkJK'><fieldset id='0gkJK'></fieldset></dl></div>

                    <tbody id='0gkJK'></tbody>
                1. 本文介绍了应用程序在 iOS 10 中处于后台时未收到推送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在使用 FCM(Firebase 云消息传递)在 iOS 中发送推送通知.

                  I'm using FCM(Firebase Cloud Messaging) for sending push notifications in iOS.

                  当应用程序处于前台状态时,我能够收到通知.但是当应用程序处于后台状态时,没有收到通知.每当应用程序进入前台状态时,才会收到通知.

                  I'm able to receive the notification when App is in foreground state. But when the App is in background state, the notification is not received. Whenever the application will come to foreground state, only then will the notification be received.

                  我的代码是:

                  - (void)userNotificationCenter:(UNUserNotificationCenter *)center
                     willPresentNotification:(UNNotification *)notification
                       withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
                  // Print message ID.
                  NSDictionary *userInfo = notification.request.content.userInfo;
                  NSLog(@"Message ID: %@", userInfo[@"gcm.message_id"]);
                  
                  // Pring full message.
                  NSLog(@"%@", userInfo);
                  
                  if( [UIApplication sharedApplication].applicationState == UIApplicationStateInactive )
                  {
                      NSLog( @"INACTIVE" );
                      completionHandler(UNNotificationPresentationOptionAlert);
                  }
                  else if( [UIApplication sharedApplication].applicationState == UIApplicationStateBackground )
                  {
                      NSLog( @"BACKGROUND" );
                      completionHandler( UNNotificationPresentationOptionAlert );
                  }
                  else
                  {
                      NSLog( @"FOREGROUND" );
                      completionHandler( UNNotificationPresentationOptionAlert );
                  }}
                  
                  
                  
                  - (void)applicationDidEnterBackground:(UIApplication *)application {
                  
                  
                  }
                  

                  App处于后台状态时:

                  When App is in background state:

                  - (void)userNotificationCenter:(UNUserNotificationCenter *)center
                     willPresentNotification:(UNNotification *)notification
                       withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler
                  

                  -- 根本没有被调用.

                  -- is not called at all.

                  我在 App Capabilities 的后台模式中启用了推送通知和远程通知.但是App仍然没有收到通知.

                  I enabled push notifications and also remote notifications in background modes in App Capabilities. But App is still not receiving the notification.

                  我提到了一些 StackOverflow 问题,但无法解决问题.iOS 版本 10 中是否有任何要添加的内容或我的代码中有任何错误?

                  I referred to some StackOverflow questions but wasn't able to solve the issue. Is there anything to add in iOS version 10 or any mistake in my code?

                  推荐答案

                  对于iOS 10,我们需要调用下面2个方法.

                  For iOS 10, we need to call the 2 methods below.

                  对于 FOREGROUND 状态

                  - (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 (^)())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);
                      completionHandler();
                  }  
                  

                  在此之前,我们必须添加UserNotifications框架并导入到AppDelegate.h文件中

                  Before that, we must add the UserNotifications framework and import in the AppDelegate.h file

                  #import <UserNotifications/UserNotifications.h>  
                  @interface AppDelegate : UIResponder <UIApplicationDelegate,UNUserNotificationCenterDelegate>  
                  

                  这篇关于应用程序在 iOS 10 中处于后台时未收到推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:应用程序在后台时未收到 Firebase 云消息 下一篇:ios10、Swift 3 和 Firebase 推送通知 (FCM)

                  相关文章

                    <small id='FXv8v'></small><noframes id='FXv8v'>

                      <tfoot id='FXv8v'></tfoot><legend id='FXv8v'><style id='FXv8v'><dir id='FXv8v'><q id='FXv8v'></q></dir></style></legend>

                      • <bdo id='FXv8v'></bdo><ul id='FXv8v'></ul>

                      <i id='FXv8v'><tr id='FXv8v'><dt id='FXv8v'><q id='FXv8v'><span id='FXv8v'><b id='FXv8v'><form id='FXv8v'><ins id='FXv8v'></ins><ul id='FXv8v'></ul><sub id='FXv8v'></sub></form><legend id='FXv8v'></legend><bdo id='FXv8v'><pre id='FXv8v'><center id='FXv8v'></center></pre></bdo></b><th id='FXv8v'></th></span></q></dt></tr></i><div id='FXv8v'><tfoot id='FXv8v'></tfoot><dl id='FXv8v'><fieldset id='FXv8v'></fieldset></dl></div>