UILocalNotification的属性和通知操作 - (Obj-C)

UILocalNotification的属性:

 // 基于时间的预定  触发时间
 @property(nullable, nonatomic,copy) NSDate *fireDate; 

 // 时区
 @property(nullable, nonatomic,copy) NSTimeZone *timeZone;  

 // 设置重复间隔 通知的最小时间间隔为1分钟
 @property(nonatomic) NSCalendarUnit repeatInterval; 
     
 // 重复的日历类型
 @property(nullable, nonatomic,copy) NSCalendar *repeatCalendar; 
 
 // 基于位置的预定   进出某个区域时可以触发通知  使用场景:
 @property(nullable, nonatomic,copy) CLRegion *region NS_AVAILABLE_IOS(8_0); //触发区域
 
 // 是否只触发一次区域通知
 @property(nonatomic,assign) BOOL regionTriggersOnce NS_AVAILABLE_IOS(8_0);

 // 提醒  横幅/弹窗中显示的通知内容
 @property(nullable, nonatomic,copy) NSString *alertBody;  
    
 // 是否显示动作按钮
 @property(nonatomic) BOOL hasAction;          
      
 // 动作按钮上的文字
 @property(nullable, nonatomic,copy) NSString *alertAction;   
 
 // 通过通知启动时的启动图片(无法做屏幕适配,基本已经不再使用)
 @property(nullable, nonatomic,copy) NSString *alertLaunchImage; 
  
 // 提醒标题,不会在界面上展示,iWatch中会有界面展示
 @property(nullable, nonatomic,copy) NSString *alertTitle NS_AVAILABLE_IOS(8_2);  
 
 // 声音 提醒音乐的名称  设置时直接使用音乐名称(使用自定义音乐: 拖入bundle中)或者设置UILocalNotificationDefaultSoundName(使用系统默认提示音, 不能在模拟器上测试)
 @property(nullable, nonatomic,copy) NSString *soundName;       
 
 // 角标
 @property(nonatomic) NSInteger applicationIconBadgeNumber;  // 0 means no change. defaults to 0
 
 // 自定义的数据
 @property(nullable, nonatomic,copy) NSDictionary *userInfo;   // throws if contains non-property list types
 
 // 该本地通知的类别的标记
 @property (nullable, nonatomic, copy) NSString *category NS_AVAILABLE_IOS(8_0);


  • 设置区域需要导入头文件,示例代码:
localNotification.region = [[CLCircularRegion alloc] initWithCenter:CLLocationCoordinate2DMake(39.9, 116.4) radius:130000 identifier:@"BJ"];
  • 是否只触发一次区域通知:regionTriggersOnce默认一次,代表进出某个区域时只执行一次(进只会调用一次,出也只会执行一次)
  • UIApplication对推送通知的一些操作:
 // 立即展示通知,配合静默通知使用
 - (void)presentLocalNotificationNow:(UILocalNotification *)notification NS_AVAILABLE_IOS(4_0) __TVOS_PROHIBITED; 
 
 // 预定通知
 - (void)scheduleLocalNotification:(UILocalNotification *)notification NS_AVAILABLE_IOS(4_0) __TVOS_PROHIBITED;  

 // 取消已经注册并且设置重复的通知/还没有触发的通知
 - (void)cancelLocalNotification:(UILocalNotification *)notification 

 // 取消所有的通知
 - (void)cancelAllLocalNotifications NS_AVAILABLE_IOS(4_0) __TVOS_PROHIBITED; 
 
 // 取出所有预定的通知(已经注册并且设置重复的通知/还还没有触发的通知)
 @property(nullable,nonatomic,copy) NSArray *scheduledLocalNotifications NS_AVAILABLE_IOS(4_0) __TVOS_PROHIBITED; // setter added in iOS 4.2 

你可能感兴趣的:(UILocalNotification的属性和通知操作 - (Obj-C))