• iOS-本地的推送


    //

    //  ViewController.m

    //  05-本地的推送

    //

    //  Created by hongqiangli on 2017/6/12.

    //

     

    #import "ViewController.h"

     

    @interface ViewController ()

     

    @end

     

    @implementation ViewController

     

    - (void)viewDidLoad {

        [super viewDidLoad];

       

        

    }

     

    /*

     补充:

     让模拟器锁屏: command + l

     

     */

    - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{

        //iOS8之后的改版,需要注册类型

        //声音,

        /*

         UIUserNotificationTypeNone    = 0,      // the application may not present any UI upon a notification being received

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

         UIUserNotificationTypeSound   = 1 << 1,声音

         UIUserNotificationTypeAlert   = 1 << 2,主题内容

         */

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

        [[UIApplication sharedApplication]registerUserNotificationSettings:settings];

        

        //1 创建一个本地通知

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

        //设置属性

        //设置推送内容

        local.alertBody = @"女神:在吗?";

        //设置从现在开始多少秒开始发这个推送

        local.fireDate = [NSDate dateWithTimeIntervalSinceNow:5];

        //设置声音(默认的)

        local.soundName = UILocalNotificationDefaultSoundName;

        //

        local.alertAction = @"";

        //文字

        local.applicationIconBadgeNumber = 10;

        //l

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

        //应用级别

        //立马发送通知

        [[UIApplication sharedApplication]presentLocalNotificationNow:local];

        //定制一个通知

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

        //取消

    //    [[UIApplication sharedApplication]cancelAllLocalNotifications];

        //用代理,监听什么时候接收到通知

    }

     

    - (void)didReceiveMemoryWarning {

        [super didReceiveMemoryWarning];

        // Dispose of any resources that can be recreated.

    }

     

     

    @end

     

     

    //----------------

    //

    //  AppDelegate.m

    //  05-本地的推送

    //

    //  Created by hongqiangli on 2017/6/12.

    //

     

    #import "AppDelegate.h"

     

    @interface AppDelegate ()

     

    @end

     

    @implementation AppDelegate

     

    //程序在前台的时候回调用接收到通知

    //程序一直活着就会调用这个方法

    - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification{

        

        NSLog(@"%@",notification);

    }

     

    //程序启动会调用:

    //1 程序启动

    //点击图标启动

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

        UILocalNotification *info = launchOptions[UIApplicationLaunchOptionsLocalNotificationKey];

        if(info){

            UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 300, 300)];

            label.backgroundColor = [UIColor redColor];

            label.numberOfLines = 0;

            //取出携带信息

    //        NSDictionary *userInfo = info[@"userInfo"];

            label.text = [NSString stringWithFormat:@"%@",info.userInfo];

            [self.window.rootViewController.view addSubview:label];

            

            

        }

        

        return YES;

    }

     

     

     

     

  • 相关阅读:
    Pixel XL编译和烧录Android 8.0
    公式编辑器CVE-2018-0798样本分析
    CVE-2021-33739 EOP漏洞分析
    Firefox 设置 Burpsuite 代理抓取本地数据包
    前端ECharts框架绘制各种图形
    c 除法反汇编算法
    IDA sig签名批量脚本
    从零构建自己的远控•客户端设计面向对象(13)
    从零构建自己的远控•AES加解密Demo(12)
    从零构建自己的远控•图像切割算法构思(11)
  • 原文地址:https://www.cnblogs.com/LiLihongqiang/p/6993925.html
Copyright © 2020-2023  润新知