本地通知
涉及類 UILocalNotification
// 本地通知發(fā)送時間
@property(nullable, nonatomic,copy) NSDate *fireDate;
// 發(fā)送時間時區(qū)
@property(nullable, nonatomic,copy) NSTimeZone *timeZone;
// / 通知重復(fù)提示的單位,可以是天匣沼、周瞒滴、月
@property(nonatomic) NSCalendarUnit repeatInterval;
// 不明覺厲
@property(nullable, nonatomic,copy) NSCalendar *repeatCalendar
// alerts 通知彈窗相關(guān)屬性
@property(nullable, nonatomic,copy) NSString *alertBody; // 為通知欄的通知甚至一段提醒文字
@property(nonatomic) BOOL hasAction; // 默認(rèn)是yes姨夹,判斷是否展示alert的按鈕
@property(nullable, nonatomic,copy) NSString *alertAction; // used in UIAlert button or 'slide to unlock...' slider in place of unlock
@property(nullable, nonatomic,copy) NSString *alertLaunchImage; // used as the launch image (UILaunchImageFile) when launch button is tapped
@property(nullable, nonatomic,copy) NSString *alertTitle NS_AVAILABLE_IOS(8_2); // defaults to nil. pass a string or localized string key
// sound 通知的聲音
@property(nullable, nonatomic,copy) NSString *soundName; // name of resource in app's bundle to play or UILocalNotificationDefaultSoundName
// badge 通知角標(biāo)夸溶。設(shè)置是幾 角標(biāo)就是幾 不會自己自增
@property(nonatomic) NSInteger applicationIconBadgeNumber; // 0 means no change. defaults to 0
// user info 用戶自定義數(shù)據(jù)吴旋,用于存放通知需要傳遞的數(shù)據(jù)
@property(nullable, nonatomic,copy) NSDictionary *userInfo;
當(dāng)創(chuàng)建好本地通知后损肛,使用整個項(xiàng)目單例 UIApplication 的方法發(fā)送通知
- (void)scheduleLocalNotification:(UILocalNotification *) notification
NS_DEPRECATED_IOS(4_0, 10_0, "Use UserNotifications Framework's -[UNUserNotificationCenter addNotificationRequest:withCompletionHandler:]") __TVOS_PROHIBITED; // copies notification
通知的接收方法 在appdelegate中
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
設(shè)置方法的接受
并且在此方法中設(shè)置整個app的角標(biāo)
角標(biāo)的相關(guān):
app運(yùn)行在后臺時,接受到通知荣瑟,這個通知遵循 結(jié)構(gòu)
{ aps = { alert = "hello, everyone"; badge = 4;sound = '';alert:'' };}
其中badge就是控制角標(biāo)的數(shù)據(jù)治拿,app本身不會根據(jù)收到的通知來控制角標(biāo),只會嚴(yán)格準(zhǔn)許你傳遞的數(shù)據(jù)笆焰。比如劫谅,你只收到一個通知,但是通知的badge設(shè)置為了 50,那么app的icon角標(biāo)就會被設(shè)置為50捏检。如果想修改角標(biāo)荞驴,只能在用戶點(diǎn)擊通知后的方法中設(shè)置UIApplication的角標(biāo)
// 遠(yuǎn)程通知
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
// 本地通知
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
通知欄中的通知點(diǎn)擊后自身就會消失,如果在接受通知方法的內(nèi)部設(shè)置的角標(biāo)為0贯城,那么全部的角標(biāo)都會消失