有空再來整理整個設定流程,今天同事討論到也有直接本機發送的方式,上網找了一下寫個函式記錄以方便使用。
- (void)pushLocalNotification:(NSDate *)date
{
//直接抓取目前時間後1分鐘
//NSDate *after = [NSDate dateWithTimeIntervalSinceNow:(1 * 60)];
//若有舊訊息則把它刪除
NSArray *oldNotificatoins = [application scheduledLocalNotifications];
if([oldNotificatoins count] > 0)
[application cancelAllLocalNotifications];
//建立一個訊息來發送
UILocalNotification *alarm = [[[UILocalNotification alloc] init] autorelease];
if(alarm)
{
alarm.fireDate = date;
alarm.timeZone = [NSTimeZone defaultTimeZone];
alarm.repeatInterval = 0;
alarm.soundName = @"beep-beep.caf";
alarm.alertBody = @"test local notification message!";
[application scheduleLocalNotification:alarm];
}
}