zoukankan      html  css  js  c++  java
  • 本地推送UILocalNotification的一些简单方法

    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 为收到本地通知的回调方法

  • 相关阅读:
    《模糊测试--强制发掘安全漏洞的利器》阅读笔记(一)
    BrickerBot
    这些写的很好的PCA文章
    决策树(挖坑待填)
    线性回归
    关于给定DNA序列,如何找到合理的切割位点使得其退火温度保持相对一致
    生成全排列
    AVL树学习笔记
    二叉搜索树
    堆排序
  • 原文地址:https://www.cnblogs.com/shen5214444887/p/4882999.html
Copyright © 2011-2022 走看看