我是 iPhone 应用程序开发的新手。我正在做警报应用程序。在这个应用程序中,我使用本地通知。我在完成按钮操作中调用通知方法。现在我点击完成按钮意味着通知正确触发。然后再次点击意味着也被解雇了,一次又一次的按下意味着工作错误,但我使用的是通知触发日期时间。此时完成意味着用户再次单击完成按钮意味着再次触发通知。
我想在那个特定的时间开火。你能帮我么。
我在这里使用这个源代码。
-(IBAction)doneButton
{
[self scheduledNotification];
}
-(void)scheduledNotification
{
Resource *resourceLoader = [[Resource alloc] init];
NSDictionary *prefDic = [resourceLoader getPlistDataAsDictionary:@"preference"];
if ([@"ON" isEqualToString:[prefDic objectForKey:@"alarm"]])
{
[[UIApplication sharedApplication] cancelAllLocalNotifications];
Class cls = NSClassFromString(@"UILocalNotification");
if (cls != nil)
{
NSString *musicName;
//NSDate *selectedDateTime = [[NSDate alloc]init];
selectedDateTime = [prefDic objectForKey:@"alarmtime"];
NSLog(@"saravanan periyasamy %@", selectedDateTime);
musicName = [NSString stringWithFormat:@"%@%@",[prefDic objectForKey:@"alarmmusic"],@".wav" ];
NSLog(@"musicname %@", musicName);
NSLog(@"saravanan periyasamy123 %@", selectedDateTime);
UILocalNotification *notif = [[cls alloc] init];
notif.fireDate = selectedDateTime; /* time for fireDate*/
NSLog(@"selectedtime %@",selectedDateTime);
notif.timeZone = [NSTimeZone systemTimeZone];
notif.alertBody = @"Alarm";
notif.alertAction = @"Show me";
notif.repeatInterval = 0;
notif.soundName = musicName;
notif.applicationIconBadgeNumber = 1;
NSDictionary *userDict = [NSDictionary dictionaryWithObject:@"saravanan"
forKey:kRemindMeNotificationDataKey];
notif.userInfo = userDict;
[[UIApplication sharedApplication] scheduleLocalNotification:notif];
[notif release];
}
}
}
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
Class cls = NSClassFromString(@"UILocalNotification");
if (cls) {
UILocalNotification *notification = [launchOptions objectForKey:
UIApplicationLaunchOptionsLocalNotificationKey];
if (notification) {
NSString *reminderText = [notification.userInfo
objectForKey:kRemindMeNotificationDataKey];
//[self.viewController showReminder:reminderText];
[self.settingViewController showReminder1:reminderText];
}
}
application.applicationIconBadgeNumber = 0;
return YES;
}
- (void)applicationWillEnterForeground:(UIApplication *)application {
application.applicationIconBadgeNumber = 0;
}
- (void)application:(UIApplication *)application
didReceiveLocalNotification:(UILocalNotification *)notification {
application.applicationIconBadgeNumber = 0;
NSString *reminderText = [notification.userInfo
objectForKey:kRemindMeNotificationDataKey];
//[self.viewController showReminder:reminderText];
[self.settingViewController showReminder1:reminderText];
}