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

  • 相关阅读:
    系统升级到9.10感觉很不错
    mysql数据库文件坏掉后通过二进值日志恢复
    关于杨宪益传
    Linux下设置屏幕亮度
    XFCE升级到4.10
    在Linux下编译安装php
    Ubuntu unity安装IndicatorMultiload
    解析Visual Studio Unit Test Result文件(trx文件)
    Linux下安装wordpress3.4
    XFCE字体发虚的解决方法
  • 原文地址:https://www.cnblogs.com/shen5214444887/p/4882999.html
Copyright © 2011-2022 走看看