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.
我在app delegate中实现了 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 /应用程序,它可以正常工作。
我正在使用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];
}
日程表通知
Schedule Notification
- (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屋!