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?
Related
I have created an independent watchkitapp in XCode, installed in apple watch and successfully sent push notification without errors from Pusher app (also in node-apn) but the notification does not arrive in app. (Tried another app for iOS and remote push notification successfully received in iOS app)
These are the steps i took
In my watchkitapp I did WKExtension.shared().registerForRemoteNotifications() and took the device token
UNUserNotificationCenter.current().requestAuthorization and allowed push notification on apple watch. ofcourse I set UNUserNotificationCenter.current().delegate to the InterfaceController (I tried Local Notification and local notifications display normally on the watch)
On XCode watchkitapp.watchkitextension I added Push Notification on capabilities
In Apple Developer page I created app id mirroring the watchkitapp bundle (not the watchkitextension one). In my case apple automatically created App Id in the server but I removed and recreated it to make sure
Checked the Apple Push Notification service and generated Development SSL Cert
Downloaded the Development SSL Cert and installed in keychain
Opened the Pusher app and selected the installed Development SSL Cert from the list. Ran the apple watch app and obtained the Token Id... sent the payload and it says the payload is sent
Tried to restart mac, iphone, apple watch, unpairing apple watch, reinstalling app but the result is the same... push is sent but does not receive in apple watch
anybody can help me how can I fix this?
Finally, I got this successfully. I use node-apn to send from server.
Here are the worth noticing things:
create app id of the watchkitapp bundle in Apple Developer page
install the latest version of: node-apn,
"dependencies": {
"apn": "git+https://github.com/node-apn/node-apn.git#3.0.0",
[...]
}
should set apns-push-type
notification.pushType
(Required when delivering notifications to devices running iOS 13 and later, or watchOS 6 and later. Ignored on earlier system versions.)
The type of the notification. The value of this header is alert or background. Specify alert when the delivery of your notification displays an alert, plays a sound, or badges your app's icon. Specify background for silent notifications that do not interact with the user.
The value of this header must accurately reflect the contents of your notification's payload. If there is a mismatch, or if the header is missing on required systems, APNs may delay the delivery of the notification or drop it altogether.
I am building a TVOS app for the new Apple TV that needs to get notifications from a server to update it's display. Remote notifications are not allowed with TVOS, and it actually displays an error when you try to register the app for remote notifications.
With this being said, are there any alternatives to what I need?
To clarify:
- The app stays running indefinitely, showing a display.
- When the user adds content to the display, I want to notify any apps that are logged in to the same user to update the display.
- I cannot use remote notifications.
Please let me know if this makes sense, and thank you in advance for your help!
What part of the registration errors out for you? Notification dialogs and banners may not really make sense on tvOS, but can you send a silent push notification? All you need to do to register for these is
[application registerForRemoteNotifications];
You do not need to display the request dialog to the user for permission for silent notifications (you do need to have the remote notifications entitlement though.)
According to Apple's documents here, they allow CloudKit. CloudKit subscriptions rely on silent push notifications that I would assume would work on tvOS (without them it would severely cripple CloudKit)
If that still does't work, then you could create your own long polling connection (essentially, you would be making your own custom push notifications). It would only be able to send messages to devices that have the app opened however.
I guess you can have the app poll a web server at a given interval to check if any updates have been made...
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.
I have an app which was supposed to have push notifications enabled, but for some reason doesn't have them. I've seen other people download and install the app, and it doesn't even prompt them for permission to send push notifications. As expected, this app doesn't appear in their Settings > Notifications.
However, on my iPad, I am able to receive push notifications from this app, and it does show up on my Settings > Notifications. I have deleted and reinstalled the app to make sure I had the same thing everyone else has (and not a development version), and I'm still able to get notifications.
Now, this app was written for a client who sent me all the provisioning profiles (dev, adhoc, distribution) as well as the files needed to be able to send push notifications, so I can't know for sure that everything was properly created.
My theory right now is that:
the adhoc profile I received was "properly created" (i.e. generated after setting up APNs on the app's App ID in the Provisioning Portal)
the distribution profile I received was generated before setting up APNs for this app (and thus, it's not "push enabled")
the reason I'm able to receive push notifications on my device is because during development I installed an adhoc version, which prompted me for permissions to receive push notifications, and even though I've deleted this adhoc version and downloaded the version from the store, the device has "cached" the fact that I'm willing to receive notifications and no longer prompts me for it. I've checked with other apps and indeed, after I delete and reinstall them, they won't prompt me again for permissions to receive push notifications.
So my questions are:
Does this theory make sense?
If it does, this means I'll have to ask the client to generate a new distribution provisioning profile. How can I verify that this profile is "push enabled"? (i.e. considering that I can't just install an app compiled with it)
Ok, I may have found a way to verify whether or not the profiles have push enabled.
If I open the .mobileprovision file as a text file, there is a bit of XML there (a plist apparently) which I'm guessing for a distribution profile should have this:
<key>aps-environment</key>
<string>production</string>
And indeed, the adhoc profile had this and the distribution profile didn't, so... I'm guessing this was the problem.
Still, any feedback would be helpful :)
Slightly different, but still useful: when you upload an app to iTunes connect, you can check whether it has Push notifications (or any other entitlements) enabled.
To do this, go to Manage your Applications, select the application, then go to "View Details" for the version you want to check.
From there, go to the "Binary details" page - there's an Entitlements field that shows what the entitlements the binary has. If Push Notifications are enabled, you'll see a "aps-environment: production" line in there.
Make sure that the distribution provisioning profile is generated after creating aps_certificate. High changes the profile may miss out aps-environment
I added the following to AppDelegate.m so I could see exactly what settings were enabled in debug
- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
UIRemoteNotificationType enabledTypes = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
NSLog(#"Receiving Notification Types: %lu", (long)enabledTypes); //0=none 1=badge 2=sound 4=alert 8=NewsStandContantAvailability
I got this from a Very inclusive and useful link: Apple Push Notification Service Tutorial - Part 1
it was extremely helpful for me.
How to test feedback.sandbox.push.apple.com? Everything goes right, but I receive empty list.
How to make it consider the device token as inactive?
I installed the application to iPhone using Xcode, received some push notifications, then removed it from iPhone and send some more notifications. But even on the next day feedback.sandbox.push.apple.com returns just empty set.
Issues with Using the Feedback Service
If you remove your app from your device and then send a push notification to it, you would expect to have the device token rejected, and the invalidated device token should appear on the feedback service. However, if this was the last push-enabled app on the device, it will not show up in the feedback service. This is because deleting the last app tears down the persistent connection to the push service before the notice of the deletion can be sent.
You can work around this by leaving at least one push-enabled app on the device in order to keep the persistent connection up. Just install any free push-enabled app from the App Store and you should then be able to delete your app and see it appear in the feedback service.
source:
http://developer.apple.com/library/ios/technotes/tn2010/tn2265.html#TNTAG34
I far as I found, Apple push notification feedback service doesn't work properly on sandbox mode. You should try it on ad-hoc or production mode.