I am implementing Push Notification for iOS using Firebase. I have followed all the steps mentioned over there for push notifications.
When I try to send a message from Firebase server to my app, I get the error in server saying Unregistered registration token.
I am using the token generated in the app. Using this code to get the token :
[FIRApp configure];
NSString *refreshedToken = [[FIRInstanceID instanceID] token];
The Not Registered happens when GCM thinks the device could not handle the message. This happens if the app is uninstalled or misconfigured to handle the message, try uninstalling app manually from phone and run it again
In my app this line was in an If condition, so not called it always.
[[UIApplication sharedApplication] registerForRemoteNotifications];
Related
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
I recently updated my app from GCM to FCM and it was working fine if I installed latest app with out updating the existing one. If I update the app then device not getting push notification. As per server it saying the push sent successfully but device not getting the push notification.
Server Response
Server Response
Observations :
iOS : when I update the app from GCM to FCM I am getting a new token.
Android : If I update the app from GCM to FCM, still the token remains same.
After updating the app on launch function I am calling the below lines,
[[UIApplication sharedApplication] registerForRemoteNotifications];
[FIRApp configure];
[self connectToFcm];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(tokenRefreshNotification:)
name:kFIRInstanceIDTokenRefreshNotification object:nil];
In the above code the token refresh was getting triggered and getting a new FCM token.
- (void)tokenRefreshNotification:(NSNotification *)notification
{
NSString *refreshedToken = [[FIRInstanceID instanceID] token];
NSLog(#"InstanceID token: %#", refreshedToken);
[FCMPlugin.fcmPlugin notifyOfTokenRefresh:refreshedToken];
[self connectToFcm];
}
Is there any flag need to set to make it work in iOS when updating app from GCM to FCM?
Note : By deleting the instanceID I am getting a new token, with that token the device able to get the push.
Old App : with GCM token - Working
New App : With FCM token - Working
Update App : From GCM token - FCM token - Not Working
I've just been trying to migrate my iOS apps over from Google Cloud Messaging to Firebase, and after putting in all the hard work and getting everything working fine for freshly installed apps, I've hit a problem:
If I install an old version of an app (that used GCM for push notifications), then I update that old version to the new Firebase-based version, I don't receive any messages to the device.
The messages are sent fine from the sender side (I use Postman to test), and they are received fine on the freshly installed apps. I'm making sure that the updated apps are getting the Firebase instance token and sending it to my server database (and log for my manual testing) as always, and since the response for the message send is always successful I'm pretty sure there's no problem with my API Key or push token in general.
Sadly that's about the extent of the information I can provide for my question, feel like I'm banging my head against a wall. It's not good enough to ask my user base to uninstall and reinstall the app from scratch, they'll lose their data! (I already migrated to Firebase for my Android apps, they're working fine.)
Anyone have any experience with this? Meantime I'm going back to GCM, 'twas working just fine...
EDIT
As Firebase swizzles methods in the AppDelegate class, it's a lot sparser now, I no longer do anything in didRegisterForRemoteNotificationsWithDeviceToken:. (I do have it defined with just an NSLog function call, it gets called, always twice for some reason.)
didFinishLaunchingWithOptions: looks a bit like this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOption
{
// Configure Firebase and listen out for token updates
[FIRApp configure];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(onTokenRefresh) name:kFIRInstanceIDTokenRefreshNotification object:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
[[UIApplication sharedApplication] registerForRemoteNotifications];
//...
}
And my onTokenRefresh: method is being called fine - I'm getting the new token, I'm able to use it with Postman and server to send out push notifications - I simply don't receive them on the app when it happens to have been updated from a previous incarnation...
- (void) onTokenRefresh
{
NSString *token = [[FIRInstanceID instanceID] token];
NSLog(#"onTokenRefresh called - My Firebase token is: %#", token);
//...
}
I am trying to create a PushNotification app and I am working with PubNub. I have gone through all of the necessary steps to:
Include PubNub libraries on my workspace
Create the proper provisioning profile for the App
Ensured PushNotification was in the profile
Create the proper SSL certificate for the app
Add the certificate to the keychain access
Create the proper .pem file
Uploaded the file to PubNub
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( NSDictionary *)launchOptions
{
// #2 Register client for push notifications
NSLog(#" Options set");
[[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
[PubNub setDelegate:self];
return YES;
}
After getting some initial compile errors, I was able run the app on my device. When I ran the app on my device, I did not receive the "...Would Like To Send Yo Push Notifications" message as I thought I should. I am able to use the PubNun console to send a message and I see the messages are received via the log, but I do not get any notification or banner. I placed an NSLog in the didFinishLaunchingWithOptions method and I see the display in the log.
After that, I deleted the app from the device, deleted the provisioning profile form the device, restated Xcode, and compile and an again with the same results. Not sure what to try next.
EDIT: The specific problem you're running into has to do with the fact that you are running the application through Xcode, and in a nutshell you can't test production push notifications this way, you'd have to use the sandbox push server and certs. If you want to test prod pushes you'll need to distribute the application signed with an Ad Hoc provisioning profile. I'm sure there are a million ways to do this, but actually my two favorites are using Testflight and Crashlytics' new Beta feature, that allows you to distribute ad hoc builds to devices basically using a single line of code, automatically once you archive a new build. I would recommend Crashlytics because it also automatically handles extremely useful analytics as well as crash reporting.
If you are referring to the initial push notifications permissions pop-up, that will only be displayed once or the lifetime of the application. The ONLY way I believe to get around this is to uninstall the up and leave it uninstalled for 3 days (I believe this is the limit).
I'm unfortunately not familiar with PubNub, but in your application are you registering for push notifications and receiving a device token?
Kevin,
If this is all what you try to do, to receive notifications using PubNub service, than it is not enough.
After you receive device push notification token, you need to pass it to PubNub client library, for example like this with default configuration:
- (BOOL) application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Initialise PubNub client.
// Warning, you should use pub/sub/secret keys for your account (at admin.pubnub.com) to
// which you uploaded your development push notification certificate (in .pem file).
[PubNub setupWithConfiguration:[PNConfiguration defaultConfiguration] andDelegate:self];
[PubNub connect];
UIRemoteNotificationType type = (UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeSound);
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:type];
return YES;
}
- (void) application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
[PubNub enablePushNotificationsOnChannel:[PNChannel channelWithName:#"my-test-channe-for-push-notifications"]
withDevicePushToken:deviceToken];
}
// Observe for some PubNub delegate methods related to push notification observation (or use completion block enabled version of API):
- (void)pubnubClient:(PubNub *)client didEnablePushNotificationsOnChannels:(NSArray *)channels {
NSLog(#"PubNub client enabled push notifications on channels: %#", channels);
}
- (void)pubnubClient:(PubNub *)client pushNotificationEnableDidFailWithError:(PNError *)error {
NSLog(#"PubNub client failed push notification enable because of error: %#", error);
}
If you see that push notification enabling has been successful for you, then use http://pubnub.com/console with pub/sub/secret keys from your account at http://admin.pubnub.com to send message into the channel (in our case "aps" payload should be sent to the channel with "my-test-channe-for-push-notifications" name).
I am working on apple push notification service. Now I have implemented the delegates methods as suggested in apple APNS guide. But this also says that one has to send device token received from APNS to provider server.
I am really confused about this thing.
Because when I launched application it asked me if I want to register for remote notifications but then later it never showed anything like that. At that time I had no code to handle this device token. But now it does not show anything like that even if I have deleted and reinstalled the whole application.
Any help would be greatly appreciated.
My code is this
- (void)viewDidLoad {
[super viewDidLoad];
//registring for remote notifications
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge |UIRemoteNotificationTypeSound)];
}
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
NSLog(#"Device token is %#", deviceToken)
}
The message to register for notifications is displayed just one time, at the first installation. To change notifications settings, you can go in notifications settings.