2012-08-07 101 views

回答

9
  1. 首先您xib,(或者代碼)設定的日期選擇器模式:時間(默認爲日期&時間)

  2. 系統假定firedate是當前日期和時間用戶選擇的時間。這不是問題,因爲您設置了重複間隔,因此它可以工作。我已經測試過它。

    UILocalNotification *localNotif = [[UILocalNotification alloc] init]; 
    [localNotif setFireDate:datePicker.date]; 
    [localNotif setRepeatInterval:NSDayCalendarUnit]; 
    [[UIApplication sharedApplication] scheduleLocalNotification:localNotif]; 
    

PS:這將是使用NSDateComponents類秒設置爲0,以便設置報警,在您需要的分鐘的第一秒響個好主意。您可以檢查:你張貼在如何做到這一點

Local notifications in iOS.

教程。

+0

感謝您的答案,但我設法做不同的方法..它的工作。一個問題..是否有可能彈出自定義通知視圖,而不是默認的,也想添加自定義聲音,在我的項目中添加可能.. +1爲您的支持 – GoCrazy 2012-08-07 18:48:28

+2

您無法顯示自定義通知彈出窗口。您可以添加自定義聲音,但它應該位於應用程序包中。因此,播放應用程序從互聯網上下載的聲音是不可能的。您只能在編譯之前播放系統聲音或您已導入應用程序的聲音。不客氣。如果您認爲它是正確的,請接受答案,以幫助未來的用戶找到解決此問題的方法。 – 2012-08-07 20:08:21

+0

是的。多數民衆贊成在我所尋找的可以發佈一些代碼播放應用程序包中的聲音,編譯前請導入 – GoCrazy 2012-08-07 20:30:46

0

您可能需要更改日期選擇器的樣式,以允許更改除日期以外的時間。

+0

感謝您answer..Is可以張貼任何教程設置報警 – GoCrazy 2012-08-07 16:25:33

+1

原始教程期望你已經有了這種環境的一些經驗,並且有充分的理由:在任何一個關於這個級別或更高級的教程中,都有許多基本的東西可以跳過。我建議你根據基本知識進行研究,並按照自己的方式完成這些任務,否則你將無法完成任何工作,根據自己的喜好進行更改,或者在出現問題時進行修復。 – Jesper 2012-08-07 16:37:40

+0

感謝您的評論..實際上警報得到通知,但我無法得到彈出窗口..會出現什麼問題 – GoCrazy 2012-08-07 16:57:12

1
+ (void)addLocalNotification:(int)year:(int)month:(int)day:(int)hours:(int)minutes:(int)seconds:(NSString*)alertSoundName:(NSString*)alertBody:(NSString*)actionButtonTitle:(NSString*)notificationID 

調用此方法與參數,並使用此

+ (void)addLocalNotification:(int)year:(int)month:(int)day:(int)hours:(int)minutes:(int)seconds:(NSString*)alertSoundName:(NSString*)alertBody:(NSString*)actionButtonTitle:(NSString*)notificationID { 
NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar]; 

//set the notification date/time 
NSDateComponents *dateComps = [[NSDateComponents alloc] init]; 
[dateComps setDay:day]; 

[dateComps setMonth:month]; 

[dateComps setYear:year]; 
[dateComps setHour:hours]; 

[dateComps setMinute:minutes]; 
[dateComps setSecond:seconds]; 

NSDate *notificationDate = [calendar dateFromComponents:dateComps]; 
[dateComps release]; 

UILocalNotification *localNotif = [[UILocalNotification alloc] init]; 
if (localNotif == nil) 
    return; 
localNotif.fireDate = notificationDate; 
localNotif.timeZone = [NSTimeZone defaultTimeZone]; 

// Set notification message 
localNotif.alertBody = alertBody; 
// Title for the action button 
localNotif.alertAction = actionButtonTitle; 

localNotif.soundName = (alertSoundName == nil) ? UILocalNotificationDefaultSoundName : alertSoundName; 

//use custom sound name or default one - look here to find out more: http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/IPhoneOSClientImp/IPhoneOSClientImp.html%23//apple_ref/doc/uid/TP40008194-CH103-SW13 

localNotif.applicationIconBadgeNumber += 1; //increases the icon badge number 

// Custom data - we're using them to identify the notification. comes in handy, in case we want to delete a specific one later 
NSDictionary *infoDict = [NSDictionary dictionaryWithObject:notificationID forKey:notificationID]; 
localNotif.userInfo = infoDict; 

// Schedule the notification 
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif]; 
[localNotif release]; 
} 
0

你可以試試這個

UILocalNotification *todolistLocalNotification=[[UILocalNotification alloc]init]; 
[todolistLocalNotification setFireDate:[lodatepicker date]]; 
[todolistLocalNotification setAlertAction:@"Note list"]; 
[todolistLocalNotification setTimeZone:[NSTimeZone defaultTimeZone]]; 
[todolistLocalNotification setAlertBody:text_todolist]; 
[todolistLocalNotification setHasAction:YES];