本地通知

来源:互联网 发布:nginx缓存配置 编辑:程序博客网 时间:2024/05/02 06:13
UILocalNotification *notification=[[UILocalNotification alloc] init];if (notification != nil) {    // 基本参数设置     NSDate *now=[NSDate new];
    //5秒后通知
    notification.fireDate = [now dateByAddingTimeInterval:5]; 
     notification.repeatInterval = 0;    notification.timeZone = [NSTimeZone defaultTimeZone];
    //应用的红色数字    notification.applicationIconBadgeNumber = 1; 
     NSArray *pathArray = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSSystemDomainMask, YES);       NSString *string = [NSString stringWithFormat:@"%@%@",pathArray[0],@"/Audio/UISounds/New/Calypso.caf"];    //播放音调          SystemSoundID theSoundID;    AudioServicesCreateSystemSoundID((__bridge CFURLRef)[NSURL fileURLWithPath:string], &theSoundID);    AudioServicesPlaySystemSound(theSoundID);

 

// 提示声音

notification.soundName = string;        // 弹出提示框    notification.alertBody = @"通知声音测试";    notification.alertAction = @"打开";            NSDictionary *infoDict = [NSDictionary dictionaryWithObject:@"本地通知测试声音文件" forKey:@"sound"];    notification.userInfo = infoDict;            // 一定间隔后触发通知    [[UIApplication sharedApplication] scheduleLocalNotification:notification]; }

 

// 提示数字清零

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {    //点击提示框的打开    application.applicationIconBadgeNumber = 0;}

- (void)applicationDidBecomeActive:(UIApplication *)application {    //当程序还在后天运行    application.applicationIconBadgeNumber = 0;}