-1

我有这个代码:

UILocalNotification *notification = [[UILocalNotification alloc] init];
[notification setAlertBody:@"This is a message"];
[notification setFireDate:[NSDate dateWithTimeIntervalSinceNow:10]];
[notification setTimeZone:[NSTimeZone defaultTimeZone]];
[application setSchedualLocalNotifications:[NSArray arrayWithObject:notification]];

这在AppDelegate.mor(-(void) applicationDidEnterBackground:­(UIApplication *)application)中工作正常,但在ViewController. 我希望在用户单击按钮时发生这种确切的事情,所以我不需要此ViewController代码AppDelegate。我怎样才能更改此代码,以便它可以在ViewController!非常感谢!

4

2 回答 2

1

嗯,获取当前应用对象

[[UIApplication sharedApplication] setSchedualLocalNotifications:[NSArray arrayWithObject:notification]];
于 2013-04-29T04:42:29.050 回答
0

以下链接显示我们只能在 AppDelegate 文件中创建和安排本地通知:

http://developer.apple.com/library/ios/#documentation/iPhone/Reference/UILocalNotification_Class/Reference/Reference.html

在以下方法中: UIApplication scheduleLocalNotification: 或 presentLocalNotificationNow:

但这里要注意的是,您始终可以获取 AppDelegate 的实例并调用这些方法: MyApplicationDelegate *appDelegate = (MyApplicationDelegate *)[[UIApplication sharedApplication] delegate];

然后调用 - [appDelegate presentLocalNotificationNow:LOcalnotificaton]

于 2013-04-29T05:09:31.460 回答