I have an app that calls scheduleLocalNotification
, but it doesn't work when I install it to /Applications instead of /var/mobile/Applications:
- (void) doNotify
{
// this doesn't work when app is in /Applications but does in /var/mobile/Applications
UILocalNotification * theNotification = [[UILocalNotification alloc] init];
theNotification.alertBody = @"Finished processing.";
theNotification.alertAction = @"Ok";
theNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:1];
[[UIApplication sharedApplication] scheduleLocalNotification:theNotification];
NSLog(@"notification scheduled: %@", theNotification);
}
I tried presentLocalNotification
instead in case it was a timing issue.
I implemented didReceiveLocalNotification
in app delegate to see if that was being called instead, but it wasn't, it was only called when app is in foreground like it should.
If I put the app back in /var/mobile/Applications, it works as it should. I'm using Xcode 4.2.1 and running iOS 5.1.1 on an iPhone 4S and iPod Touch 4g
EDIT: App can run in the background because it is a music app
I met the same problem just now. And I already solve this problem through the official document.
In fact, you should regist the notification to get access to use notification:
Register for Notifications
Schedule Notification