当Firebase与Push框架一起使用时,未调用didReceiveRemoteNotification



我使用Firebase进行分析,并使用推送通知库。当我使用其中任何一个时,都会调用didReceiveRemoteNotification。但是当我同时使用它们时,就不会调用didReceiveRemoteNotification
代码:

didFinishLaunchingWithOptions:

NSString *google_app_id = @"----";
NSString *gcm_sender_id = @"----";
FIROptions *o = [[FIROptions alloc] initWithGoogleAppID:google_app_id GCMSenderID:gcm_sender_id];
o.APIKey = @"----";
o.bundleID = @"----";
o.clientID = @"----";
[FIRApp configureWithOptions:o];  
// Initilization of push framework 

didReceiveRemoteNotification

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
// This method is not called when Firebase and push framework are enabled at the same time
// It works fine when only Firebase or only push framework is enabled
NSLog(@"Push: %@", userInfo);
}

这是因为Firebase使用swizzling来拦截AppDelegate的方法。

您应该在应用程序的信息中禁用它。plist:

<key>FirebaseAppDelegateProxyEnabled</key>
<false/>

事实上,在GitHub上有很多关于Firebase在iOS中推送通知的信息。你可能会在那里找到进一步问题的答案。

在Firebase Cloud Messaging中关于此方法的文档中说:

如果您在应用程序中收到通知消息在后台,在用户点击之前不会触发此回调在启动应用程序的通知上。

mb此方法仅在您点击通知时调用哪个启动应用程序?

根据我的经验,我用以下方法处理推送:

- (void)userNotificationCenter:(UNUserNotificationCenter *)center
didReceiveNotificationResponse:(UNNotificationResponse *)response
withCompletionHandler:(void (^)())completionHandler {

方法获取有关即将到来的推送通知的信息(如果应用程序处于活动状态(。在块中,您必须放置常量以显示您的通知:

completionHandler(UNNotificationPresentationOptionAlert);

还有一个:

(void)userNotificationCenter:(UNUserNotificationCenter *)center
willPresentNotification:(UNNotification *)notification
withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {

此方法适用于点击推送通知。在这里,你正在处理移动到一些特殊的屏幕。

希望我的经验能帮上忙!

最新更新