本地推送

本文详细介绍了iOS8之后本地通知的设置方法,包括如何注册不同类型的通知(如图标文字、声音和主题内容),创建并发送本地通知的过程,以及设置通知的具体属性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  

    //iOS8之后 需要注册通知类型  包含哪些(声音,图标文字,文本) 信息

    /*

     UIUserNotificationTypeNone    = 0,

     UIUserNotificationTypeBadge   = 1 << 0, 包含图标文字  0001

     UIUserNotificationTypeSound   = 1 << 1, // 声音      0010

     UIUserNotificationTypeAlert   = 1 << 2, // 主题内容  0100

     */

    //0111

    UIUserNotificationSettings *setting = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert categories:nil];

    

    [[UIApplication sharedApplication]registerUserNotificationSettings:setting];

    

    

}

 

    //1.创建一个本地通知

    UILocalNotification *local= [[UILocalNotification alloc]init];

    /*

     // timer-based scheduling 定制  特定的时间发出通知

     @property(nonatomic,copy) NSDate *fireDate; 触发 时间

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

     

     @property(nonatomic) NSCalendarUnit repeatInterval; 重复间隔     // 0 means don't repeat

     @property(nonatomic,copy) NSCalendar *repeatCalendar; 重复间隔

     

     @property(nonatomic,copy) CLRegion *region NS_AVAILABLE_IOS(8_0);//区域

     

     @property(nonatomic,assign) BOOL regionTriggersOnce NS_AVAILABLE_IOS(8_0); //决定区域的一个bool

     

     // alerts

     @property(nonatomic,copy) NSString *alertBody;  提醒的主题

     @property(nonatomic) BOOL hasAction;                // NO 不显示滑动解锁的按钮 反之 显示

     @property(nonatomic,copy) NSString *alertAction;    //滑动解锁的文字

     @property(nonatomic,copy) NSString *alertLaunchImage;   //点击通知横幅的启动程序的 启动 图片

     @property(nonatomic,copy) NSString *alertTitle   提示的标题文字

     

     // sound 默认: UILocalNotificationDefaultSoundName

     @property(nonatomic,copy) NSString *soundName;

     // badge

     @property(nonatomic) NSInteger applicationIconBadgeNumber;  //图标文字

     // user info

     @property(nonatomic,copy) NSDictionary *userInfo;   // 用户指定的携带参数

     [UIUserNotificationSettings settingsForUserNotificationTypes:userNotificationActionSettings:]

     @property (nonatomic, copy) NSString *category NS_AVAILABLE_IOS(8_0);分类

     */

    //设置属性

    local.alertBody = @"sb:在吗?";

    

    local.fireDate = [NSDate dateWithTimeIntervalSinceNow:5];

    

    local.soundName = UILocalNotificationDefaultSoundName;

    local.applicationIconBadgeNumber = 10;

    

    local.userInfo = @{@"name":@"sb",@"content":@"在吗?"};

    

    //应用级别

    //定制一个通知 用代理  监听什么接收到通知

    [[UIApplication sharedApplication]scheduleLocalNotification:local];

 

    //立即发出通知

    //[[UIApplication sharedApplication]presentLocalNotificationNow:local];

    

    //取消所有的本地通知

    //[[UIApplication sharedApplication]cancelAllLocalNotifications];

    

    NSDictionary *dict = @{@"name info":@"zhangsa"};

    

    NSLog(@"%@",dict[@"name info"]);

 

 

 

转载于:https://www.cnblogs.com/kongchengtingnuan/p/4639456.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值