firebase-ios-sdk
firebase-ios-sdk copied to clipboard
Firebase Messaging: Fails to receive a notifications in iOS
Step 1: Describe your environment
- Xcode version: 12.5.1
- Firebase SDK version: 8.6.0
- Installation method: Zip file
- Firebase Component: Messaging
Step 2: Describe the problem
Device doesn't receive a notification instead whenever a message arrives it dumps the following to the logs
2021-09-02 10:52:19.984833-0700 AppStudioApp[1047:649086] [] nw_protocol_instance_access_flow_state [C1.1.1:2] Failed to find flow 1076131f8
2021-09-02 10:52:19.988414-0700 AppStudioApp[1047:649086] [] nw_protocol_instance_access_flow_state [C1.1.1:2] Failed to find flow 1076131f8
2021-09-02 10:52:20.013324-0700 AppStudioApp[1047:649270] [] nw_protocol_instance_access_flow_state [C1.1.1:2] Failed to find flow 1076131f8
2021-09-02 10:52:20.013568-0700 AppStudioApp[1047:649270] [] nw_protocol_instance_access_flow_state [C1.1.1:2] Failed to find flow 1076131f8
2021-09-02 10:52:20.014694-0700 AppStudioApp[1047:649270] [] nw_protocol_instance_access_flow_state [C1.1.1:2] Failed to find flow 1076131f8
2021-09-02 10:52:20.015046-0700 AppStudioApp[1047:649270] [connection] nw_endpoint_handler_set_adaptive_read_handler [C2 2607:f8b0:4007:80e::200a.443 ready channel-flow (satisfied (Path is satisfied), viable, interface: en0, ipv4, ipv6, dns)] unregister notification for read_timeout failed
2021-09-02 10:52:20.015198-0700 AppStudioApp[1047:649270] [connection] nw_endpoint_handler_set_adaptive_write_handler [C2 2607:f8b0:4007:80e::200a.443 ready channel-flow (satisfied (Path is satisfied), viable, interface: en0, ipv4, ipv6, dns)] unregister notification for write_timeout failed
2021-09-02 10:52:20.015328-0700 AppStudioApp[1047:649270] [connection] nw_endpoint_handler_set_keepalive_handler [C2 2607:f8b0:4007:80e::200a.443 ready channel-flow (satisfied (Path is satisfied), viable, interface: en0, ipv4, ipv6, dns)] unregister notification for keepalive failed
2021-09-02 10:52:20.015699-0700 AppStudioApp[1047:649270] [] nw_protocol_instance_access_flow_state [C1.1.1:2] Failed to find flow 1076131f8
2021-09-02 10:52:20.016971-0700 AppStudioApp[1047:649270] [] nw_protocol_instance_access_flow_state [C1.1.1:2] Failed to find flow 10750cdc8
2021-09-02 10:52:20.017515-0700 AppStudioApp[1047:649270] [connection] nw_endpoint_handler_set_adaptive_read_handler [C1.1.1 2607:f8b0:4007:80e::200a.443 ready channel-flow (satisfied (Path is satisfied), viable, interface: en0, ipv4, ipv6, dns)] unregister notification for read_timeout failed
2021-09-02 10:52:20.017635-0700 AppStudioApp[1047:649270] [connection] nw_endpoint_handler_set_adaptive_write_handler [C1.1.1 2607:f8b0:4007:80e::200a.443 ready channel-flow (satisfied (Path is satisfied), viable, interface: en0, ipv4, ipv6, dns)] unregister notification for write_timeout failed
2021-09-02 10:52:20.017744-0700 AppStudioApp[1047:649270] [connection] nw_endpoint_handler_set_keepalive_handler [C1.1.1 2607:f8b0:4007:80e::200a.443 ready channel-flow (satisfied (Path is satisfied), viable, interface: en0, ipv4, ipv6, dns)] unregister notification for keepalive failed
2021-09-02 10:52:20.030810-0700 AppStudioApp[1047:649086] [] nw_protocol_instance_access_flow_state [C1.1.1:2] Failed to find flow 1076131f8
Steps to reproduce:
What happened? How can we make the problem occur? Manually link the dependencies in the project via QMAKE.
If you have a downloadable sample project that reproduces the bug you're reporting, you will likely receive a faster response on your issue.
build-AppStudioFirebase-Qt_5_15_5_for_iOS-Release.zip
Relevant Code:
Replace the following code in the sample project. Based on my observation It failed in both cases.
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
#import <UserNotifications/UserNotifications.h>
#include "QmlApplication.h"
#include <QObject>
#include <QDebug>
#include <Firebase.h>
//------------------------------------------------------------------------------
@interface QIOSApplicationDelegate
@end
//Add a category to QIOSApplicationDelegate
@interface QIOSApplicationDelegate (QBackgroundAudioDelegate) <UNUserNotificationCenterDelegate, FIRMessagingDelegate>
@end
//------------------------------------------------------------------------------
NSString * const kGCMMessageIDKey = @"gcm.message_id";
@implementation QIOSApplicationDelegate (QBackgroundAudioDelegate)
- (BOOL) application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[FIRApp configure];
[FIRMessaging messaging].delegate = self;
if ([UNUserNotificationCenter class] != nil)
{
[UNUserNotificationCenter currentNotificationCenter].delegate = self;
UNAuthorizationOptions authOptions = UNAuthorizationOptionAlert | UNAuthorizationOptionSound | UNAuthorizationOptionBadge;
[[UNUserNotificationCenter currentNotificationCenter] requestAuthorizationWithOptions:authOptions completionHandler:^(BOOL granted, NSError * _Nullable errpr)
{
if (granted)
{
NSLog(@"Granted == true");
}
else
{
NSLog(@"Granted == false");
}
}];
}
[application registerForRemoteNotifications];
NSLog(@"registered for remote notifications");
return YES;
}
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
const char *data = (char *)[deviceToken bytes];
NSMutableString *token = [NSMutableString string];
for (NSUInteger i = 0; i < [deviceToken length]; i++)
{
[token appendFormat:@"%02.2hhX", data[i]];
}
NSLog(@"Push Notification Token: %@", [token copy]);
NSLog(@"Did Register for Remote Notifications with Device Token (%@)", deviceToken);
[FIRMessaging messaging].APNSToken = deviceToken;
}
- (void) application:(UIApplication *)app
didFailToRegisterForRemoteNotificationsWithError:(NSError *)err
{
NSLog(@"Remote notification support is unavailable due to error: %@", err);
}
-(BOOL) application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler
{
if ([userActivity.activityType isEqualToString: NSUserActivityTypeBrowsingWeb])
{
NSURL* nsUrl = userActivity.webpageURL;
if (nsUrl == nil) return NO;
QUrl url = QUrl(QString::fromNSString(nsUrl.absoluteString));
auto qmlApplication = qobject_cast<QmlApplication*>(QmlApplication::instance());
qDebug() << Q_FUNC_INFO << url << ":" << qmlApplication;
if (qmlApplication)
{
qmlApplication->openUrl(url);
}
else
{
QmlApplication::setOpenUrl(url);
}
}
return YES;
}
- (void) applicationDidReceiveMemoryWarning:(UIApplication*)application
{
qDebug() << Q_FUNC_INFO;
auto qmlApplication = qobject_cast<QmlApplication*>(QmlApplication::instance());
if (qmlApplication)
{
qmlApplication->lowMemory();
}
}
//------------------------------------------------------------------------------
- (void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
NSLog(@"TEST %@", userInfo);
if (userInfo[kGCMMessageIDKey])
{
NSLog(@"Message ID %@", userInfo[kGCMMessageIDKey]);
}
[self createNotification: userInfo];
}
//------------------------------------------------------------------------------
- (void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
NSLog(@"Received notification: %@", userInfo);
[self createNotification: userInfo];
auto qmlApplication = qobject_cast<QmlApplication*>(QmlApplication::instance());
NSError * err;
NSData * jsonData = [NSJSONSerialization dataWithJSONObject:userInfo[@"payload"] options:0 error:&err];
NSString * myString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
NSLog(@"Yes %@",myString);
if (qmlApplication)
{
qmlApplication->remoteMessageReceived(QString::fromNSString(myString));
}
completionHandler(UIBackgroundFetchResultNewData);
}
//------------------------------------------------------------------------------
- (void) createNotification:(NSDictionary *) data
{
NSDictionary* config = data[@"aps"];
NSString* notificationTitle = config[@"title"];
NSString* notificationBody = config[@"body"];
UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init];
content.title = notificationTitle;
content.body = notificationBody;
content.sound = [UNNotificationSound defaultSound];
content.userInfo = data[@"payload"];
UNTimeIntervalNotificationTrigger *trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:1.0 repeats:NO];
UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:@"new-message" content:content trigger:trigger];
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
// center.delegate = self;
[center addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error)
{
if (error)
{
NSLog(@"Local Notification failed");
}
}];
}
- (void) userNotificationCenter:(UNUserNotificationCenter *) center
willPresentNotification:(UNNotification *) notification
withCompletionHandler:(void (^)(UNNotificationPresentationOptions options)) completionHandler
{
Q_UNUSED(center)
Q_UNUSED(notification)
completionHandler(UNNotificationPresentationOptionAlert);
}
- (void) userNotificationCenter:(UNUserNotificationCenter *) center
didReceiveNotificationResponse:(UNNotificationResponse *) response
withCompletionHandler:(void (^)()) completionHandler
{
NSLog( @"Handle push from background or closed" );
// if you set a member variable in didReceiveRemoteNotification, you will know if this is from closed or background
NSLog(@"%@", response.notification.request.content.userInfo);
}
//------------------------------------------------------------------------------
- (void) messaging:(FIRMessaging *)messaging didReceiveRegistrationToken:(NSString *)fcmToken
{
NSLog(@"FCM registration token: %@", fcmToken);
}
@end
Hi @siddeshpillai,
Based on the files you provided, this doesn't look like the usual setup for iOS. Could you confirm if you're using the C++ SDK? Thanks.
@rizafran I'm using Qt Framework for building this iOS app. Yes, I confirm I'm using the C++ SDK. I'm linking them manually using QMAKE.
@siddeshpillai are you able to receive notifications sent directly via APNs?
@morganchen12 No I haven't tried that yet. But I can give it a shot and keep you posted.
Hey @siddeshpillai. We need more information to resolve this issue but there hasn't been an update in 5 weekdays. I'm marking the issue as stale and if there are no new updates in the next 5 days I will close it automatically.
If you have more information that will help us get to the bottom of this, just add a comment!
@morganchen12 Able to receive notifications sent directly via APNs.
Hi @siddeshpillai, sorry for not getting back to you in this. I'm just wondering if you're still encountering the issue on the latest SDK version?
Hey @siddeshpillai. We need more information to resolve this issue but there hasn't been an update in 5 weekdays. I'm marking the issue as stale and if there are no new updates in the next 5 days I will close it automatically.
If you have more information that will help us get to the bottom of this, just add a comment!
Since there haven't been any recent updates here, I am going to close this issue.
@siddeshpillai if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.