Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 01-10-2012, 04:41 PM   #1 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 39
thephatp is on a distinguished road
Question UILocalNotification - How to handle when App is NOT running?

I have implemented UILocalNotifications in two different apps now. One uses Location Services, which means if it gets killed, it (usually) gets restarted (so it's not as big of an issue). However, in another app, I schedule a UILocalNotification based upon time. In this case, I'm having a major problem.

If I schedule a notification, then the app gets killed, pushed out of memory, phone is turned off then on again, I cannot view older notifications "automatically" when opening the app.

Here is the workflow that works (app running in the background):
  1. Launch app; app schedules notification; close app; app is now running in the background
  2. Receive local notification; ignore it at first; pull the drop down menu from the top (status bar); touch the notification to launch the app
  3. Results: The app appropriately displays the information in the notification.

Here is the workflow that does not work (app no longer running in the background):
  1. Launch app; app schedules notification; close app; app is now running in the background
  2. Manually kill app (to simulate my situation)
  3. Still receive local notification; ignore it at first; pull the drop down menu from the top (status bar); touch the notification to launch the app
  4. Results: The app launches, but the didReceiveLocalNotification method is not called. The user things the app doesn't work.
  5. Note: I can't even manually force the information, because if they have received more than one notification, I can't tell which one they touched on to know which one to display.

Is there any way to know which notification they touched on when the app is not running in the background (and thus does not run the didReceiveLocalNotification method)?
thephatp is offline   Reply With Quote
Old 01-10-2012, 05:04 PM   #2 (permalink)
Just helping out.
 
Domele's Avatar
 
Join Date: Feb 2011
Posts: 2,565
Domele is on a distinguished road
Default

UIApplication will call didFinishLaunchingWithOptions on your app delegate. In the options dictionary is a UILocalNotification object if it was launched due to that. You can retrieve it with the following key: UIApplicationLaunchOptionsLocalNotificationKey
__________________
If you are looking for a quality developer, I'm your man. Give me a PM if you are interested.

New app - See screenshots and details at www.globaclock.com.

If you want to thank me, click the link. Every click counts. If you want to do more, buy my app. A link is available on my website. Thanks.
Domele is offline   Reply With Quote
Old 01-10-2012, 05:12 PM   #3 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 39
thephatp is on a distinguished road
Default

Quote:
Originally Posted by Domele View Post
UIApplication will call didFinishLaunchingWithOptions on your app delegate. In the options dictionary is a UILocalNotification object if it was launched due to that. You can retrieve it with the following key: UIApplicationLaunchOptionsLocalNotificationKey
I thought that was the correct way to do it, but it's still not working for some reason. I have the following code in my didFinishLaunchingWithOptions:

Code:
UILocalNotification *notification = 
    [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
[self application:application didReceiveLocalNotification:notification];
Is there something more I need to do? I seem to recall it not even calling the method, but I'll need to check again. Is it possible that I'm doing something incorrectly when scheduling the notification such that it wouldn't show up in this case (i.e. in the above code, "notification" turns out nil)?
thephatp is offline   Reply With Quote
Old 01-10-2012, 11:04 PM   #4 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 39
thephatp is on a distinguished road
Question

Ok, I've done some testing and no luck.

At first, it worked. I almost reported back that somehow it was magically working again. I followed the steps outlined in my previous post, and when I touched one of the items in the notification center, it launched the app and showed the relevant information.

However, I did get it to not work again as well. The difference was that I performed the steps outlined in the original post, except this time, I wait a while (probably 30 minute) before touching one of the items in the notification center. This time, it launched the app, but it did not display the notification.

I don't know how to debug this in XCode, either, since I have to kill the app, which then kills the debugging. So, when I touch one of the notifications, I don't have an attached debugger when the app launches. I've created a UIView in code that contains a text field, and I'm outputting various details to that view and then showing the view. We'll see what happens now and if I can get a better idea as to what is going on when it doesn't work.

Any other ideas are welcome.
thephatp is offline   Reply With Quote
Reply

Bookmarks

Tags
ios, iphone sdk, uilocalnotification

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 383
11 members and 372 guests
7twenty7, Atatator, buggen, guusleijsten, j.b.rajesh@gmail.com, morterbaher, QuantumDoja, sacha1996, Sami Gh, tim0504, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,674
Threads: 94,122
Posts: 402,907
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Atatator
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 05:37 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0