zoukankan      html  css  js  c++  java
  • 本地通知的实现

     
    - (IBAction)openLocal:(id)sender {
       
        UILocalNotification *ln = [[UILocalNotification alloc] init];
        ln.alertAction = @"赶集赶紧";
        ln.alertBody = @"我是本地通知";
        ln.fireDate = [NSDate dateWithTimeIntervalSinceNow:5];
        ln.timeZone = [NSTimeZone defaultTimeZone];
        ln.repeatInterval = kCFCalendarUnitSecond;
        ln.applicationIconBadgeNumber = 2;
        ln.userInfo = @{@"key":@"go to study iOS"};
       
        if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)]) {
            UIUserNotificationType type = UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound;
            UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:type categories:nil];
            [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
        } else {
        }
       
        [[UIApplication sharedApplication] scheduleLocalNotification:ln];
       
    }
    - (IBAction)removeLocal:(id)sender {
       
        [[UIApplication sharedApplication] cancelAllLocalNotifications];
        NSLog(@"%@" , [UIApplication sharedApplication].scheduledLocalNotifications);
    }


    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
     
     
    - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
    {
        NSLog(@"我收到本地通知了");
       
        NSString *message = notification.userInfo[@"key"];
       
        NSLog(@"%@" , message);
       
        NSInteger badge = [UIApplication sharedApplication].applicationIconBadgeNumber;
        badge --;
        badge = badge >= 0 ? badge : 0;
        [UIApplication sharedApplication].applicationIconBadgeNumber = badge;
       
    }
     
     
     
     
     
  • 相关阅读:
    DRF分页器
    DRF版本控制
    crrm复习
    python面试题网络编程和数据库
    python基础面试题
    前端格式
    数据库基本命令
    数据库管理系统
    线程协程和进程
    IPC通信
  • 原文地址:https://www.cnblogs.com/benpaobadaniu/p/5095515.html
Copyright © 2011-2022 走看看