0
我是iPhone應用程序開發新手。現在我正在開發iPhone的鬧鐘應用程序。在這個應用程序中,我從UIDataPicker中選擇數據。然後我應用於觸發報警按鈕操作的NSLocalNotification。這是第一次工作。然後再次點擊那個按鈕我再次工作,但時間也一樣。這是錯誤的工作。如何設置報警應用的NSTimer?
在這裏,我想我需要我們NSTimer。我不知道如何使用NSTimer,並且它也是工作後臺應用程序還如何設置這個定時器。
以下開發的報警通知代碼。
- (void) saveButtonAction:(id)sender {
[[UIApplication sharedApplication] cancelAllLocalNotifications];
Class cls = NSClassFromString(@"UILocalNotification");
if (cls != nil)
{
Resource *resourceLoader = [[Resource alloc] init];
NSDictionary *prefDic = [resourceLoader getPlistDataAsDictionary:@"preference"];
NSString *musicName;
NSDate *selectedDateTime = [[NSDate alloc]init];
if (prefDic && [prefDic objectForKey:@"alarmtime"]) {
//firstVal_textField.text = [prefDic objectForKey:@"value1"];
NSLog(@"saravanan %@",[prefDic objectForKey:@"alarmtime"]);
selectedDateTime = [prefDic objectForKey:@"alarmtime"];
NSLog(@"saravanan periyasamy %@", selectedDateTime);
musicName = [NSString stringWithFormat:@"%@%@",[prefDic objectForKey:@"alarmmusic"],@".wav" ];
}
UILocalNotification *notif = [[cls alloc] init];
//notif.fireDate = [datePicker date];
notif.fireDate = selectedDateTime;
notif.timeZone = [NSTimeZone defaultTimeZone];
notif.alertBody = @"Alarm";
notif.alertAction = @"Show me";
//notif.repeatInterval = 0;
//notif.soundName = UILocalNotificationDefaultSoundName;
notif.soundName = musicName;
notif.applicationIconBadgeNumber = 1;
NSDictionary *userDict = [NSDictionary dictionaryWithObject:@"saravanan"
forKey:kRemindMeNotificationDataKey];
notif.userInfo = userDict;
[[UIApplication sharedApplication] scheduleLocalNotification:notif];
[notif release];
}
}
}