以下のコードを使用して通知をスケジュールします。
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
if (localNotif == nil)
return FALSE;
localNotif.fireDate = fireDate;
localNotif.repeatInterval = repeatInterval;
localNotif.timeZone = [NSTimeZone defaultTimeZone];
localNotif.alertBody = @"Meeting";
// Set the action button
localNotif.hasAction = YES;
localNotif.alertAction = NSLocalizedString(@"Show",nil);
localNotif.soundName = UILocalNotificationDefaultSoundName;
localNotif.applicationIconBadgeNumber = 1;
/* SCHEDULE NOTIFICATION */
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
これも appdelegate.h でプロパティ localNotification を宣言し、通知を傍受してから、以下のようにします。
UILocalNotification *localNotification;
@property (nonatomic, retain) UILocalNotification *localNotification;
@synthesize localNotification;
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
self.localNotification = notification;
NSLog(@"NOTIFICATION - DID RECEIVE");
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
if (self.localNotification)
{
// Do whatever you want
}
}