iOS Persistent Notification / Quick Launch - iphone

I'm curious if anyone can provide information on how apps like AppSwitcher use the notification center to create persistent quick-launch notifications.
I know that they are using a url to do launch apps, but what I'm looking for is how to create the notification and keep it persistent.

If your app creates a notification and doesn't clear notifications programmatically, it will remain in Notification Center until the user clears all notifications from your app.

The best I've been able to come up with is calling something like a following ever so often:
[[UIApplication sharedApplication] cancelLocalNotification:localNotification];
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
This will delete the current notification, and replace it with a new one. However, it's not really persistent, and another drawback is that the screen will turn on when the notification gets refreshed. Still searching for a better way.

Related

How to turn Auto-Lock to Never in Swift?

Is there any Swift command to actually set the Auto-Lock to Never or a specific time period? I want to create a simple app that only has two buttons: one is to set the Auto-Lock to Never and the other one is to set it back to iOS default (1 min).
So when a user open this app and tap the Never button, s/he can open other apps but the iPhone or iPad will never auto lock while running the other apps. If s/he is done with other apps, s/he can open this app again and tap the Default button to set the Auto-Lock back to 1 min.
I understand this can be done from the Settings but I am just curious how I can do it from the backend using Swift.
I am new to Swift, btw.
Thanks much!
So when a user open this app and tap the Never button, s/he can open other apps but the iPhone or iPad will never auto lock while running the other apps
You can't do that. You are sandboxed. You cannot affect what happens to the user while running some other app.
When app is open, try to disable the idleTimer in viewDidLoad
UIApplication.shared.isIdleTimerDisabled = true
When app is closed to open other apps, try to -enable again idleTimer when yourViewController disappears, so put this in viewDidDisappear
UIApplication.shared.isIdleTimerDisabled = true
You need to make use of this API call to set the idle timer disable and enable.
This is in objective-C. Just convert it to swift. The API is available in UIApplication.h
-(void) onApplicationDidActivate:(NSNotification*) notification
{
[[UIApplication sharedApplication] setIdleTimerDisabled:NO];
}
-(void) onApplicationWillDeactivate
{
[[UIApplication sharedApplication] setIdleTimerDisabled:NO];
}

How to cancel all local notifications when app is deleted from background not from device

I want to cancel all local notifications when app deleted from background, not from Device.
I know this is
[[UIApplication sharedApplication] cancelAllLocalNotifications];
but my Question is where should i pass it to fire event when application terminates from background.
I called inside applicationWillTerminateFromBackground but it is not working.
You could simply check to see if the app is in the background, and if it is, not fire the notifications.

How can I temporarily disable all local notification scheduled by my iPhone app?

Is there any method to temporarily disable all local notifications created by an iPhone app? I need to re enable them all with respect to a condition. my requirement is if the user turned off the notification button on my app , then no more notifications is shown.If he turned it on then all notifications should be shown. Any idea?
You can get all scheduled notifications and save them in shared preferences for example.
[[UIApplication sharedApplication] scheduledLocalNotifications];
Then cancel all notifications:
- (void)cancelLocalNotification:(UILocalNotification *)notification
If user activate notifications again, you can reschedule them again.
You can use "cancelAllLocalNotifications" method and When User turn it On you can set again All notification for it.

can application find out if push notifications are enabled or disabled?

Can my application find out if push notifications were disabled through Settings on the device? I am not talking about checking with feedback.push.apple.com. I would simply like to know if the switch in the Settings was set to ON or OFF.
You can use
[[UIApplication sharedApplication] enabledRemoteNotificationTypes]
If this returns UIRemoteNotificationTypeNone which is equal to the value 0, then the application accepts no notifications. Hope this helps you.
You can find out which kind of notifications are enabled for your app using [[UIApplication sharedApplication] enabledRemoteNotificationTypes].

sample code for canceling the local notification in iphone

Sample code for canceling the local notification.
I am having a application which sets a local notification and now i want to cancel one of the local notification set the by the application can someone provide the sample code for the same
Cancel all local notifications with this code:
[[UIApplication sharedApplication] cancelAllLocalNotifications];
(you actually just need the middle line.
Cancel one local notification with this line of code:
[[UIApplication sharedApplication] cancelLocalNotification:theNotification];
where theNotification is a UILocalNotification object, so in order to cancel a specific notification you need to hold on to it's UILocalNotification.
You can find more stuff in apple's documentation: http://developer.apple.com/iphone/library/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/IPhoneOSClientImp/IPhoneOSClientImp.html