簡單記錄
1.注冊通知
//判斷是否已經注冊通知
UIApplication *app = [UIApplication sharedApplication];
UIUserNotificationSettings *setting = [app currentUserNotificationSettings];
// 如果setting.types == UIUserNotificationTypeNone 需要注冊通知
if(setting.types == UIUserNotificationTypeNone)//沒有注冊通知
{
UIUserNotificationSettings *newSetting = [UIUserNotificationSettings settingsForTypes:
UIUserNotificationTypeBadge|
UIUserNotificationTypeSound|
UIUserNotificationTypeAlert
categories:nil];
[app registerUserNotificationSettings:newSetting];
}
else//已經注冊了通知
{
創建通知的代碼
}
2.如果注冊了通知,就調用該方法
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
創建通知的代碼
}
創建通知的代碼
UILocalNotification *ln = [[UILocalNotification alloc]init];
if (ln) {
// 設置時區
ln.timeZone = [NSTimeZone defaultTimeZone];
// 通知第一次發出的時間
ln.fireDate = [[NSDate date]dateByAddingTimeInterval:5];
// 設置通知屬性
ln.soundName = @"click.wav"; // 音效文件名
// 通知的具體內容
ln.alertBody = @"重大新聞:小韓哥的博客又更新了,趕快進來看看吧!....";
// 鎖屏界面顯示的小標題,完整標題:(“滑動來”+小標題)
ln.alertAction = @"查看新聞吧";
// 設置app圖標數字
ln.applicationIconBadgeNumber = 10;
// 設置app的額外信息
ln.userInfo = @{
@"icon":@"text.png",
@"title":@"重大新聞",
@"time":@"2016-02-28",
@"body":@"重大新聞:小韓哥的博客又更新了,趕快進來看看吧!"
};
// 設置重啟圖片
ln.alertLaunchImage = @"101339g76j7j9t2zgzdvkj.jpg";
// 設置重復發出通知的時間間隔
//? ? ? ? ln.repeatInterval = NSCalendarUnitMinute;
}
3.調用通知。