Quantcast
Viewing all articles
Browse latest Browse all 2

how to set NSTimer for alarm application?

I am new in iPhone application development. Now i am developing alarm application for iPhone. In this application i am selected data from UIDataPicker. Then i applied to NSLocalNotification firedate with in alarm button action. It is working first time. Then second time agin click that button i again also working, but time also same. It is wrongly working.

Here i think i need to us NSTimer. I don't know how to use NSTimer, and also it is working background application also how to set this timer.

following developed code for alarm notification.

        - (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];}}}

Viewing all articles
Browse latest Browse all 2

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>