How to debug Notifications on iOS With Firebase - ios

I have followed the tutorial to setup Notifications on iOS and I have checked that in the application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken token: NSData) function that a FCM token was available FIRInstanceID.instanceID().token().
From the Firebase Console I tried to send a notification (status is Completed) but no notification was received on my iOS Device.
In order to check the 'Apple side', I have uploaded y push notification certificates into another Push Notification Service Provided and it works.
So I would like to know how can I debug my application?

Related

Retrieve the app push token from the device automatically in swift iOS

Is it possible to get a device token (push token) automatically or without registering for push notification in iOS Swift?
Currently, we are getting device token while registering for push notifications:
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
...
}
It's not possible. We can not retrieve the app push token from the device automatically or without registering for push notification in swift iOS

This fake notification should be forwarded to firebase Swift5 iOS

I have gone through the official notification and followed all steps. Also APN certificates are already uploaded on firebase. When i push notifciation from Grow section manually, i receive notification but while while entering phone number with country code in my app, i am getting the following errors.
This fake notification should be forwarded to Firebase Auth
Optional(Error Domain=FIRAuthErrorDomain Code=17054 "If app delegate swizzling is disabled, remote notifications received by
UIApplicationDelegate need to be forwarded to FIRAuth's
canHandleNotificaton: method." UserInfo={NSLocalizedDescription=If app
delegate swizzling is disabled, remote notifications received by
UIApplicationDelegate need to be forwarded to FIRAuth's
canHandleNotificaton: method.,
FIRAuthErrorUserInfoNameKey=ERROR_NOTIFICATION_NOT_FORWARDED})
In Google info.plist, isfirebaseProxyEnable is also set to No.
DidreceiveRemoteNotification method also implemented.
Please help me in solving this problem.
It seems that you don't have APNs set up correctly, check that:
Push notifications is enabled in Capabilities of your app in
Xcode settings.
Background Modes is enabled in Capabilities of
your app in Xcode settings and under it Remote notifications is
checked
Your app ID registered on apple developer site has Push Notification enabled
Background refresh is not disabled on the device or for your app in iOS
Settings
I assume that you have an internet connection during the tests.
If any points of the above need to change, just delete the app completely from the device before re-compile and run it again.
To fix this, make sure you have this function in you AppDelegate file:
func application(_ application: UIApplication, didReceiveRemoteNotification notification: [AnyHashable : Any], fetchCompletionHandler completionHandler: #escaping (UIBackgroundFetchResult) -> Void) {
if Auth.auth().canHandleNotification(notification) {
completionHandler(.noData)
return
}
}

APNS rejects notification with reason "DeviceTokenNotForTopic"

I'm receiving this error only when trying to register for remote notifications using UserNotifications framework.
When using PushKit everything works ok.
dispatch_queue_t mainQueue = dispatch_get_main_queue();
// Create a push registry object
self.voipRegistry = [[PKPushRegistry alloc] initWithQueue: mainQueue];
// Set the registry's delegate to self
self.voipRegistry.delegate = self;
// Set the push type to VoIP
self.voipRegistry.desiredPushTypes = [NSSet setWithObject:PKPushTypeVoIP];
Since Xcode 11 and iOS13 there are changes in PushKit to support CallKit, so I'm trying to use UserNotifications instead, as described in Apple's documentation
Important
If you are unable to support CallKit in your app, you cannot use PushKit to handle push notifications. Instead, configure your app's push notification support with the UserNotifications framework.
I'm registering for remote notifications this way
- (BOOL) application:(UIApplication*) application didFinishLaunchingWithOptions:(NSDictionary*) launchOptions
{
[[UIApplication sharedApplication] registerForRemoteNotifications];
And receiving token:
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
But when I'm sending notification from my server, I get DeviceTokenNotForTopic.
I'm not sure, if UserNotifications framework uses different APNs server or token format is different.
APNS sends such error if bundleID of your app different from the apns-topic that you are sending from the server in request for voip push.
Or a certificate for a voip push is generated for another bundleID.
Error code https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CommunicatingwithAPNs.html
More discussions here. https://github.com/QuickBlox/quickblox-ios-sdk/issues/1020
For me, I had changed the app's name and bundle ID and I hadn't renewed the device token and the certificate for notifications with images.
To solve that, I firstly went to the Certificates, Identifiers & Profiles section of my Apple Developer account and generated a new certificate with the AppGroups Capability.
Then I got a new device token in the calling of the AppDelegate's function
application( _ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data)
After getting the token from the deviceToken parameter and using it for sending the notification, it started working again.
if u r facing devicetokennotfortopic
then just try this
topic should be your bundle id of u r application
i fixed my issue
ex this is u r bundle id
com.app.xxx.SumNotService
i have removed SumNotService
com.app.xxx(this worked for me)
try

AWS SNS push notification not received on iPhone 6 and above

My coworker and I are building an app and implementing push notification feature utilizing AWS SNS API.
The issue here is that some devices work fine but some like iPhone 6,7,8 receive no notification regardless of the OS version (they're mostly iOS 11,12).
We've covered the basic by checking the below points:
notification turned on on all test devices
testers grant permission to receive notification at the app launch time
the p12 certificate uploaded to AWS is valid and the format is correct
The error messages we got from AWS CloudWatch Logs mostly were "bad device token" or "unregistered", but we are sure that we upload the device token as soon as we got it from APNS.
EDIT: actual code added
Register for notification (within didFinishLaunchingWithOptions)
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { granted, error in
if let error = error {
print("\(error.localizedDescription)")
} else {
application.registerForRemoteNotifications()
}
}
Get token
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
print("Successfully registered for notifications!")
// upload token to our database for later use
}
Is there anything we are missing?

iOS Firebase Push Notifications received to first token only, after token changes no longer received

edit: Updating question with new information.
So there's a number of questions out there about Firebase notifications not being received but I've not found one quite like this.
I've recently switched over from using the old p12 APNs certificates to the glorious new p8, and uploaded it to all of my projects on Firebase v4.0.0.
What I'm seeing is, when I do a fresh install of any of my projects, I can send & receive push notifications fine. But after some time, the token changes - and it just stops working - Firebase says "message sent successfully" but no message is received.
Weirdly - my app still receives push notifications to the previous Firebase token, while the new one reported by Firebase isn't working.
Following the advice at Debugging Firebase Cloud Messaging on iOS, I happily debugged the morning away:
Are there any error messages coming back from my Postman firebase attempts? Nope, success:1 every time
Am I getting pushes with app in the background, foreground or neither? Neither.
Are my AppDelegate remote notification registration attempts working successfully? Yes.
Can I directly send a message over APNs, using the new .p8 file? Yes (thanks to this). Messages are being received when I send them directly over APNs just fine!
In the Firebase console, if I send a message to all devices in a project, I receive the message to all devices. But if I try to limit it to my debug device via its FCM token, I get nothing.
So there's one last link that's just not working - appearing to work perfectly for new installs and then bombing after some amount of time - the FCM to APNs link. But how would I debug it?
Here in
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
...
NotificationCenter.default.addObserver(self,
selector: #selector(self.tokenRefreshNotification),
name: .firInstanceIDTokenRefresh,
object: nil)
return true
}
func tokenRefreshNotification(_ notification: Notification) {
if let refreshedToken = FIRInstanceID.instanceID().token() {
print("InstanceID token: \(refreshedToken)")
// Here you get the refreshed token
// here you can connect to fcm and do subscribe to notifications
}
}
Hopefully it will solve the problem.

Resources