当应用在后台运行时,Google Firebase远程通知不会弹出 [英] Google Firebase remote notifications not popping up when app is running in background
问题描述
我正在使用Google Firebase向用户发送通知。当时我试图发送通知单个设备(我的)。
遇到接收通知时出现问题 - 而我的应用程序正在后台横幅中运行时不会显示。但是,如果我打开我的应用程序,方法didReceiveRemoteNotification:触发我的警报视图:
- (空)应用程序:(UIApplication的*)应用程序didReceiveRemoteNotification:(的NSDictionary *)USERINFO
fetchCompletionHandler:(无效(^)(UIBackgroundFetchResult))completionHandler {
UIAlertView中*警报= [[UIAlertView中的alloc] initWithTitle:用户信息[@ 通知] [@body]
message:@More info ...
delegate:self
cancelButtonTitle:@Cancel
otherButtonTitles:@Open,nil] ;
[alert show];
但是,由于它是在Google Firebase文档中编写的,因此此方法触发应用程序打开后,所以它是有道理的。
所以消息传递到我的设备,如果应用程序在后台,我不能触发通知横幅。
我读了关于将消息优先级设置为高和自定义数据密钥内容 - 可用于1,但没有运气。
我在代码中缺少其他东西来触发通知?
我已经使用Google Firebase Guide实现了这个功能。
我开始再次下云端通讯阅读谷歌文档火力地堡我发现这个:
在setAPNSToken:type:中提供您的APNs令牌和令牌类型。确保正确设置类型的值:沙箱环境的FIRInstanceIDAPNSTokenTypeSandbox或生产环境的FIRInstanceIDAPNSTokenTypeProd。如果您没有设置正确的类型,消息不会传递到您的应用
所以我错过了把这个声明方法:didRegisterForRemoteNotificationsWithDeviceToken:
- (无效)应用:(UIApplication的*)申请
didRegisterForRemoteNotificationsWithDeviceToken:(NSData的*)deviceToken {
[FIRInstanceID instanceID] setAPNSToken:deviceToken type:FIRInstanceIDAPNSTokenTypeSandbox];
不要忘记把type:FIRInstanceIDAPNSTokenTypeProd生产。
I am using Google Firebase to send notifications to users. At the time I am trying to send notification to single device (mine).
Having a problem with receiving notifications - while my app is running in background banner not appears. But if I open my app, method didReceiveRemoteNotification: triggers my alert view:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:userInfo[@"notification"][@"body"]
message:@"More info..."
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Open",nil];
[alert show];
}
But as it's written in Google Firebase documentation, this method triggers after app opens, so it make sense.
So message is delivered to my device, I just can't trigger a notification banner if app is in background.
I read about setting message priority to High and custom data key content-available to 1, but no luck.
Am I missing something else in my code to trigger notification?
I have done this with Google Firebase Guide to implement Notifications.
解决方案 I resolved my problem. I started reading documentation on Google Firebase once again and under Cloud Messaging I found this:
Provide your APNs token and the token type in setAPNSToken:type:. Make sure that the value of type is correctly set: FIRInstanceIDAPNSTokenTypeSandbox for the sandbox environment, or FIRInstanceIDAPNSTokenTypeProd for the production environment. If you don't set the correct type, messages are not delivered to your app.
So I missed to put this statement in method :didRegisterForRemoteNotificationsWithDeviceToken:
- (void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
[FIRInstanceID instanceID] setAPNSToken:deviceToken type:FIRInstanceIDAPNSTokenTypeSandbox];
}
Don't forget to put type: "FIRInstanceIDAPNSTokenTypeProd" for production.
这篇关于当应用在后台运行时,Google Firebase远程通知不会弹出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!