Firebase Cloud Messaging development and release profile

后端 未结 4 952
误落风尘
误落风尘 2020-12-29 11:29

I recendly swtiched over from Google Cloud Messaging to Firebase Cloud Messaging.

With GCM I had to choose the sandbox option. As described here : https://developers

相关标签:
4条回答
  • 2020-12-29 12:03

    Be safe, use below:

        #if DEBUG
            FIRInstanceID.instanceID().setAPNSToken(deviceToken, type: .sandbox)
        #else
            FIRInstanceID.instanceID().setAPNSToken(deviceToken, type: .prod)
        #endif
    

    Do not unnecessarily set sandbox token to prod type and vice versa.

    0 讨论(0)
  • 2020-12-29 12:18

    It is about the setAPNSToken() function. You need to set the FIRInstanceIDAPNSTokenType to Prod while adding the device token. I use swift for that, the code I used is this:

    func application(application: UIApplication,
                     didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData)
    {
        FIRInstanceID.instanceID().setAPNSToken(deviceToken, type: FIRInstanceIDAPNSTokenType.Prod)
    }
    

    also if you just want to remove the warning, you may use a production provisioning profile.

    0 讨论(0)
  • 2020-12-29 12:20

    I solved the problem by adding the code below to the project.

    FIRInstanceIDAPNSTokenType.Sandbox will be used when you install the app though TestFlight,
    and FIRInstanceIDAPNSTokenType.Prod when your app goes live on the App Store.

    func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) 
    {
        FIRInstanceID.instanceID().setAPNSToken(deviceToken, type: FIRInstanceIDAPNSTokenType.Sandbox)
        FIRInstanceID.instanceID().setAPNSToken(deviceToken, type: FIRInstanceIDAPNSTokenType.Prod)
    }
    
    0 讨论(0)
  • 2020-12-29 12:20

    I followed the documentation provided and was having the same issue, then I tried the quick start app and it worked. The key seems to be to add the logic to connect to the FCM after obtaining a token, this step is missing in the setup documentation. After I did this it worked on my development device outside of TestFlight without any other special sandbox switches.

    https://github.com/firebase/quickstart-ios/blob/master/messaging/FCM/AppDelegate.m#L85

    // [START refresh_token]
    - (void)tokenRefreshNotification:(NSNotification *)notification {
      // Note that this callback will be fired everytime a new token is generated, including the first
      // time. So if you need to retrieve the token as soon as it is available this is where that
      // should be done.
      NSString *refreshedToken = [[FIRInstanceID instanceID] token];
      NSLog(@"InstanceID token: %@", refreshedToken);
    
      // Connect to FCM since connection may have failed when attempted before having a token.
      [self connectToFcm];
    
      // TODO: If necessary send token to appliation server.
    }
    // [END refresh_token]
    
    // [START connect_to_fcm]
    - (void)connectToFcm {
      [[FIRMessaging messaging] connectWithCompletion:^(NSError * _Nullable error) {
        if (error != nil) {
          NSLog(@"Unable to connect to FCM. %@", error);
        } else {
          NSLog(@"Connected to FCM.");
        }
      }];
    }
    // [END connect_to_fcm]
    
    - (void)applicationDidBecomeActive:(UIApplication *)application {
      [self connectToFcm];
    }
    
    // [START disconnect_from_fcm]
    - (void)applicationDidEnterBackground:(UIApplication *)application {
      [[FIRMessaging messaging] disconnect];
      NSLog(@"Disconnected from FCM");
    }
    // [END disconnect_from_fcm]
    
    0 讨论(0)
提交回复
热议问题