iOS 本地通知
来源:互联网 发布:中华养生网源码 编辑:程序博客网 时间:2024/06/05 10:56
//联系人:石虎 QQ: 1224614774昵称:嗡嘛呢叭咪哄
/**
注意:本地通知 直接拷贝到AppDelegate.h文件中,和主控制器中即可完成
*/
效果:
=======================================================
#import "AppDelegate.h"
@implementation AppDelegate
// 只有当应用在前台时,该方法才会被调用
- (void)application:(UIApplication *)application
didReceiveLocalNotification:(UILocalNotification*)notification{
//如果应用程序在前台,将应用程序图标上红色徽标中数字设为0
application.applicationIconBadgeNumber =0;
//使用UIAlertView显示本地通知的信息
[[[UIAlertViewalloc] initWithTitle:@"收到通知"
message:notification.alertBody
delegate:nilcancelButtonTitle:@"确定"otherButtonTitles:nil]show];
}
=========================主控制器==============================
XIB 连线图:
#import "ViewController.h"
@interface ViewController ()
{
UIApplication *app;
}
@end
@implementation ViewController
- (void)viewDidLoad
{
[superviewDidLoad];
app = [UIApplicationsharedApplication];
}
- (IBAction)changed:(id)sender
{
UISwitch* sw = (UISwitch*) sender;
if (sw.on)
{
if([UIApplicationinstancesRespondToSelector:@selector(registerUserNotificationSettings:)])
{
[[UIApplicationsharedApplication] registerUserNotificationSettings:[UIUserNotificationSettingssettingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSoundcategories:nil]];
}
//创建一个本地通知
UILocalNotification *notification = [[UILocalNotificationalloc]init];
//设置通知的触发时间
notification.fireDate = [NSDatedateWithTimeIntervalSinceNow:10];
//设置通知的时区
notification.timeZone = [NSTimeZonedefaultTimeZone];
//设置通知的重复发送的事件间隔
notification.repeatInterval =kCFCalendarUnitHour;
//设置通知的声音
notification.soundName =@"gu.mp3";
//通知标题
notification.alertTitle=@"我是标题";
//设置当设备处于锁屏状态时,显示通知的警告框下方的title
notification.alertAction =@"打开";
//设置通知是否可显示Action
notification.hasAction =YES;
//设置通过通知加载应用时显示的图片
notification.alertLaunchImage =@"logo.png";
//设置通知内容
notification.alertBody =@"亲,好几天????,想念你了!";
//设置显示在应用程序上红色徽标中的数字
notification.applicationIconBadgeNumber =10;
//设置userinfo,用于携带额外的附加信息。
NSDictionary *info =@{@"bys":@"key"};
notification.userInfo = info;
//调度通知
[appscheduleLocalNotification:notification]; // ①
}
else
{
//获取所有处于调度中本地通知数组
NSArray *localArray = [appscheduledLocalNotifications];
if (localArray)
{
for (UILocalNotification *notiin localArray)
{
NSDictionary *dict = noti.userInfo;
if (dict)
{
//如果找到要取消的通知
NSString *inKey = [dictobjectForKey:@"key"];
if ([inKeyisEqualToString:@"bys"])
{
//取消调度该通知
[appcancelLocalNotification:noti]; //
}
}
}
}
}
}
- iOS 本地通知 远程通知
- iOS本地通知 远程通知
- iOS本地通知&定时通知
- iOS实现本地通知
- iOS本地通知
- iOS本地通知
- iOS本地通知UILocalNotification
- IOS实现本地通知
- IOS 本地通知 UILocalNotification
- ios本地通知UILocalNotification
- iOS UILocalNotification本地通知
- iOS实现本地通知
- iOS实现本地通知
- IOS实现本地通知
- iOS-本地通知
- IOS 本地通知
- IOS本地推送通知
- iOS本地通知:UILocalNotification
- ubtun安装docker
- 盐水的故事
- 解析TCP三次握手四次挥手
- ACdream 1084 寒假安排 (数学题)
- 前言--你也可以成为量子计算机程序员
- iOS 本地通知
- Leetcode:523. Continuous Subarray Sum
- OC内存优化
- 容器与虚拟机双城记
- 编程scala
- Linux升级内核虽然我按照上面的方法没有成功,原因是镜像地址下载太慢导致的,后续知道怎么解决后在评论中给出方案
- j2se项目如何打成可以运行Jar包
- while(a<b<c)怎么理解?
- ViewPager个性化切换