我接受了从Google云消息传递到Firebase云消息传递的信息。
使用GCM,我必须选择沙盒选项。如下所述:https://developers.google.com/cloud-messaging/ios/client#obtain_a_registration_token见第3点。
要在调试模式下接收推送通知,我必须做这样的事情
[[GGLInstanceID sharedInstance] startWithConfig:instanceIDConfig];
_registrationOptions = @{kGGLInstanceIDRegisterAPNSOption:deviceToken,
kGGLInstanceIDAPNSServerTypeSandboxOption:@YES};
要从AppStore(例如TestFlight)接收应用程序中的推送通知,我不得不说:
kGGLInstanceIDAPNSServerTypeSandboxOption:@NO};
现在我在Firebase中找不到这样的内容。首先,我认为不再切换这些愚蠢的价值观。但现在我的TestFlight应用程序中不再收到任何推送通知了。
在我的调试控制台中,当我在设备上调试时,一个输出是这样的:
<FIRInstanceID/WARNING> APNS Environment in profile: development
哪个适合本地调试,但在TestFlight中不受欢迎。 (我不知道TestFlight应用程序是否会发生这种情况,因为我没有控制台。)
所以我的问题是:是否有人知道我是否可以在Firebase中手动更改此Sandbox选项?
谢谢,
西蒙
答案 0 :(得分:11)
我通过在项目中添加以下代码解决了这个问题。
通过TestFlight安装应用程序时将使用FIRInstanceIDAPNSTokenType.Sandbox,
和你的应用程序在App Store上线时的FIRInstanceIDAPNSTokenType.Prod。
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData)
{
FIRInstanceID.instanceID().setAPNSToken(deviceToken, type: FIRInstanceIDAPNSTokenType.Sandbox)
FIRInstanceID.instanceID().setAPNSToken(deviceToken, type: FIRInstanceIDAPNSTokenType.Prod)
}
答案 1 :(得分:2)
我按照提供的文档提出了同样的问题,然后我尝试了快速启动应用程序并且它有效。关键似乎是在获取令牌后添加连接到FCM的逻辑,在安装文档中缺少此步骤。在我这样做之后,它在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]
答案 2 :(得分:2)
安全,请在下方使用:
#if DEBUG
FIRInstanceID.instanceID().setAPNSToken(deviceToken, type: .sandbox)
#else
FIRInstanceID.instanceID().setAPNSToken(deviceToken, type: .prod)
#endif
不要将沙盒令牌不必要地设置为prod类型,反之亦然。
答案 3 :(得分:1)
关于setAPNSToken()
功能。您需要在添加设备令牌时将FIRInstanceIDAPNSTokenType
设置为Prod
。我使用swift,我使用的代码是:
func application(application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData)
{
FIRInstanceID.instanceID().setAPNSToken(deviceToken, type: FIRInstanceIDAPNSTokenType.Prod)
}
如果您只想删除警告,也可以使用生产配置文件。