本地通知角标相关

2016-11-21  本文已影响156人  erbai

本地通知

涉及类 UILocalNotification

 // 本地通知发送时间
@property(nullable, nonatomic,copy) NSDate *fireDate;
// 发送时间时区
@property(nullable, nonatomic,copy) NSTimeZone *timeZone;
// / 通知重复提示的单位,可以是天、周、月 
@property(nonatomic) NSCalendarUnit repeatInterval; 
// 不明觉厉
@property(nullable, nonatomic,copy) NSCalendar *repeatCalendar
// alerts 通知弹窗相关属性
@property(nullable, nonatomic,copy) NSString *alertBody;      // 为通知栏的通知甚至一段提醒文字
@property(nonatomic) BOOL hasAction;                // 默认是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 通知角标。设置是几 角标就是几 不会自己自增
@property(nonatomic) NSInteger applicationIconBadgeNumber;  // 0 means no change. defaults to 0

// user info 用户自定义数据,用于存放通知需要传递的数据
@property(nullable, nonatomic,copy) NSDictionary *userInfo;   

当创建好本地通知后,使用整个项目单例 UIApplication 的方法发送通知
- (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 设置方法的接受
并且在此方法中设置整个app的角标

角标的相关:
app运行在后台时,接受到通知,这个通知遵循 结构
{ aps = { alert = "hello, everyone"; badge = 4;sound = '';alert:'' };}
其中badge就是控制角标的数据,app本身不会根据收到的通知来控制角标,只会严格准许你传递的数据。比如,你只收到一个通知,但是通知的badge设置为了 50,那么app的icon角标就会被设置为50。如果想修改角标,只能在用户点击通知后的方法中设置UIApplication的角标

// 远程通知
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo 
// 本地通知
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification

通知栏中的通知点击后自身就会消失,如果在接受通知方法的内部设置的角标为0,那么全部的角标都会消失

上一篇下一篇

猜你喜欢

热点阅读