• 本地通知 LocalNotification


    本地通知 LocalNotification 

    在Appdelegate中实现以下两个方法

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
        // Override point for customization after application launch.
        //设置桌面红点内的数字
    //    application.applicationIconBadgeNumber = 0;
        
        //请求通知权限
        UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeAlert | UIUserNotificationTypeSound | UIUserNotificationTypeBadge) categories:nil];
        [application registerUserNotificationSettings:settings];
        
        return YES;
    }

    收到本地通知的代理方法

    1.点击本地通知弹框

    2.程序在前台, 收到本地通知

    - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
        NSLog(@"%@", notification);
    }

    添加一个button到ViewController中

    #import "ViewController.h"
    
    @interface ViewController ()
    - (IBAction)localNoti:(id)sender;
    @end
    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad]; 
    }
    
    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    
    - (IBAction)localNoti:(id)sender {
        //创建本地通知
        UILocalNotification *notification = [[UILocalNotification alloc] init];
        //提示框内容
        notification.alertBody = @"起床啦";
        //提示框标题
        notification.alertTitle = @"醒啦";
        //通知声音
        notification.soundName = UILocalNotificationDefaultSoundName;
        //触发时间
        notification.fireDate = [NSDate dateWithTimeIntervalSinceNow:10];
        //icon旁边的数字
        notification.applicationIconBadgeNumber = [UIApplication sharedApplication].applicationIconBadgeNumber + 1;
        //本地通知重复
        notification.repeatInterval = NSCalendarUnitMinute;
        //发送通知
        [[UIApplication sharedApplication] scheduleLocalNotification:notification];
    }
    @end

    cmd + shift + H 退出程序, 本地通知就弹出

     

     

  • 相关阅读:
    [SAP HANA] HANA 安装更新工具HDBLCM
    [SAP BASIS] [TMS] TMS相关的程序和后台作业
    [sap basis] [authorization trace] Disable/enable authorization trace
    IEEE 802.11 标准列表
    802.11 wireless 七
    802.11 wireless 六
    802.11 wireless 五
    802.11 wireless 四
    802.11 wireless 三
    802.11 wireless 二
  • 原文地址:https://www.cnblogs.com/OrangesChen/p/5071403.html
Copyright © 2020-2023  润新知