Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 9 years ago.
Improve this question
Problem:
The app doesn't appear on notification center and it is unable to receive push notifications right after installation completes and the app registers for push notifications via registerForRemoteNotificationTypes:.
Details:
The app usually appears in notification center after the device is restarted and after that everything works just fine.
Sometimes the app shows up in notification center right after intallation and registration for APNs(I still can't confirm this but I think I stumbled upon such situations).
The app calls the method registerForRemoteNotificationTypes each time a user logins and each time a user logouts respectively with bit masks (UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound) and UIRemoteNotificationTypeNone.
enabledRemoteNotificationTypes returns correct values.
Initially I used the method unregisterForRemoteNotifications on logout but I changed it to registerForRemoteNotificationTypes:UIRemoteNotificationTypeNone due to suspicians that this could be causing the problem .
This problem occurs in both development and adhoc builds and irrespectively of whether the app is installed via xcode or itunes.
Any thoughts and advices will be greatly appreciated. Thank you!
This was happening to some of my devices. (Not showing up in notification center and not receiving pushes.)
Managed to fix it by doing:
Delete the app
Delete all the relevant profiles from the device. Settings app > General > Profiles, then tap into each of the Provisioning Profiles related to your app, then tap Remove. On iOS 8/9, where the setting no longer exists, use XCode > Windows > Devices > select device > Show provisioning profiles... > then remove the profile(s)
Turn your phone off, then on again.
Give 5 mins
Reinstall your app, the Provisioning Profile should get installed automatically.
Launch app and let it register and stuff.
Test push notifications again
For us, it didn't work immediately, so give it a few minutes.
Maybe there is a problem with registering and unregistering the app at login/logout respectively, from Apple's documentation:
An application should register every time it launches and give its provider the current token.
And not sure about unregistering, they don't mention unregistering in their programming guide, maybe the app should never unregister and the server should handle that, by sending or not sending push notifications depending if the user is logged in or not. This is how I've done it in the past, and never experienced this issue, so maybe this approach works for you too.
Well, I also have this problem, I found that as the application used the unregisterForRemoteNotifications before uninstall at the previous install.
And, in addition, if the application install again and login to register for the remote notifications, this problem will happen.
It happened also at the first install(installed after reset your iOS device). if you use the unregisterForRemoteNotifications before login, then register at the login operation, this problem will happen.
As this problem happened, you need to restart the iOS device.
For the unregisterForRemoteNotifications, we couldn't stop this problem, but we can reduce the probability of the occurrence of the problem, the method is:
If the device token didn't delete from provider at the previous install, then use unregisterForRemoteNotifications at the current install before login;
Otherwise, you should never use unregisterForRemoteNotifications.
Related
I am developing an app that uses push notifications, and testing on a device with iOS 5.1.1. I would like to test the scenario where the user is prompted about push notifications during the app's first run. The dialog appears the first time I call registerForRemoteNotificationTypes, but never appears again, even if the app is re-installed from scratch. How can I clear the setting so that the dialog will appear again?
The same question was posted before, but the answers do not work for iOS 5 or later, as noted in the comments there.
Apple's documentation says to uninstall the app and mess with the clock to make it look like the app was uninstalled for a day, but this does not work on iOS5.
Another answer suggested running General -> Reset -> Erase All Content And Settings - I tried this, but it froze my device and I ended up having to power-cycle it. In any case, this is a heavy-handed solution that is not practical for testing.
Another answer suggested removing your app's entry from /private/var/mobile/Library/RemoteNotification/Clients.plist, but this file does not exist on iOS5.
Is there a way to accomplish this on iOS5?
I found a solution that works if your device is jailbroken:
Use an app like iFile to open the file /var/mobile/Library/SpringBoard/applicationstate.plist with a property list viewer
Find your app's bundle identifier and delete the key SBRemoteNotificationClient
Restart SpringBoard - either reboot the device, SSH to the device and run killall SpringBoard, or use the Respring app.
Next time you run your app, it will show the notification permission dialog once again.
I've tested this on iOS 5.1.1.
Provided your code paths for iOS 5 and iOS 6 aren't too different, the easiest option is probably to just test that specific behaviour on iOS 6 — the callbacks you get on iOS 5 should be similar enough for it not to be an issue.
Alternatively, change the app's bundle ID. Slightly tedious (in the past I've needed to restart Xcode for it to notice that change in bundle ID), and you'll need a wildcard provisioning profile handy.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
When my iPhone application start, I want to notify the user if there is a new updates / version released on App store.
Does anybody have any ideas or has anybody else achieved anything similar?
Thanks
Use Nick Lockwood's iVersion library. It's whole purpose is to notify the user when new updates are available.
iVersion is a library for dynamically checking for updates to Mac/iPhone App Store apps from within the application and notifying users about the new release. It can also notify users about new features in the app the first time they launch after an upgrade.
Purpose:
The Mac and iOS App Store update mechanism is somewhat cumbersome and disconnected from the apps themselves. Users often fail to notice when new versions of an app are released, and if they do notice, the App Store's "download all" option means that users often won't see the release notes for the new versions of each of their apps.
Whilst it is not permitted to update an App Store app from within the app itself, there is no reason why an app should not inform the user that the new release is ready, and direct them to the App Store to download the update.
And if your app is not on the App Store, either because it's an in-house/enterprise iOS app, or a Mac app delivered to customers outside of the store, you can't use the App Store update mechanism anyway.
iVersion is a simple, zero-config class to allow iPhone and Mac App Store apps to automatically check for updates and inform the user about new features.
iVersion automatically detects when the new version of an app is released on the App Store and informs the user with a helpful alert that links them directly to the app download page.
Or if your app is not on the store, iVersion lets you specify a remote plist file to check for new releases, and a download URL where users can get the latest release.
iVersion has an additional function, which is to tell users about important new features when they first run an app after downloading a new version.
These excerpts were taken from the Github page here, where you can download it. There is also a comprehensive tutorial on installing and configuring iVersion, so I recommend that you check it out.
Hope this helps!
To give a comprehensive answer. There are basically two ways you can go here. Depends on where you want to put the responsibility.
App checks for new versions on server
Using this approach, you would add a method to your app that is being called on every launch to compare the current version of the app (wherever you want to save that) with the version stored on the server. To achieve this, the server must implement a small web service that returns the latest version as a string or something else very simple. No rocket science there.
Server pushes new version information to app
This way you implement more code on the server-side to do a Push Notification to your app which informs the app about the new version. Advantage here is: Less client-side code and less effort to check, because the version check does not happen every time the app is started but instead only once the new version is actually released.
you can do a call to your server when the app starts.
and that way check for a news item in your database, for example.
When the server gives you something. show it in an alert.
On the other hand, when there is an update in the appstore, doesn't the iphone give a warning?
APNS - Apple Push Notification System
Try it and google for ready server solutions.
Update: Okay, lets get it longer -
APNS is the best way to inform user about something new. It works with every state of the app - even when app closed - and it helps to avoid unnecessary requests to server.
But you will need server to send pushes - if you can write it by yourself - it's nice, but the are some services to create backend for your app (no links - no ads, just google it).
To find out how to start with APNS on the client side and how to create all needed certificates and keys read this one
Just check the latest version by communicating with your server and compare with the current version of app when the app starts up, if there is a newer version, notify the user.
Apologies in advance for the plug - but I think a service I built extending the concept from my experience building many apps solves this problem. Look at CleverStork - an Update Manager for Apps
There is something known as Silent notifications from iOS 7 and above, you can use that for
this
I am using APNS service in my universal app (iPhone/iPad) and i am not geting notifications on device. Previously i was getting notifications perfectly but now a days with the same code at server side and client, it is not working.
On server side notification status is delivered but i am not receiving it on my device.
I have checked most of the questions on stackoverflow but i was unable to find my question. one guy said that in development environment it may have delays, but my problem is that i am not receiving notifications at all.
Note: i am using sandbox environment not production.
Just in case you haven't found a solution yet, one additional thing you could check is if your device's date and time is properly set (in the OS). If your iPod, iPhone or iPad isn't set to the current date, we found that notifications are ignored silently. Of course, there are many other possible explanations as to why your service stopped working, but this is a simple thing to check when everything else appears to be fine.
Following are the things you can check
Check the entitlements while codesigning the app. (They can be seen in Xcode build log).
Check whether notifications are on for the device in the settings menu.
If you are using corporate network on the iOS device, the push notifications might be blocked. Try using a different network.
After launching the app, check the organizer for any logs with the reason why push notifications can not be enabled.
I hope some of this helps you out.
I just revoke my certificates
Uploaded new certificates deleted all provision from my organizer
and then created new provisions and installed them on my system.
At the same time I got my APNS working.
When a app has a push notification feature implemented at what point in time do we see the app name under Settings-->Notifications for enabling/disabling notifications?
Is it when you install the app and IOS will automatically come to know this or we need to run the app at-least once to see this option.
I am seeing two different cases: When I install the app on my iPod touch I immediately see the Push notification enabling switch in Settings but when I install it on my iPhone it do not show this option even after running the app. What could be the reason?
It shows when you register the app for push notifications in code. The reason it is showing up for you as soon as you install it on one of your devices is that you have already accepted it on a previous install of the same app, and uninstalling/reinstalling unfortunately does not cause iOS to forget this.
I am developing an app with push notifications. To check all possible ways of user interaction, I'd like to test my app when a user declines to have push notifications enabled for my app during the first start.
The dialog (initiated by registerForRemoteNotificationTypes), however, appears only once per app. How do I reset the iPhone OS's memory of my app. Deleting the app and reinstalling doesn't help.
Technical Note TN2265: Troubleshooting Push Notifications
The first time a push-enabled app
registers for push notifications, iOS
asks the user if they wish to receive
notifications for that app. Once the
user has responded to this alert it is
not presented again unless the device
is restored or the app has been
uninstalled for at least a day.
If you want to simulate a first-time
run of your app, you can leave the app
uninstalled for a day. You can achieve
the latter without actually waiting a
day by setting the system clock
forward a day or more, turning the
device off completely, then turning
the device back on.
Update: As noted in the comments below, this solution stopped working since iOS 5.1. I would encourage filing a bug with Apple so they can update their documentation. The current solution seems to be resetting the device's content and settings.
Update: The tech note has been updated with new steps that work correctly as of iOS 7.
Delete your app from the device.
Turn the device off completely and turn it back on.
Go to Settings > General > Date & Time and set the date ahead a day or more.
Turn the device off completely again and turn it back on.
UPDATE as of iOS 9
Simply deleting and reinstalling the app will reset the notification status to notDetermined (meaning prompts will appear).
Thanks to the answer by Gomfucius below:
https://stackoverflow.com/a/33247900/704803
Another just for testing solution to this is by simply changing your bundle id. Just don't forget to change it back once you're done!
On iOS 9.0.2, I'm getting the "register push notification alert" every time I delete the app and reinstall it. This is true for both AppStore production downloads and adhoc mode.
UPDATE: It is confirmed this is working for iOS 9.x
As already noted the approach for resetting the notification state for an app on a device is changed for iOS5 an newer.
This works for me on iOS6:
Remove the app from the device
Set the device datetime two days or more ahead
Restart the device
Set the device datetime two days or more ahead
Restart the device
Install and run the app again
However this will only make the initial prompt appear again - it will not remove any other push state related stuff.
The plist:
/private/var/mobile/Library/RemoteNotification/Clients.plist
... contains the registered clients for push notifications. Removing your app's entry will cause the prompt to re-appear
Doing it programmatically seems to work for me everytime.
I have a build with the following line uncommented:
[[UIApplication sharedApplication] unregisterForRemoteNotifications];
I run it every time I want to unregister from PN. You might have to end the app explicitly from the recents list and play around with the Notification Center in Settings app to get it right.
Also, the UI prompt asking the user to register for PN may not show up. Not sure if has been disabled in any of the recent iOS versions.
I agree with micmdk.. I had a development environment setup with Push Notifications and needed a way to reset my phone to look like an initial install… and only these precise steps worked for me… requires TWO reboots of Device:
From APPLE TECH DOC:
Resetting the Push Notifications Permissions Alert on iOS
The first time a push-enabled app registers for push notifications, iOS asks the user if they wish to receive notifications for that app. Once the user has responded to this alert it is not presented again unless the device is restored or the app has been uninstalled for at least a day.
If you want to simulate a first-time run of your app, you can leave the app uninstalled for a day. You can achieve the latter without actually waiting a day by following these steps:
Delete your app from the device.
Turn the device off completely and turn it back on.
Go to Settings > General > Date & Time and set the date ahead a day or more.
Turn the device off completely again and turn it back on.
As ianolito said, setting the date should work:
You can achieve the latter without actually waiting a day by setting the system clock forward a day or more, turning the device off completely, then turning the device back on.
I noticed on my device (iPhone 4, iOS 6.1.2) setting the system clock a day forward or even a few days did not work for me. So I set the date forward a month and then it did work and my application showed the notifications prompt again.
Hope this helps for anyone, it can be kind of head aching!
I have wondered about this in the past and came to the conclusion that it was not actually a valid test case for my code. I don't think your application code can actually tell the difference between somebody declining notifications the first time or later disabling it from the iPhone notification settings. It is true that the user experience is different but that is hidden inside the call to registerForRemoteNotificationTypes.
Calling unregisterForRemoteNotifications does not completely remove the application from the notifications settings - though it does remove the contents of the settings for that application. So this still will not cause the dialog to be presented a second time to the user the next time the app runs (at least not on v3.1.3 that I am currently testing with). But as I say above you probably should not be worrying about that.
The same tech note as refered to in the accepted answer (TN2265 - Troubleshooting Push Notifications) has since been updated with a solution for iOS 5 and above.
In short: create a backup and restore from it every time.
On iOS 5 and later, reset the push notifications permissions alert by restoring the device from a backup (r. 11450187). Here are the steps to do this efficiently:
Use the Xcode Organizer to install your app on the device. The key is to install the app for the first time without running it.
Use iTunes to back up the device.
Run the app. The push notifications permissions alert will be presented.
When you want to reset the push notifications permissions alert, restore the device from the backup you created in the first step.
The Apple Tech Note also described you can restore the device to reset the Push Notification dialog.
It does not say that you can also use the option "General -> Reset -> Erase All Content And Settings" on the device itself (iOS 5.x).
I recently ran into the similar issue with react-native application. iPhone OS version was 13.1 I uninstalled the application and tried to install the app and noticed both location and notification permissions were not prompted.
On checking the settings, I could see my application was enabled for location(from previous installation) however there was no corresponding entry against the notification Tried uninstalling and rebooting without setting the time, it didn't work. Btw, I also tried to download the Appstore app, still same behavior.
The issue was resolved only after setting the device time.
In addition to the answer of ianolito.
Had the same issue with an app I downloaded a year ago and denying push notification initially. Now wanting push notifications back, these steps worked for me on iOS 7 beta. Not sure which point(s) triggered it exactly.
Close and delete the app.
Go to your iCloud settings and delete the app from the iCloud. Do this on all other devices where you have iCloud backup for apps enabled. After deactivating and deleting make a fresh backup. The app should not be listed any more under the backups. (This is maybe why the Technical Note from Apple described by ianolito stopped working in iOS 5, since iCloud was introduced in iOS 5 and many have iCloud backup for apps enabled.)
Go to your time settings and set the time more than 1 month ahead.
Switch the iPhone off (no reset).
Wait a minute, switch it on again and download the app again.
Start the app and I was presented the dialog again.
Enable app backup again, since it is still deactivated. Correct the time.
Thank god I did not have to "Erase All Content And Settings". Maybe it will help someone.
After hours of searching, and no luck with the suggestions above, this worked like to a charm for 3.x+
override func viewDidLoad() {
super.viewDidLoad()
requestAuthorization()
}
func requestAuthorization() {
if #available(iOS 10.0, *) {
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { (granted, error) in
print("Access granted: \(granted.description)")
}
} else {
// Fallback on earlier versions
}
}