随笔 - 91,  文章 - 0,  评论 - 4,  阅读 - 13万

1.添加本地推送,需要在app添加推送。可以根据通知的userInfo的不同的键值对来区分不同的通知

复制代码
    UILocalNotification *notification = [[UILocalNotification alloc] init];
    if(notification)
    {
        notification.fireDate = [NSDate dateWithTimeIntervalSinceNow:5.0]; // 通知触发事件的时间
        //    notification.repeatInterval = 2; // 循环次数
        //    notification.repeatCalendar=[NSCalendar currentCalendar];//当前日历,使用前最好设置时区等信息以便能够自动同步时间
        notification.alertBody = @"推送第2次测试";
        notification.alertAction=@"打开应用"; //待机界面的滑动动作提示
        
        notification.applicationIconBadgeNumber=1;//应用程序图标右上角显示的消息数
        //    notification.alertLaunchImage=@"Default";//通过点击通知打开应用时的启动图片,这里使用程序启动图片
        //    notification.soundName=UILocalNotificationDefaultSoundName;//收到通知时播放的声音,默认消息声音
        //    notification.soundName=@"msg.caf";//通知声音(需要真机才能听到声音)
        
        //设置用户信息
        notification.userInfo=@{@"id":@1,@"user":@"This is a test!"};//绑定到通知上的其他附加信息
        
        // 调用通知
        [[UIApplication sharedApplication] scheduleLocalNotification:notification];
    }
复制代码

 

 

2.移除本地通知,在不需要此通知时记得移除

1 [[UIApplication sharedApplication] cancelAllLocalNotifications];

 

2.在AppDelegate中的- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification 为收到本地通知的回调方法

 

posted on   xiao孛  阅读(324)  评论(0编辑  收藏  举报
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示