2011-08-19 94 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