2011-01-31 42 views
1

我想制作一个应用程序,它可以让你在我的iPhone应用程序中设置一个闹钟,然后即使我的应用程序没有运行,它也会被激活。即使我的应用程序处于非活动状态,我如何向用户显示警报?

我该如何实施?在.M

-(void)startTimer { 

    NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(updateCurrentTime) userInfo:nil repeats:YES]; 

} 

-(void)updateCurrentTime { 

     currentTime ++; 
     if (currentTime == userDefinedTime) { 

      // Time is up 

     } 

} 
+1

Xcode只是一个IDE - 你可能是指iOS和/或CocoaTouch? – 2011-01-31 07:57:01

回答

1

尝试。在潜入之前需要注意以下几点:

  1. 它仅适用于iOS4及更高版本。
  2. 的NSDate是一个痛苦的屁股,这是调度的唯一选择

虽这么说,你就可以开始:

UILocalNotification *notif = [[UILocalNotification alloc] init]; 

notif.alertBody = @"This is a Local Notification"; 
NSDate *date = [NSDate date]; 
notif.fireDate = [date addTimeInterval:600];// fire the notification in ten minutes 
[[UIApplication sharedApplication] scheduleLocalNotification:notif]; 
[notif release]; 

如果您需要更多的帮助,只是发表评论:)

+1

只有当应用程序处于打开状态时才能使用。 – 2011-01-31 06:37:47

+0

我想运行eventhough应用程序不运行 – SRI 2011-01-31 07:06:56

7

你想用UILocalNotification在.H

int *currentTime; 

相关问题