当应用在后台运行时,Google Firebase远程通知不会弹出

编程入门 行业动态 更新时间:2024-10-24 01:57:24
本文介绍了当应用在后台运行时,Google Firebase远程通知不会弹出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用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远程通知不会弹出

本文发布于:2023-11-27 08:34:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1637305.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:弹出   用在   后台   通知   Google

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!