BackgroundingBursting Your Bubble on iOS
SorryDoing what you want in the backgroundis almost impossible
photo by protographer23
Get Your Notepads      ReadySuspending vs. ResumingLocal NotificationsDoing Stuff in the Background
Exiting vs. ResumeSince iOS 4, you can keep your app“open” on exitBut it’s really just a “freeze” andresume - nothing happ...
Resume MeSet the ‘UIApplicationExitsOnSuspend’to ‘NO’ in your Info.plist
App Delegate Events App Initial Load -> Exit:   applicationDidBecomeActive   applicationWillResignActive   applicationDidE...
Sounds PromisingapplicationDidEnterBackground soundspromising, but you can’t do anythinginside it that is long-running.  D...
Terminate on ExitSet ‘UIApplicationExitsOnSuspend’ to‘YES’ in your Info.plist
App Delegate Events App Launch -> Exit:   applicationDidBecomeActive   applicationDidEnterBackground   applicationWillTerm...
Kill MeIf the user does the jiggle and Red-Xes the app, no events are fired
DEMO!
Local NotificationsYou can schedule local notificationsto prompt the user at a future timeeven if your app isn’t runningUs...
DEMO!
Ok, NextSo you “can” do things in thebackground, but it’s limited to 3things:  Get GPS updates  Play Justin Bieber  Do the...
Set Your PlistDo do one of those 3 lovely things inthe background, set the‘UIBackgroundModes’ in yourInfo.plistValues are:...
LocationGet super duper real-time updates ormajor changes onlyUse CLLocationManager to do the magic
DEMO!
Playing AudioIt’s easy: start playing your tunesusing AV* framework.If something else starts playingmusic, you lose
DEMO!
VOIPSorry, no demo.But supposedly you can open a socketand keep it open.
Fighting the ManPeople have tried tricking the systemby playing an “empty” sound file.This works until some other app play...
ConclusionRead more at:  http://developer.apple.com/library/ios/  #documentation/iphone/conceptual/  iphoneosprogramminggu...
Thanks!Find me on Twitter @dnstevensonBuy one of my apps at http://www.stevensonsoftware.comLeave me a 5-star review and I...
Upcoming SlideShare
Loading in …5
×

iOS Backgrounding - SLC Cocoaheads

1,149 views
1,035 views

Published on

Presentation for the September 2011 Salt Lake City Cocoaheads group. Covers the basics of how iOS apps terminate, resume, and what you can do in the background.

Published in: Technology, News & Politics
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,149
On SlideShare
0
From Embeds
0
Number of Embeds
116
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • iOS Backgrounding - SLC Cocoaheads

    1. 1. BackgroundingBursting Your Bubble on iOS
    2. 2. SorryDoing what you want in the backgroundis almost impossible
    3. 3. photo by protographer23
    4. 4. Get Your Notepads ReadySuspending vs. ResumingLocal NotificationsDoing Stuff in the Background
    5. 5. Exiting vs. ResumeSince iOS 4, you can keep your app“open” on exitBut it’s really just a “freeze” andresume - nothing happens while it’sin the background
    6. 6. Resume MeSet the ‘UIApplicationExitsOnSuspend’to ‘NO’ in your Info.plist
    7. 7. App Delegate Events App Initial Load -> Exit: applicationDidBecomeActive applicationWillResignActive applicationDidEnterBackground On Relaunch: applicationWillEnterForeground
    8. 8. Sounds PromisingapplicationDidEnterBackground soundspromising, but you can’t do anythinginside it that is long-running. Docs say you have 5 seconds You can’t get back to the UI
    9. 9. Terminate on ExitSet ‘UIApplicationExitsOnSuspend’ to‘YES’ in your Info.plist
    10. 10. App Delegate Events App Launch -> Exit: applicationDidBecomeActive applicationDidEnterBackground applicationWillTerminate
    11. 11. Kill MeIf the user does the jiggle and Red-Xes the app, no events are fired
    12. 12. DEMO!
    13. 13. Local NotificationsYou can schedule local notificationsto prompt the user at a future timeeven if your app isn’t runningUseful - but remember the user isn’trequired to open the app, and yournotification may never appear
    14. 14. DEMO!
    15. 15. Ok, NextSo you “can” do things in thebackground, but it’s limited to 3things: Get GPS updates Play Justin Bieber Do the VOIP
    16. 16. Set Your PlistDo do one of those 3 lovely things inthe background, set the‘UIBackgroundModes’ in yourInfo.plistValues are: location, audio, voip
    17. 17. LocationGet super duper real-time updates ormajor changes onlyUse CLLocationManager to do the magic
    18. 18. DEMO!
    19. 19. Playing AudioIt’s easy: start playing your tunesusing AV* framework.If something else starts playingmusic, you lose
    20. 20. DEMO!
    21. 21. VOIPSorry, no demo.But supposedly you can open a socketand keep it open.
    22. 22. Fighting the ManPeople have tried tricking the systemby playing an “empty” sound file.This works until some other app playssound.GPS Updates take up battery power, soyour users may hate you.
    23. 23. ConclusionRead more at: http://developer.apple.com/library/ios/ #documentation/iphone/conceptual/ iphoneosprogrammingguide/ BackgroundExecution/ BackgroundExecution.htmlSample Code: https://github.com/dnstevenson/BackgroundTestGood Luck!
    24. 24. Thanks!Find me on Twitter @dnstevensonBuy one of my apps at http://www.stevensonsoftware.comLeave me a 5-star review and I’ll beyour best friend

    ×