Tag: uilocalnotification

如何设置与iOS 8弃用每周重复的UILocalNotifications?

在iOS 8之前,安排每周重复通知很容易,我们只是将NSWeekCalendarUnit分配给notification.repeatInterval值。 现在在iOS 8中,几乎所有的NSCalendarUnit值都被弃用和取代,主要是为了保持一致性,Apple可以将它们从NSDayCalendarUnit重命名为NSCalendarUnitDay 。 但是,他们将NSWeekCalendarUnit更改为NSCalendarUnitWeekOfMonth和NSCalendarUnitWeekOfYear ,没有明确说明差异是什么,并且UILocalNotification文档仍然使用已弃用的值。 我想要一个UILocalNotification 每7天重复一次 。 我认为NSCalendarUnitWeekOfMonth是正确的值,但是当我使用它时,我没有重复。 testing是耗时的,因为每个testing需要一个星期! 有谁知道哪个新的星期日历单位应该用于每周重复的本地通知,或者是否应该继续使用已弃用的值,尽pipe有警告?

自定义iOS UILocalNotification声音不播放(可能与Xcode更新有关)

我试图得到一个自定义的声音在UILocalNotification工作,我只是没有听起来。 如果我使用UILocalNotificationDefaultSoundName ,我确实得到默认声音,但是当指定自定义声音时,没有声音,只是消息。 据我所知,声音小于30秒,格式正确。 以下是文件信息的屏幕截图: 我已经检查了Xcode的DerivedData目录中的.app目录,而alarm.caf文件位于应用程序的根目录下,我相信这意味着它在包中(对吧?)。 我很确定这是前一阵子,我已经升级了Xcode。 也许这是一个提示? 我也尝试删除/重新安装/重新启动在其他答案中提到的。 正如你所看到的,我首先调用cancelAllLocalNotifications 。 有没有人有任何想法可能是错的? [[UIApplication sharedApplication] cancelAllLocalNotifications]; NSLog(@"installing alarm"); [arguments pop]; // name [arguments pop]; // title alarm.alertBody = [arguments pop]; alarm.fireDate = [[NSDate date] addTimeInterval:[[arguments pop] intValue]/1000]; //alarm.soundName = UILocalNotificationDefaultSoundName; alarm.soundName = @"alarm.caf"; [[UIApplication sharedApplication] scheduleLocalNotification:alarm];

根据时间在后台激活本地通知

所以我有一个应用程序,包括重复间隔本地通知,我想添加一个function,将在睡眠时间暂停通知。 到目前为止,我已经为用户创build了两个dateselect器来表明他们想要停止重复间隔的时间以及什么时候自动重新启动。 我已经添加了一个uiswitch来激活睡眠模式或忽略该function。 现在,我将如何使我的主uipickerview – (他们从那里select那里通知) – 如果它是开启的,听取uiswitch,然后暂停在我的第一个dateselect器的通知,并重新通知在来自第二个dateselect器的时间? 我已经设置了我的datepickers和我的uiswitch,但不知道如何实现它与我的uipickerview ..应该在DidSelectRow的方法? 或者在appdelegate中的方法(如DidEnterBackground)? 请问你是否需要更多的信息或代码来理解这个想法,并帮助我。 谢谢。 加上: 这里是我为datepicker准备的代码,但是我只是想把连接添加到我的select器视图中。 NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init]; dateFormatter.timeZone=[NSTimeZone defaultTimeZone]; dateFormatter.timeStyle=NSDateFormatterShortStyle; dateFormatter.dateStyle=NSDateFormatterShortStyle; NSString *dateTimeString=[dateFormatter stringFromDate:startTime.date]; NSLog(@"Start time is %@",dateTimeString); NSDateFormatter *dateFormatter2 = [[NSDateFormatter alloc]init]; dateFormatter2.timeZone=[NSTimeZone defaultTimeZone]; dateFormatter2.timeStyle=NSDateFormatterShortStyle; dateFormatter2.dateStyle=NSDateFormatterShortStyle; NSString *dateTimeString2=[dateFormatter2 stringFromDate:endTime.date]; NSLog(@"End time is %@",dateTimeString2); 我也有这个代码来比较时间: if ([[NSDate date] isEqualToDate:startTime.date]) { NSLog(@"currentDate is […]

本地通知声音不起作用

我试图做一个闹钟应用程序,但是当我尝试做出本地通知时,我无法播放声音。 我得到这个错误: [user info = (null)} with a sound but haven't received permission from the user to play sounds] 这里是代码: @IBOutlet var setAlaram: UIDatePicker! @IBAction func setAlarmButton(sender: AnyObject) { var dateformater = NSDateFormatter() dateformater.timeZone = NSTimeZone .defaultTimeZone() dateformater.timeStyle = NSDateFormatterStyle.ShortStyle dateformater.dateStyle = NSDateFormatterStyle.ShortStyle var datetimestring = NSString() datetimestring = dateformater.stringFromDate(setAlaram.date) println(datetimestring) [self .localnotification(setAlaram.date)] } func […]

检测下一个将触发的UILocalNotification

有没有办法find下一个本地通知将触发NSDate ? 例如,我已经设置了三个本地通知: 通知#1:设定在昨天下午3:00开始,每天重复间隔。 通知#2:今天下午5:00开始,每天重复。 通知#3:明天下午6:00,每天重复播放。 鉴于目前是下午4:00,下一个将触发的本地通知是通知#2。 我如何检索本地通知并获取date? 我知道我可以在数组中检索这些本地通知,但是如何根据今天的date获取将会触发的下一个通知?

当应用程序在Swift 2.0后台运行时发送本地通知

我试图在用户最小化应用程序时(通过点击iPhone的主页button或locking手机)发送“推送通知样式”警报。 我的应用程序不断分析一个XML文件(每10秒钟),我希望应用程序继续运行,以便在程序中遇到一些条件时向用户发送本地通知,即使用户已经最小化应用程序或locking了它们电话。 我已经从教程中反弹,每个人似乎都“安排”了一个通知,但是这对我来说不起作用,因为我的通知不是基于时间的,而是基于满足条件的。 到目前为止我所做的是: AppDelegate.swift func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { // Override point for customization after application launch. application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil)) return true } MapViewController.swift // Some function func someFunction(delta: Int) { if delta < 100 { // Send alert to user if app is open let […]

播放自定义声音的UILocalNotifications

我在我的应用程序中实现了本地通知,但是我只是想知道是否有一种方法可以播放不属于iPhone App主包的声音。 基本上在我的应用程序中,我希望用户录制在本地通知生成时播放的声音,而不是播放预先录制或默认声音。 据我所知,这是可以实现的,因为我已经看到2-3应用程序在app store,这是做同样的事情,我想做 – (void)alertSelector:(NSString *)AlertTitle WithFiringTime:(NSDate *)date { UILocalNotification *localNotification = [[[UILocalNotification alloc] init] autorelease]; [localNotification setFireDate:date]; [localNotification setTimeZone:[NSTimeZone defaultTimeZone]]; NSDictionary *data = [NSDictionary dictionaryWithObject:date forKey:@"payload"]; [localNotification setUserInfo:data];[localNotification setAlertBody:AlertTitle]; [localNotification setAlertAction:@"View"]; [localNotification setHasAction:YES]; localNotification.soundName=@"voice.aif"; if (!localNotification) return; [[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; }

在本地通知的警报主体中显示图像

我正在使用本地通知,但我想要在警报的消息正文中放置一个图像。 我怎样才能做到这一点?

registerUserNotificationSettings不显示提示iOS 8

我似乎无法得到提示在iOS 8.1或8.2中显示registerUserNotificationSettings 。 这里是我在做didFinishLaunchingWithOptions : if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) { #ifdef __IPHONE_8_0 UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeAlert |UIUserNotificationTypeSound | UIUserNotificationTypeBadge) categories:nil]; NSLog(@"Reg settings %@", settings); [application registerUserNotificationSettings:settings]; #endif } 同样在这里得到正确的电话: – (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings{ NSLog(@"Did register – %@", notificationSettings); } 然而却没有提示。 更令人讨厌的是,当设备被locking时,警报将会显示,但是不会给出通知警报声。 任何想法在工作?

如何从iTunes中设置声音本地通知?

我尝试创build闹钟应用程序,但我不知道如何将歌曲从iTunes设置为本地通知。 现在我使用这个代码来调用iTunes – (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.section == 0) { MPMediaPickerController *picker = [[MPMediaPickerController alloc] initWithMediaTypes: MPMediaTypeMusic]; picker.delegate = self; picker.allowsPickingMultipleItems = NO; picker.prompt = NSLocalizedString (@"Select any song from the list", @"Prompt to user to choose some songs to play"); //[self presentModalViewController: picker animated: YES]; [self.navigationController pushViewController:picker animated:YES]; NSLog(@"gsudifghukdsf"); [picker release]; […]