<legend id='HEOS9'><style id='HEOS9'><dir id='HEOS9'><q id='HEOS9'></q></dir></style></legend>

    • <bdo id='HEOS9'></bdo><ul id='HEOS9'></ul>
      <i id='HEOS9'><tr id='HEOS9'><dt id='HEOS9'><q id='HEOS9'><span id='HEOS9'><b id='HEOS9'><form id='HEOS9'><ins id='HEOS9'></ins><ul id='HEOS9'></ul><sub id='HEOS9'></sub></form><legend id='HEOS9'></legend><bdo id='HEOS9'><pre id='HEOS9'><center id='HEOS9'></center></pre></bdo></b><th id='HEOS9'></th></span></q></dt></tr></i><div id='HEOS9'><tfoot id='HEOS9'></tfoot><dl id='HEOS9'><fieldset id='HEOS9'></fieldset></dl></div>
      1. <small id='HEOS9'></small><noframes id='HEOS9'>

      2. <tfoot id='HEOS9'></tfoot>

        未使用 firebase 和 Objective C 接收推送通知

        时间:2023-07-28

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

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

              <tfoot id='ILJCS'></tfoot>
                <bdo id='ILJCS'></bdo><ul id='ILJCS'></ul>
                • 本文介绍了未使用 firebase 和 Objective C 接收推送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试使用 Firebase 进行推送通知.我已经通过 Cocoapods 成功安装了 FirebaseFirebase 消息传递.

                  I am trying to use Firebase for push notification. i have successfully installed the Firebase And Firebase messaging via Cocoapods.

                  我使用了下面的代码

                   - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
                      [FIRApp configure];
                  
                      [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(tokenRefreshCallback:) name:kFIRInstanceIDTokenRefreshNotification object:nil];
                  
                  
                      UIUserNotificationType allNotificationsType = (UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge);
                  
                      UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:allNotificationsType categories:nil];
                      [application registerUserNotificationSettings:settings];
                  
                      [application isRegisteredForRemoteNotifications];
                  
                      return YES;
                  }
                  
                  
                   -(void)applicationDidEnterBackground:(UIApplication *)application {
                  
                      [[FIRMessaging messaging] disconnect];
                      NSLog(@"Disconnect from FCM");
                  }
                  
                  - (void)applicationDidBecomeActive:(UIApplication *)application {
                       [self connectToFirebase];
                  }
                  
                  - (void) application:(UIApplication *) application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:( void (^)(UIBackgroundFetchResult))completionHandler{
                  
                      // Pring The Message Id
                      NSLog(@"Mesage Id : %@",userInfo[@"gcm.message_id"]);
                  
                      // Print Full Message
                      NSLog(@"%@",userInfo);
                  }
                  
                  #pragma mark -- Custom Firebase code
                  
                  
                  - (void)tokenRefreshCallback:(NSNotification *) notification{
                      NSString *refreshedToken = [[FIRInstanceID instanceID] token];
                      NSLog(@"IstanceID token: %@", refreshedToken);
                  
                      // Connect To FCM since connection may have failed when attempt before having a token
                      [self connectToFirebase];
                  }
                  
                  -(void) connectToFirebase{
                  
                      [[FIRMessaging messaging] connectWithCompletion:^(NSError * _Nullable error)
                       {
                           if ( error != nil)
                           {
                               NSLog(@"Unable to Connect To FCM. %@",error);
                           }
                           else
                           {
                               NSLog((@"Connected To FCM"));
                           }
                       }];
                  }
                  

                  当我使用与 Xcode 连接的 iPhone 运行上述代码时,当我从 Firebase 控制台发送消息时遇到以下问题

                  When i run the above code using my iPhone connected with Xcode i am facing the following issues when i send a message from Firebase Console

                  1).当应用程序处于前台(活动)时,日志显示以下消息

                  1). when the app is in foreground (active), Log shows the below message

                  Mesage Id : (null){
                      CustommData = "First Message";
                      "collapse_key" = "abcd.iospush.FireBasePush";
                      from = 555551391562;
                      notification =     {
                          badge = 4;
                          body = "Test Message";
                          e = 1;
                          sound = default;
                          sound2 = default;
                      };
                  }
                  

                  注意 Message Idnull.

                  2).我的手机在通知中心中没有显示任何通知,无论应用程序处于前台、后台还是关闭状态

                  2). My phone doesn't show any notification in Notification Centre whether App is in Foreground , Background or Closed

                  我希望用户在应用处于后台、前台或关闭时接收推送通知

                  I want user to receive push notifications when App is in Background , Foreground or Closed

                  推荐答案

                  您必须调用 [[UIApplication sharedApplication] registerForRemoteNotifications]; 才能正确注册远程通知.

                  You must call [[UIApplication sharedApplication] registerForRemoteNotifications]; to properly register for remote notifications.

                  为后台使用配置远程通知

                  您是否已将应用的后台模式配置为接受远程通知?你可以通过点击:Project Name -> Capabilities -> Background Modes

                  Have you configured your app's background modes to accept remote notifications? You can do this by clicking: Project Name -> Capabilities -> Background Modes

                  打开它,然后勾选远程通知旁边的框,如下面的屏幕截图所示.

                  Turn this on and then tick the box beside Remote Notifications as seen in the screenshot below.

                  这篇关于未使用 firebase 和 Objective C 接收推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:无论如何,是否可以在没有 Firebase 数据库的情况下使用 FCM 从一台设备向另一台设备发送通知? 下一篇:如何使网格视图在android中水平滚动而不是垂直滚动?

                  相关文章

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

                  <small id='5DivH'></small><noframes id='5DivH'>

                  <tfoot id='5DivH'></tfoot>