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