Waiting Period Before iPhone APNs Starts Pushing? - iphone

I am running Push Notification on two test apps. The first test app I got working over a 2 day period. The 2nd test app I tried to implement Push Notification tonight and have been banging my head over it. I am able to swap the certificates and the 1st app receives notifications, but when I use the .pem for the 2nd app, nothing happens.
I have gone through the entire process twice tonight, trying to get the Push to work for this 2nd app. My only conclusion, given that I can swap the .pems and it will work for the 1st app, is that something is wrong with the 2nd .pem or maybe there is a waiting period before the push starts working, and I just didn't realize it during my first setup?
Edit: The problem was that I was using
-(BOOL)application: didFinishLaunchingWithOptions:
in my delegate and not using
-(void)applicationDidFinishLaunching:
I was doing...
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Register for Push Notifications
UIRemoteNotificationType notifyTypes = (UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeBadge);
}
When I should have been doing
-(void)applicationDidFinishLaunching:(UIApplication *)application {
//NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults];
// Register for Push Notifications
UIRemoteNotificationType notifyTypes = (UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound |UIRemoteNotificationTypeBadge);
}

There is a waiting period before Push starts working, though in my experience said period is generally quite short. Make sure that the little dot is green in your App ID page of the provisioning portal - and make sure that it is for the correct App ID and environment (for example, if you're running in debug, make sure that it is configured for development).
Apart from that, it could be an issue with your .pem or provisioning profile as well.
From the Apple Push Reference guide:
You have to modify the profile in some minor way (for example, toggle an option) for the portal to generate a new provisioning profile. If the profile isn't so “dirtied,” you're given the original profile without the push entitlements.
Do you have any errors coming up when you attempt to push?

Related

How to make remote notifications work with CloudKit Subscriptions?

So far I was unable to make subscriptions to work. (receive a push notification on my device, subscriptions appears to be created successfully)
I have been playing with [CloudKitAtlas][1]. I did what it's told on the readme for that proyect:
Requirements
Build
iOS 8.0 SDK and Xcode 6
Enable the CloudKit entitlement in iCloud (from Capabilities)
Change your container name to provision a container in your developer account
I'm able to launch the app, it registers successfully for remote notifications:
2014-06-09 11:15:17.712 CloudKitAtlas[841:220562] Registered for Push
notifications with token:
I'm also able to create records, query them and subscribe:
2014-06-09 11:15:21.966 CloudKitAtlas[841:220934] Subscribed to Item
And if I go to the dashboard I see several subscriptions created.
But then when I create a new record nothing happens, the callback:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)info
Is never executed (Note: I'm running the app on a iPhone 5S, not on the simulator)
I'm using a debug signature with explicit bundle id (no wildcard) and for this app id I also created the corresponding push notifications certificates although I just downloaded them as I have nothing to do with those files.
Am I forgetting to do something?
Am I not testing it properly?
Does anyone manage to get remote notifications on his device triggered by a subscription?
Update 15 / 06 / 14
Apparently it's a bug on apple side, let's wait a couple of weeks.
https://developer.apple.com/library/content/samplecode/CloudAtlas/Introduction/Intro.html#//apple_ref/doc/uid/TP40014599
Update 18 / 05 / 15
In case anyone is wondering this bug was resolved by Apple long time ago and now it works like a charm, although you need to make some considerations:
Make sure the saveSubscription:completionHandler: method executes without errors
If you use [application registerForRemoteNotifications]; You will ONLY get notifications with the app on foreground, it might look like is pointless but it is very useful as this kind of push notifications are "silent" and you don't require user permission to use them
If you want to get old fashion push notifications with the pop up asking for permission and an alert that appears outside of the app and everything you need to use something like:
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:
UIUserNotificationTypeBadge |
UIUserNotificationTypeSound |
UIUserNotificationTypeAlert
categories:nil];
[application registerUserNotificationSettings:settings];
That's all
registerForRemoteNotificationTypes:types
NS_DEPRECATED_IOS(3_0, 8_0, "Please use registerForRemoteNotifications and registerUserNotificationSettings: instead");
// Returns the enabled types, also taking into account any systemwide settings; doesn't relate to connectivity.
enabledRemoteNotificationTypes
NS_DEPRECATED_IOS(3_0, 8_0, "Please use -[UIApplication isRegisteredForRemoteNotifications], or -[UIApplication currentUserNotificationSettings] to retrieve user-enabled remote notification and user notification settings");
That from iOS8 it becomes deprecated is not cause, probably will be?

push notification is not working

I'm trying to enable push notification in my app but it's not working. How ever it was working in my last app. When i integrated it in that app. but now i again test that app it's not working in that app also. By mean of not working is that it's not showing the confirmation or enabling pop view for push notification.i am using 4.6 xcode version and using this line of code for enabling the push notification
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
is there is some issue in new xcode or sdk or there is some change in the code now ?
As far as I know only once you get the notification to enable the PushNotification . i.e the notification which is showing the message "Would you like to enable the notification ........." . Once you click OK on one device you didn't get that same alert on same device on next run . So try to check it on other device or debug the code using the Developer Profile .
In the delegate methods log the error in did fail method and verify
- (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);
}
is the provisioning profile matter ? i mean i am using the wild card
provisioning profile for testing the push notification
Yes, the provisioning profile matters. It must contain a push entitlement for the environment to which you intend to send push notifications (either sandbox or production).
From the Local and Push Notification Programming Guide :
The Team Admin or Team Agent must next create the provisioning profile
(Development or Distribution) used in the server side of
remote-notification development. The provisioning profile is a
collection of assets that associates developers of an application and
their devices with an authorized development team and enables those
devices to be used for testing. The profile contains certificates,
device identifiers, the application’s bundle ID, and all entitlements,
including <aps-environment>. All team members must install the
provisioning profile on the devices on which they will run and test
application code.
And you can't use a wild card provisioning profile. You must use a provisioning profile with a non-wildcard Application ID.
From the Local and Push Notification Programming Guide :
The next page displays your valid application IDs. An application ID
consists of an application’s bundle ID prefixed with a ten-character
code generated by Apple. The team admin must enter the bundle ID. For
a certificate, it must incorporate a specific bundle ID; you cannot
use a “wildcard” application ID.

Why does the iPhone still give me a device token if push is turned off?

The first time I run my app, I get asked if I want to allow push notifications, so I select yes. Now, when I go to settings and turn off all notifications for my app, I still get a device token from - (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken;. Am I, as the dev, responsible to track if my app has any enabled? Or is this a bug?
The device token is generally stored on a server someplace. If the user suddenly decides they want push notifications and turns it back on, their device token has already been generated and stored on your server.
If the device token was not generated, then the user would have to make sure the app has been terminated and then re-launched in order for the device token to get generated.
You can determine if the user has turned off push notifications with the code below
UIRemoteNotificationType remoteNotificationType = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
if (remoteNotificationType == UIRemoteNotificationTypeNone) {
... Do not send push
}

Registering the iPhone application for push notification not working

I have tried out the example found in the link http://www.raywenderlich.com/3443/apple-push-notification-services-tutorial-part-12 , for my iPhone push notification message. I could successfully run all steps except the steps for registering the app for push notification for the first time.
I have followed different variations of the code:
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
But none worked for me. I am testing it in my iPhone 4 and my Xode version is 4.2 , OS is Lion.
Please advice.
You can try the following:
Make sure your Xcode project is configured to use the explicit bundle ID from the provisioning portal
Make sure you're not building the target with wildcard or team provisioning profile, check this on the project AND target settings
If you created your provisioning profile before configuring the app ID for push, regenerate the provisioning profile
Also look at the error object in the UIApplicationDelegate method
application:didFailToRegisterForRemoteNotificationsWithError:
EDIT 1
Open your provisioning profile in a text editor and look for the string
<key>aps-environment</key>
If your profile does not contain this, it is not correctly set up for push.
Here is my workin code sample from application delegate (AppDelegate.m)
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[application registerForRemoteNotificationTypes:UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound];
}
To check if registration went OK, implement these three methods
– application:didReceiveRemoteNotification:
– application:didRegisterForRemoteNotificationsWithDeviceToken:
– application:didFailToRegisterForRemoteNotificationsWithError:
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIApplicationDelegate_Protocol/Reference/Reference.html
Or you can go to Settings to see if there is permissions settings available
like this:
If this problem appears in production (with your application on the appStore), it's very likely because you created/enabled the APNS production mode of your application AFTER having created the distribution profile.
In this case, no other option but to submit again with a correct certificate...
Rule of thumb: ALWAYS enable/create production certificate for your application BEFORE creating the distribution profile.
You can use the method described by 'nduplessis' (see below) to manually check if you application will run notification once approved.
iOS 14 ?
For those who faced with inability to get token, and double checked all the things mentioned above, and developed on iOS 14, and if you have non-english app title, go to Project - Target - Product Name and replace name by $(TARGET_NAME).
I spent entire week on this bug.
Once again: if your app receives token on iOS12, but can not on iOS14, get rid of non-latin chars in names. They say, including entitlements, but as for me, I've managed to make it work and with cyrillic entitlements. To change Product name was enough.
Have you ever seen the push notification dialog in your app? If you dismiss the dialog it takes 24 hours to reshow. Check this by setting the time on your iPhone ahead by 2 days and see if it shows.
Also have you implemented the delegate methods:
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
- (void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
Try putting an NSLog(#"") in the didRegisterForRemoteNotificationsWithDeviceToken and didFailToRegisterForRemoteNotificationsWithError and see it is is getting in there?
Also you require an App Id that is setup for Push notification and you need to have generated the Push notification certificates to send the messages.
You can only register it with a provisioning profile having an app id with push notification services enabled.please Check those steps also.This a good tutorial for starting push notification http://mobiforge.com/developing/story/programming-apple-push-notification-services
Go to Capabilities -> Push Notifications. If there are errors then try out this solution!
If Xcode version was changed from 7 to 8 then try out this solution!
Xcode 7 copies the aps-environment entitlement from your provisioning profile. Turning on push notifications on Xcode 8 adds the entitlement both to your provisioning profile and the entitlements file.
Try adding the aps-environment entitlement to your app's entitlements file, or switch the notification capability off and on again.

How to send push notifications to users' devices, not just my own

I want to ask about what I need to make a Push Notification, I reed a lot of things and Succeeded send a push from my mac to my devices that exists in the organizer (using PushMeBaby source code). but also I'm confused about make it for other devices (all who has my app) and How I get their Token Device number ?
Just in Big title tell me what I need.
Thanks
Use UIApplication's
- (void)registerForRemoteNotificationTypes:(UIRemoteNotificationType)types
The device token will be returned via callback:
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
Then you have to send deviceToken to your server. Note: deviceToken can change from time to time. So you have to check it every time and resubmit to your server if it changes.
Make sure that port 2195 is opened on your router. You should also register your application for remote notifications on Provisioning portal.
Not to promote other peoples stuff but there is an easy way to send notifications with premade code by xtify and Parse google them they are both free.