2013-04-04 56 views
0

我想开发一个提醒应用程序。它应该提醒人们每周,每月,每季度,半年和每年。当应用程序处于后台状态时获取本地通知?

我正在使用NSDate属性来获取当前日期,然后我将7天添加到当前日期,添加7天后的日期将被存储在plist中。

我选择电话/邮件/留言按钮来提醒人们。在按钮动作中,我将当前日期与保存在plist中的日期进行比较,然后设置本地通知。但是根据火灾日期,本地通知不起作用。当应用程序处于前台时它工作正常,但进入后台则无法正常工作。

+0

您是否在通知中心为应用程序启用了通知? – 2013-04-04 14:51:08

回答

0

你必须安排你的报警。下面是苹果的文件片段:

- (void)scheduleAlarmForDate:(NSDate*)theDate 
{ 
    UIApplication* app = [UIApplication sharedApplication]; 
    NSArray* oldNotifications = [app scheduledLocalNotifications]; 

    // Clear out the old notification before scheduling a new one. 
    if ([oldNotifications count] > 0) 
     [app cancelAllLocalNotifications]; 

    // Create a new notification. 
    UILocalNotification* alarm = [[UILocalNotification alloc] init]; 
    if (alarm) 
    { 
     alarm.fireDate = theDate; 
     alarm.timeZone = [NSTimeZone defaultTimeZone]; 
     alarm.repeatInterval = 0; 
     alarm.soundName = @"alarmsound.caf"; 
     alarm.alertBody = @"Time to wake up!"; 

     [app scheduleLocalNotification:alarm]; 
    } 
} 

你可以找到苹果的文档"App States and Multitasking"了很多有用的信息,特别是在部分"Background Execution and Multitasking"(它正好覆盖您的使用情况)。

+0

这是否解决了您的问题?如果是这样,我会很感激,如果你能标记答案。 – tigloo 2013-04-05 11:57:56

相关问题