Firebase云消息传递开发和发布configuration文件
我从Google云消息传递到Firebase云消息传递。
有了GCM,我不得不select沙箱选项。 如此处所述: https : //developers.google.com/cloud-messaging/ios/client#obtain_a_registration_token请参阅第3点。
要以debugging模式接收推送通知,我必须做这样的事情
[[GGLInstanceID sharedInstance] startWithConfig:instanceIDConfig]; _registrationOptions = @{kGGLInstanceIDRegisterAPNSOption:deviceToken, kGGLInstanceIDAPNSServerTypeSandboxOption:@YES};
要从AppStore接收推送通知(例如TestFlight),我不得不说:
kGGLInstanceIDAPNSServerTypeSandboxOption:@NO};
现在我无法在Firebase中find这样的内容。 首先,我认为伟大的没有改变这些愚蠢的价值观了。 但是现在我不再在我的TestFlight应用程序中收到任何推送通知。
在我的debugging控制台,当我在设备上debugging时,一个输出是这样的:
<FIRInstanceID/WARNING> APNS Environment in profile: development
这对本地debugging很有用,但在TestFlight中是不需要的。 (我不知道TestFlight应用程序是否会发生这种情况,因为我没有它们的控制台。)
所以我的问题是:有人知道我是否可以在Firebase中手动更改这个Sandbox选项?
谢谢,
西蒙
我通过将下面的代码添加到项目中解决了这个问题。
FIRInstanceIDAPNSTokenType.Sandbox将在您通过TestFlight安装应用程序时使用,
和FIRInstanceIDAPNSTokenType.Prod当你的应用程序在App Store上线。
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) { FIRInstanceID.instanceID().setAPNSToken(deviceToken, type: FIRInstanceIDAPNSTokenType.Sandbox) FIRInstanceID.instanceID().setAPNSToken(deviceToken, type: FIRInstanceIDAPNSTokenType.Prod) }
我跟着提供的文档,并具有相同的问题,然后我尝试了快速启动应用程序,它的工作。 关键似乎是在获取令牌后添加连接到FCM的逻辑,安装文档中缺less此步骤。 当我这样做后,它在TestFlight之外的我的开发设备上工作,没有任何其他特殊的沙箱开关。
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]
它关于setAPNSToken()
函数。 您需要在添加设备令牌时将FIRInstanceIDAPNSTokenType
设置为Prod
。 我使用swift,我使用的代码是这样的:
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) { FIRInstanceID.instanceID().setAPNSToken(deviceToken, type: FIRInstanceIDAPNSTokenType.Prod) }
另外,如果您只想删除警告,则可以使用生产供应configuration文件。
安全,使用如下:
#if DEBUG FIRInstanceID.instanceID().setAPNSToken(deviceToken, type: .sandbox) #else FIRInstanceID.instanceID().setAPNSToken(deviceToken, type: .prod) #endif
不要不必要地将沙盒标记设置为prodtypes,反之亦然。
- iOS上的Firebase参考
- iOS Firebase如何在Block之外传递快照值/密钥
- 检索存储在childByAutoId()参考(Swift)中的特定Firebase数据
- 在同一个uitableview中显示两个不同的自定义单元格 – swift firebase
- asynchronous加载 – UITableView和Firebase
- 无法将types''的值转换为期望的参数types'String':在表视图单元格中添加数组以从Fireabse获取数据时
- 针对复杂写入的Firebase提交/回滚
- iOS Firebase推送通知:如何提供Firebase用户的设备令牌并发送通知
- 导致“线程1:信号SIGABRT”的Firebase