I am now using an calendar app, it allow me to set a reminder and it reminds me even I am at Airplane mode.
How can I do the same thing in my program?
you can use UILocalNotifications,
here is the url
https://developer.apple.com/library/ios/documentation/iPhone/Reference/UILocalNotification_Class/Reference/Reference.html
Your calendar alert is a local notification set on your device. It isn't a push notification to require internet connection.
Refer the examples of notification usage here
Related
I am trying to get my device unregistered from the remote notification services in my app, so I tried to use [[UIApplication sharedApplication] unregisterForRemoteNotifications]. But this does not work. My app still shows up on the notifications section of my iPhone's settings app. Is there any other way I can do this?
It is still there but it won't receive any notifications. That is the default behavior, once you registered your app will remain in the notification center and it will be activated/ deactivated when you register/unregister for remote notifications.
Unregister function is not related to iOS app setting.
Only if you turn on the setting and register notification by function, you can get the notification successfully.
If even one of them is off, you should not receive any notification.
I am using UILocalNotification in my app to schedule notifications. The notifications work fine and show up when I want them to. I dont have an issue with that. I am NOT doing any remote/push notifications.
What got me wondering is that I never saw the famous permissions dialog that you usually see for push notifications in several app. I even reset my device and ran my app. That still didn't cause the permission dialog to show up.
Does this permission dialog not show up if your app is using only local notifications or am I not implementing some method that actually causes the app to ask for this permission?
I know I could implement my own dialog after the app started that asked the user for this permission but I was hoping that Apple took care of that, especially since it treats remote and local notifications the same in the Settings app.
Yes, in iOS8, local notifications do require permissions.
The documentation for registerUserNotificationSettings: stipulates that
If your app displays alerts, play sounds, or badges its icon while in the background, you must call this method during your launch cycle to request permission to alert the user in those ways.
Typically, you make this request if your app uses local or push notifications to alert the user to new information involving your app.
It is recommended that you call this method before you schedule any local notifications or register with the push notification service.
It looks like local notifications do not need any user permission. The Permission dialog just shows up for the Push Notifications. I am able to schedule/cancel local notifications without any user permission.
NOTE: this includes push notifications / remote notifications
when using Xcode6 with iOS7 or iOS8
Test when registerUserNotificationSettings: API is available at runtime.
if ([application respondsToSelector:#selector(registerUserNotificationSettings:)]) {
UIUserNotificationSettings* notificationSettings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];
[[UIApplication sharedApplication] registerForRemoteNotifications];
} else {
[[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
}
Thanks to http://corinnekrych.blogspot.ae/2014/07/how-to-support-push-notification-for.html
Apple's documentation for presentLocalNotificationNow and scheduleLocalNotification says,
Prior to scheduling any local notifications, you must call the registerUserNotificationSettings: method to let the system know what types of alerts, if any, you plan to display to the user.
So I am not sure how others in this page are saying Local Notifications do not need User Permissions.
Checkout this other discussion on the same topic:
Ask for User Permission to Receive UILocalNotifications in iOS 8
Yes, that's correct. Local notifications do not need any OS permissions. However, as a good practice, I'd suggest giving an opt-out option for the user in such cases from your application.
This would work well in two ways:
An annoyed user, getting frustrated because of seeing local notification yet time & again, not knowing the difference between Push/Local notification might leave a bad review on the app store.
Its always a good practice to provide flags to turn ON/OFF such functionality for a given user.
Am developing an iPhone app. In my current iPhone app i want to integrate APNS that we want to send a messages to the user. I gathered information about APNS. But, still i have some doubts on the APNS.
How APN works that means how the push notifications showing to the user?
If our iPhone app get closed from Background, the Apple push notification will work or our app should be in run?
What will happen if we send a notification to the user but,if the user is in offline. The message will deliver to the user once the user gets online (Get network connection) or the message won't show to the user?
Push Notifications will be show the user if the user doesn't open the app in their iPhone?
Can anyone please guide me on these doubts? I hope on you friends. Please help me. Thanks in advance.
I think you did not follow Apple developer library instructions. I have doubts about your understanding of APNS and its working.
When you send the notification to user, and his cell is off or not connected to the internet, he/she will get message/notification when his/her cell will turn on or connect to the network.
And Push Notifications also work when your application is in backGround or user is not using the application.
Hope this information can clear your confusion, you should look in to the apple developer videos and SDK about push notifications.
Also this is SOreadytohelp.
You asked quite a few questions. I'll try to answer some of them as well as I know:
How APN works: You send a message to Apple's servers with the specific device ID. Apple will deliver that message to the iOS device. (You likely want a more specific answer, so please ask.)
If your app has been allowed background app notifications, then they will be delivered in the background. (The user can enable/disable this)
If the particular iOS device is not connected to the network, notifications will be queued. But, identical notifications will get discarded and only the most recent will get delivered. See: Quality of Service
Yes (basically the same answer for 2).
I'd like to be notified of certain events on my webserver with a push notification from my website to my iPhone. Is this somehow possible, or do I have to install/create a special App for this?
In order to use Push Notification it would have to be a native iPhone app on your phone. You might be able to set up some sort of email notification coming from your website and turn on push notifications for your mail client on your iPhone.
In regards to #gnuf's post (Sorry it wouldn't let me comment on your post) Your web server can act as the Provider of Push Notifications but will still require a native application on the phone to receive the notifications.
You can definitely send notifications triggered from a website: you just have to hook up the backend to do so. See this previous post for more information.
I am using Apple Push Notification in my application.
when my application is installed on device i want application to ask user if they want allow application to use notification or not, how can i implement so?
something like this application.
Thanks.
You don't need to do any extra work for that. Just configure your app for push notifications and call:
[[UIApplication sharedApplication] registerForRemoteNotificationTypes: types];
This happens automatically when an app asks to register itself for push notifications, just as it does when an app first asks for the device's location. You don't need to do anything special beyond the -registerForRemoteNotificationTypes: call (as Max mentioned) which you have to make anyway.