2013-04-04 57 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

相關問題