2011-08-19 147 views
0

我正在製作一個iphone應用程序,其中有一個鬧鐘實現模塊。在這個警報實施中,我必須設置警報,並且此警報可以是不同時間的一天中的次數,並且可以是多天。我想爲它使用日曆API。如何使用日曆API設置鬧鐘。我怎樣才能實現這個概念。如果有人知道這個概念。請幫幫我。iphone應用程序重複鬧鐘

在此先感謝。

+0

你應該看看[UILocalNotification類](HTTP:/ /developer.apple.com/librar y/ios/#documentation/iPhone/Reference/UILocalNotification_Class/Reference/Reference.html),它可以做一些你想要的,但它有[限制](http://stackoverflow.com/questions/6966365/uilocalnotification-repeat -interval-for-custom-alarm-sun-mon-tue-wed-thu-fr/6966665#6966665) – progrmr

回答

2

林假設你想要某種形式的推送通知?像一個UIAlertView。這被稱爲UILocalNotification。

UILocalNotification *localNotif = [[UILocalNotification alloc]init]; 
[localNotif setFireDate:[NSDate dateWithTimeInterval:10.0f sinceDate:[NSDate new]]]; // the date to fire 
[localNotif setAlertAction:@"Test"]; // title 
[localNotif setAlertBody:@"This is a test"]; // tells you what to put in the description 
[localNotif setRepeatInterval: NSWeekCalendarUnit]; // repeat interval, what you asked for 
[[UIApplication sharedApplication]scheduleLocalNotification:localNotif]; // put it into the application 
[localNotif release]; 

這將激活一個通知在十秒鐘,重複它從您指定的日期每週(我相信所以請評論,如果我錯了老鄉程序員)。

您綁定到這些選項

NSEraCalendarUnit NSYearCalendarUnit NSMonthCalendarUnit NSDayCalendarUnit NSHourCalendarUnit NSMinuteCalendarUnit NSSecondCalendarUnit NSWeekCalendarUnit NSWeekdayCalendarUnit NSWeekdayOrdinalCalendarUnit NSQuarterCalendarUnit