UILocalNotification を使って iPhone に通知を出す
画面上の方にぴょこっと現れるアレ。アプリ開いてると出ないみたい。
UILocalNotification *localNotification = [[UILocalNotification alloc] init]; NSDate *fireDate = [[NSDate alloc] initWithTimeInterval:10*60 sinceDate:[NSDate date]]; // 10分後に通知する localNotification.fireDate = fireDate; localNotification.timeZone = [NSTimeZone localTimeZone]; localNotification.alertAction = @"title of notification"; localNotification.alertBody = @"message of notification"; localNotification.soundName = UILocalNotificationDefaultSoundName; localNotification.applicationIconBadgeNumber = 2; // アイコンのバッヂを2にする[f:id:sasata299:20140305140800p:plain] [[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
ちなみに、通知を受け取ったときにはこのメソッドが呼ばれる。
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification