-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.mまたはでは正常に機能します(-(void) applicationDidEnterBackground:­(UIApplication *)application)が、 では機能しませんViewController。ユーザーがボタンをクリックしたときにこれとまったく同じことが起こるようにしたかったので、ViewControllernotにこのコードが必要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 のインスタンスを取得して、これらのメソッドを呼び出すことができるということです。

次に呼び出します - [appDelegate presentLocalNotificationNow:LOcalnotificon]

于 2013-04-29T05:09:31.460 に答える