Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 9    Views: 243

Bonzo
Apple Fan
Profile
Posts: 783
Reg: Jan 30, 2012
Basingstoke
13,530
06/20/13 08:01 AM (12 years ago)

TUTORIAL: Please don't leave my app !!! - Local Notifications - iOS

For those that may find this helpful..... When your app is sent to the background.....your customers may never go back to it for all you know.....so why not give them a little reminder?? Like this: http://www.randalldesigns.co.uk/localnotification.png You can set it to appear after a set time after the app has been sent to the background. Heres how..... In your app delegate.m add this code under the "//applicationDidEnterBackground" section NSDate *AlarmTime = [[NSDate date] dateByAddingTimeInterval:5]; // the dateByAddingTimeInterval is the amount of time after the app goes to the background. In this example it is 5 seconds UIApplication *app = [UIApplication sharedApplication]; UILocalNotification *notifyalarm = [[UILocalNotification alloc] init]; if (notifyalarm) { notifyalarm.fireDate = AlarmTime; notifyalarm.timeZone = [NSTimeZone defaultTimeZone]; notifyalarm.repeatInterval = 0; notifyalarm.soundName = @"right.mp3"; //sound file must be added to the project notifyalarm.alertBody = @"Add your message here"; [app scheduleLocalNotification:notifyalarm]; } add this code under the "//applicationWillEnterForeground" section UIApplication *app = [UIApplication sharedApplication]; NSArray *oldNotifications = [app scheduledLocalNotifications]; if ([oldNotifications count] > 0){ [app cancelAllLocalNotifications]; } Hope someone finds it useful! Thanks Steve
 
farcat
buzztouch Evangelist
Profile
Posts: 1008
Reg: Jan 27, 2012
France
13,230
like
06/20/13 08:21 AM (12 years ago)
Thanks STeve, that's a keeper! Farcat
 
Kittsy
buzztouch Evangelist
Profile
Posts: 2251
Reg: Feb 22, 2012
Liverpool
31,360
like
06/20/13 08:22 AM (12 years ago)
Great stuff
 
tb
buzztouch Evangelist
Profile
Posts: 2050
Reg: Nov 03, 2011
Oxford
32,300
like
06/20/13 08:42 AM (12 years ago)
It seems like a good thing to keep users glued to your app, but I would just like to add a little downside to this. I watched a WWDC video (from last Friday), which I think is called "Put magic into your app". In that, the presenter explains how you should use push notifications effectively. He says that remindig users to go into your app is likely to annoy the user. If used too much, the user is likely to delete the app. I have deleted apps due to this reasoning too. He says the app user is likely to press and hold the app icon, and the app icon will start jiggling. When apps start jiggling, they're scared!
 
mysps
Code is Art
Profile
Posts: 2082
Reg: May 14, 2011
Palma
33,320
like
06/20/13 10:20 AM (12 years ago)
Thank you Bonzo this is great! I think you can keep them glued if each time you post a notification its worth opening or provides value to the end users. Of course use with "caution"!
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
06/20/13 02:03 PM (12 years ago)
Suuuuuuuu-weet! Cheers! -- Smug
 
Black White
I hate code!
Profile
Posts: 292
Reg: Feb 22, 2012
hanoi
4,770
like
06/20/13 05:15 PM (12 years ago)
Woa, very nice thank for share !
 
Arubaman
Aspiring developer
Profile
Posts: 636
Reg: Oct 20, 2011
Akron
16,910
like
06/21/13 08:55 AM (12 years ago)
Seen this on Geeky lemon, wondered if it would integrate.
 
Bonzo
Apple Fan
Profile
Posts: 783
Reg: Jan 30, 2012
Basingstoke
13,530
like
06/21/13 09:17 AM (12 years ago)
That's where I got it from. Works a treat!
 
TooT
I hate code!
Profile
Posts: 87
Reg: May 12, 2013
Singapore
870
like
12/07/14 04:51 AM (11 years ago)
Thats great ! Thanks for your help !
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.