Iphone 我如何重复我的本地通知声音,直到我点击它的&引用;“视图”;按钮
通知声音为20秒,但我想重复该声音至少60秒。在那之后它会打瞌睡。这是我珍贵的密码:D看一看,请帮助我 代码:-Iphone 我如何重复我的本地通知声音,直到我点击它的&引用;“视图”;按钮,iphone,objective-c,alarm,uilocalnotification,Iphone,Objective C,Alarm,Uilocalnotification,通知声音为20秒,但我想重复该声音至少60秒。在那之后它会打瞌睡。这是我珍贵的密码:D看一看,请帮助我 代码:- @interface SetAlarmViewController : UIViewController <UITableViewDataSource,UITableViewDelegate,UITextFieldDelegate>{ IBOutlet UITableView *tableview; IBOutlet UIDatePicker *date
@interface SetAlarmViewController : UIViewController <UITableViewDataSource,UITableViewDelegate,UITextFieldDelegate>{
IBOutlet UITableView *tableview;
IBOutlet UIDatePicker *datePicker;
IBOutlet UITextField *eventText;
IBOutlet UINavigationBar *titleBar;
IBOutlet UIButton *setAlarmButton;
}
@property (nonatomic, retain) IBOutlet UITableView *tableview;
@property (nonatomic, retain) IBOutlet UIDatePicker *datePicker;
@property (nonatomic, retain) IBOutlet UITextField *eventText;
@property(nonatomic, retain) IBOutlet UINavigationBar *titleBar;
@property(nonatomic, retain) IBOutlet UIButton *setAlarmButton;
@property(nonatomic) UIReturnKeyType returnKeyType;
- (IBAction) scheduleAlarm:(id) sender;
- (void)showReminder:(NSString *)text;
@implementation SetAlarmViewController
@synthesize datePicker,tableview, eventText,titleBar,setAlarmButton,returnKeyType;
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
eventText.returnKeyType = UIReturnKeyDone;
datePicker.minimumDate = [NSDate date];
NSDate *now = [NSDate date];
[datePicker setDate:now animated:YES];
eventText.delegate = self;
}
- (void) viewWillAppear:(BOOL)animated {
[self.tableview reloadData];
}
- (IBAction) scheduleAlarm:(id) sender {
[eventText resignFirstResponder];
NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar];
// Get the current date
NSDate *pickerDate = [self.datePicker date];
// Break the date up into components
NSDateComponents *dateComponents = [calendar components:( NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit )
fromDate:pickerDate];
NSDateComponents *timeComponents = [calendar components:( NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit )
fromDate:pickerDate];
// Set up the fire time
NSDateComponents *dateComps = [[NSDateComponents alloc] init];
[dateComps setDay:[dateComponents day]];
[dateComps setMonth:[dateComponents month]];
[dateComps setYear:[dateComponents year]];
[dateComps setHour:[timeComponents hour]];
// Notification will fire in one minute
[dateComps setMinute:[timeComponents minute]];
[dateComps setSecond:[timeComponents second]];
NSDate *itemDate = [calendar dateFromComponents:dateComps];
[dateComps release];
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
if (localNotif == nil)
return;
localNotif.fireDate = itemDate;
localNotif.timeZone = [NSTimeZone defaultTimeZone];
// Notification details
localNotif.alertBody = [eventText text];
// Set the action button
localNotif.alertAction = @"Show me";
localNotif.repeatInterval = NSDayCalendarUnit;
localNotif.soundName = @"jet.wav";
localNotif.applicationIconBadgeNumber = 1;
// Specify custom data for the notification
NSDictionary *userDict = [NSDictionary dictionaryWithObject:eventText.text
forKey:kRemindMeNotificationDataKey];
localNotif.userInfo = userDict;
// Schedule the notification
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
[localNotif release];
[self.tableview reloadData];
eventText.text = @"";
}
#pragma mark -
#pragma mark Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [[[UIApplication sharedApplication] scheduledLocalNotifications] count];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSArray *notificationArray = [[UIApplication sharedApplication] scheduledLocalNotifications];
UILocalNotification *notif = [notificationArray objectAtIndex:indexPath.row];
if(notif)
{
[[UIApplication sharedApplication] cancelLocalNotification:notif];
}
[self.tableview reloadData];
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell...
NSArray *notificationArray = [[UIApplication sharedApplication] scheduledLocalNotifications];
UILocalNotification *notif = [notificationArray objectAtIndex:indexPath.row];
[cell.textLabel setText:notif.alertBody];
[cell.detailTextLabel setText:[notif.fireDate description]];
return cell;
}
- (void)viewDidUnload {
datePicker = nil;
tableview = nil;
eventText = nil;
[super viewDidUnload];
}
#pragma mark -
#pragma mark === Text Field Delegate ===
#pragma mark -
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
return YES;
}
#pragma mark -
#pragma mark === Public Methods ===
#pragma mark -
- (void)showReminder:(NSString *)text {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Reminder"
message:text delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
[self.tableview reloadData];
[alertView release];
}
- (void)dealloc {
[super dealloc];
// [datePicker release];
// [tableview release];
// [eventText release];
}
@end
@接口设置AlarmViewController:UIViewController{
IBUITableView*表格视图;
IBUIDatePicker*日期选择器;
IBOutlet UITextField*事件文本;
IBUINAVIGATIONBAR*标题栏;
IBUIButton*设置报警按钮;
}
@属性(非原子,保留)IBUITableView*tableview;
@属性(非原子,保留)IBUIDatePicker*datePicker;
@属性(非原子,保留)IBOutlet UITextField*eventText;
@不动产(非原子,保留)IBUINAVIGATIONBAR*标题栏;
@属性(非原子,保留)IBUIButton*setAlarmButton;
@属性(非原子)UIReturnKeyType returnKeyType;
-(iAction)ScheduleArm:(id)发送方;
-(void)showAlerter:(NSString*)文本;
@AlarmViewController的实现
@合成日期选择器、tableview、eventText、标题栏、setAlarmButton、returnKeyType;
//实现viewDidLoad以在加载视图(通常从nib)后执行附加设置。
-(无效)viewDidLoad{
[超级视图下载];
eventText.returnKeyType=UIReturnKeyDone;
datePicker.minimumDate=[NSDate日期];
NSDate*现在=[NSDate日期];
[datePicker setDate:现在已设置动画:是];
eventText.delegate=self;
}
-(无效)视图将显示:(BOOL)动画{
[self.tableview重载数据];
}
-(iAction)计划报警:(id)发送方{
[eventText辞职FirstResponder];
NSCalendar*日历=[NSCalendar自动更新当前日历];
//获取当前日期
NSDate*pickerDate=[self.datePicker-date];
//把日期分成几个部分
NSDateComponents*dateComponents=[日历组件:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit)
起始日期:pickerDate];
NSDateComponents*timeComponents=[日历组件:(NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit)
起始日期:pickerDate];
//设定点火时间
NSDateComponents*dateComps=[[NSDateComponents alloc]init];
[dateComps setDay:[dateComponents day]];
[dateComps setMonth:[dateComponents month]];
[dateComps setYear:[dateComponents year]];
[dateComps设置小时:[timeComponents小时]];
//通知将在一分钟内发出
[dateComps setMinute:[timeComponents minute]];
[dateComps setSecond:[timeComponents second]];
NSDate*itemDate=[calendar dateFromComponents:dateComps];
[dateComps发布];
UILocalNotification*localNotif=[[UILocalNotification alloc]init];
if(localNotif==nil)
返回;
localNotif.fireDate=itemDate;
localNotif.timeZone=[NSTimeZone defaultTimeZone];
//通知详情
localNotif.alertBody=[eventText];
//设置操作按钮
localNotif.alertAction=@“向我展示”;
localNotif.repeatInterval=NSDayCalendarUnit;
localNotif.soundName=@“jet.wav”;
localNotif.applicationBadgeNumber=1;
//指定通知的自定义数据
NSDictionary*userDict=[NSDictionary Dictionary WithObject:eventText.text
forKey:kRemindMeNotificationDataKey];
localNotif.userInfo=userDict;
//安排通知的时间
[[UIApplication sharedApplication]scheduleLocalNotification:localNotif];
[localNotif发布];
[self.tableview重载数据];
eventText.text=@;
}
#布拉格标记-
#pragma标记表视图数据源
-(NSInteger)表格视图中的节数:(UITableView*)表格视图{
返回1;
}
-(NSInteger)表视图:(UITableView*)表视图行数节:(NSInteger)节{
返回[[[UIApplication sharedApplication]ScheduledLocalNotification]计数];
}
-(void)tableView:(UITableView*)tableView未选择RowatineXpath:(NSIndexPath*)indexPath
{
NSArray*notificationArray=[[UIApplication sharedApplication]ScheduledLocalNotification];
UILocalNotification*notif=[notificationArray objectAtIndex:indexPath.row];
如果(不如果)
{
[[UIApplication sharedApplication]取消通知:notif];
}
[self.tableview重载数据];
}
//自定义表格视图单元格的外观。
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{
静态NSString*CellIdentifier=@“Cell”;
UITableViewCell*单元格=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
如果(单元格==nil){
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle重用标识符:CellIdentifier]自动释放];
}
//配置单元格。。。
NSArray*notificationArray=[[UIApplication sharedApplication]ScheduledLocalNotification];
UILocalNotification*notif=[notificationArray objectAtIndex:indexPath.row];
[cell.textlab setText:notif.alertBody];
[cell.detailtextlab setText:[notif.fireDate description]];
返回单元;
}
-(无效)视图卸载{
日期选择器=零;
tableview=nil;
eventText=nil;
[超级视频下载];
}
#布拉格标记-
#pragma标记===文本字段委托===
#布拉格标记-
-(BOOL)textField应返回:(UITextField*)textField{
[textField resignFirstResponder];
返回YES;
}
#布拉格标记-
#pragma标记===公共方法===
#布拉格标记-
-(无效)显示提醒:(NSString*)文本{
UIAlertView*alertView=[[UIAlertView alloc]initWithTitle:@“提醒”
消息:文本代理:self
取消按钮:@“确定”
其他按钮:无];
[警报视图显示];
[self.tableview重载数据];
[警报视图发布];
}
-(无效)Dealo