zoukankan      html  css  js  c++  java
  • 使用UILocalNotification给App添加本地消息通知

    使用过的代码,直接贴上

     1 UILocalNotification *notification = [[UILocalNotification alloc] init];
     2   if (notification!=nil) {
     3     NSDate *now = [NSDate new];
     4     //从现在开始,10秒以后通知
     5     notification.fireDate=[now addTimeInterval:10];
     6     //使用本地时区
     7     notification.timeZone=[NSTimeZone defaultTimeZone];
     8     notification.alertBody=@"顶部提示内容,通知时间到啦";
     9     //通知提示音 使用默认的
    10     notification.soundName= UILocalNotificationDefaultSoundName;
    11     notification.alertAction=NSLocalizedString(@"你锁屏啦,通知时间到啦", nil);
    12     //这个通知到时间时,你的应用程序右上角显示的数字。
    13     notification.applicationIconBadgeNumber = 1;
    14     NSDictionary *dic = [NSDictionary dictionaryWithObject:@"name" forKey:@"key"];
    15     notification.userInfo = dic;
    16     //启动这个通知
    17     [[UIApplication sharedApplication]scheduleLocalNotification:notification];
    18 }

    需要注意的是在iOS8之后需要注册消息推送服务才可以,具体实现就在AppDelegate的

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

    方法中直接调用下面方法即可

    1 if ([UIApplication instancesRespondToSelector:@selector(registerUserNotificationSettings:)]) {
    2       [application registerUserNotificationSettings:[UIUserNotificationSettings 
    3                                    settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound 
    4                                          categories:nil]];
    5 }
  • 相关阅读:
    链接服务器创建
    线性RAM地址非线性映射转换充分应用RAM地址空间TFT液晶驱动
    FPGA跨时钟域同步,亚稳态等
    Go常见的坑
    VSCode+PicGo+Gitee实现高效markdown图床
    友链
    linux 命令行使用codeql
    Linux 多进程服务配置 systemd
    列表中重复元素的个数
    起不出来题目了呜呜
  • 原文地址:https://www.cnblogs.com/jackma86/p/4982169.html
Copyright © 2011-2022 走看看