scheduleLocalNotification不适用于越狱应用程序吗? [英] scheduleLocalNotification doesn't work for jailbreak apps?
问题描述
我有一个调用scheduleLocalNotification
的应用程序,但是当我将其安装到/Applications 而不是/var/mobile/Applications 时,它不起作用:
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);
}
我改用了presentLocalNotification
,以防出现计时问题.
I tried presentLocalNotification
instead in case it was a timing issue.
我在应用程序委托中实现了didReceiveLocalNotification
,以查看是否调用了它,但不是,仅当应用程序处于应有的前景时才调用它.
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.
如果我将应用重新放回/var/mobile/Applications ,则它应能正常工作. 我正在使用Xcode 4.2.1,并在iPhone 4S和iPod Touch 4g上运行iOS 5.1.1
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
推荐答案
注册通知
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
if ([UIApplication instancesRespondToSelector:@selector(registerUserNotificationSettings:)]){
[application registerUserNotificationSettings:[UIUserNotificationSettings
settingsForTypes:UIUserNotificationTypeAlert| UIUserNotificationTypeSound | UIUserNotificationTypeBadge categories:nil]];
}
[launchOptions valueForKey:UIApplicationLaunchOptionsLocalNotificationKey];
}
时间表通知
- (void)applicationDidEnterBackground:(UIApplication *)application
{
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
NSLog(@"startLocalNotification");
UILocalNotification *notification = [[UILocalNotification alloc] init];
notification.fireDate = [NSDate dateWithTimeIntervalSinceNow:2];
notification.alertBody = @"notification Message ";
notification.timeZone = [NSTimeZone defaultTimeZone];
notification.soundName = UILocalNotificationDefaultSoundName;
//notification.applicationIconBadgeNumber = 10;
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
}
这篇关于scheduleLocalNotification不适用于越狱应用程序吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!