Local Notification

来源:互联网 发布:淘宝店铺红包幸运抽奖 编辑:程序博客网 时间:2024/06/06 17:39


Listing4-3 Scheduling an alarm notification

- (void)scheduleAlarmForDate:(NSDate*)theDate

{

    UIApplication* app = [UIApplication sharedApplication];

    NSArray* oldNotifications = [app scheduledLocalNotifications];

    // Clear out the old notification before scheduling a new one.

   if ([oldNotifications count] > 0)

        [app cancelAllLocalNotifications];

    // Create a new notification.

    UILocalNotification* alarm = [[[UILocalNotification alloc] init] autorelease];

   if (alarm)

    {

        alarm.fireDate = theDate;

        alarm.timeZone = [NSTimeZone defaultTimeZone];

        alarm.repeatInterval =0;

        alarm.soundName =@"alarmsound.caf";

        alarm.alertBody =@"Time to wake up!";

        [app scheduleLocalNotification:alarm];  

    }  

}


0 0
原创粉丝点击