로컬 노티피케이션

IPHONE 2014. 1. 16. 17:32
반응형

1. 로컬 노티피케이션 예약하기.

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    // 백그라운드로 간후 10초후 발생.
    NSDate *alertTime = [[NSDate date] dateByAddingTimeInterval:10];
    UIApplication *app = [UIApplication sharedApplication];
    UILocalNotification *notifyAlarm = [[UILocalNotification alloc] init];
   
    if (notifyAlarm)
    {
        notifyAlarm.fireDate = alertTime;
        notifyAlarm.timeZone = [NSTimeZone defaultTimeZone];
        notifyAlarm.repeatInterval = 0;
        notifyAlarm.soundName = @"bell_tree.mp3";
        notifyAlarm.alertBody = @"Staff meeting in 30 minutes";
        [app scheduleLocalNotification:notifyAlarm];
    }
}


2. 예약된 노티피케이션 취소하기.

UIApplication *app = [UIApplication sharedApplication];

NSArray *oldNotifications = [app scheduledLocalNotifications];


if([oldNotifications count] > 0)

[app cancelAllLocalNotifications];


3. 첫번째 로컬 노티피케이션 즉시 호출하기.

NSArray *notifications = [app scheduledLocalNotifications];

if([notifications count] > 0)

[app presentLocalNotificationNow:notifications[0]];

반응형
Posted by 컴스터
,