didFinishLaunchingWithOptions not Showing Initial Alert (PubNub) - ios

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).

Related

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

Google Play Services iOS 's push notifications is not working

I'm testing Google Play Service in iOS with TBMPSkeleton from https://github.com/playgameservices/ios-basic-samples
I did upload all APNS Certificate in Google Play Console (link) but when running game on devices, i didn't receive any notifications when having invitations or when match status changed in both development or production environment. Debugging show that game did receive APNS token successfully, i did test my certificates using php scripts from https://www.raywenderlich.com/123862/push-notifications-tutorial and sent push notifications successfully.
So what wrong with my project? Did i config something wrong? I'm using XCode 7.3.1 (7D1014), Google Play Service 5.1.1
Check the Adding Push Notifications in Your iOS Game.
It's good that you were able to download your APNS certificate. But that's just step 1. The succeeding steps are:
Step 2. Create a provisioning profile that contains push notification entitlements. To learn how to create a provisioning profile, you can refer to the Apple Developer Provisioning and Development documentation, under 'Creating and Installing the Provisioning Profile'. Make sure to drag the provisioning profile to your test device in the organizer.
Step 3. Upload the .p12 file that you created to the Google Play Developer Console. The .p12 file must be in the PKCS #12 format, and must contain only a single certificate.
Step 4. Register your app to receive push notifications after the user successfully signs-in. Add the following code in your finishedWithAuth:error handler, at the point where the user has successfully signed in to Google Play games services. This brings up the standard iOS push notifications dialog. If your game already has registered for push notifications by implementing this code elsewhere, then you don't need to add this line again.
[[UIApplication sharedApplication] registerForRemoteNotifications:
(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert)];
Step 5. In your appDelegate, add the following code to the callback for retrieving the push device token passed back from APNS. This device token is used for outbound push notifications, and your app must register it with the Google Play games services push service. Make sure to always register your device token through GPGManager to enable push notifications from Google Play games services. Even if the user has not signed in; the GPGmanager object will cache this token and save it until the user signs in.
- (void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken
:(NSData *)deviceToken {
NSLog(#"Got deviceToken from APNS! %#", deviceToken);
[[GPGManager sharedInstance] registerDeviceToken:deviceToken
forEnvironment:GPGPushNotificationEnvironmentSandbox];
}

How to get device tokens as Apple Push Notification Service provider?

I would like to add support for sending Apple Push Notifications to a iOS app. This is a news app, so every time some important news event has occurred, then I would like to broadcast a push notification to all users and devices where the app is installed.
According to the Apple Push Notification Service documentation, in Figure 3-3 the Client App must send the device token to the Provider.
In order to be able to send Push Notifications to all devices where my app is installed, do I have to create a webservice which receives and stores device tokens from the client apps when they register for notifications? In order to send a push notification, I need a token and the payload. I want to send a push notification to all users, typically many thousand users. So how can I best get access to the device tokens so that I can send the push notification to all users?
Yes. You will have to make a web service for sending the push notifications to any of the devices that are using your app. As far as the device tokens are concerned, you can get them through your code using this :
- (void)applicationDidFinishLaunching:(UIApplication *)app {
// other setup tasks here....
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
}
// Delegation methods
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken {
const void *devTokenBytes = [devToken bytes];
self.registered = YES;
[self sendProviderDeviceToken:devTokenBytes]; // custom method
}
- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err {
NSLog(#"Error in registration. Error: %#", err);
}
You need to write this in your AppDelegate.m, this will fetch the device token needed to send the push notifications.
Also, you can store those tokens on some Database server for further usage in sending notifications. You can use these tokens the next time when you want to send some notifications to selected or all of the users.

parse push notifications not working ios

I installed Parse sdk on my iphone app. This is for xcode 4.5.
I get the modal request to enable push notifications.
The subscription is successful. The token shows up on the parse web app.
Says 1 user subscribed.
But I dont get a notification from the web app.
I just cant understand what to do here.
All the provisioning madness should be correct.
Was done for development.
I am using the below code to listen for the notifications.
But never gets fired. What am i doing wrong here???
- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo {
NSLog(#"received push %#", userInfo);
[PFPush handlePush:userInfo];
}
Check your app's push notification page in the Parse dashboard, which should be at https://www.parse.com/apps/(your app)/push_notifications. If the push notification doesn't appear there, then your notification didn't get sent, and the problem is on the web app's side.
Try sending the push notification while your app isn't running. If you get the notification, then it's something in your app. If you don't get the notification, then you must have set up the push notification incorrectly somewhere.
Also, Parse has a pretty detailed tutorial.

send device token to server from apple push notification service

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.

Resources