Tag: uilocalnotification

iOS本地通知 – 在后台回拨

上下文:我的iOS应用程序使用本地通知,我安排本地通知,然后通过didRecieveLocalNotifications回拨通知。 这个工作正常,当应用程序在前台但是当应用程序在后台我得到的iOS通知, 但没有回电 。 我的问题:当应用程序处于后台时,如何从iOS获得callback。 这是回拨代码 – – (void)application:(UIApplication *)application didReceiveLocalNotification: (UILocalNotification *)notification { //call your method that you want to do something in your app NSLog (@"Received Notification"); [UIApplication sharedApplication].applicationIconBadgeNumber = 1; [myRootController HandleLocalNotifications:notification]; }

保证在正确的时间ios交付的UILocalNotification

我的本地通知存在问题: 如果设备处于closures状态或更改电话date ,通知将保持在队列中,并随着下一个通知一起开始。 为什么? 由于需要非常关注通知date。如何保证正确的通知发送? 我们应该在哪里放置删除过期通知的代码?

如何在祷告时间不同的时间设置本地通知重复间隔?

在本地通知中有repeatInterval属性,我们可以将单位重复间隔分为时,分,日,周,年等 我希望祷告时间和每一天都有同样的过程。 所以每个祷告时间都会有本地通知。 祈祷时间每天都是不同的时代

获取一个UILocalNotification每周开火

我已经设置了一个本地通知来触发。 我想知道如何让它在每周的同一时间,例如周一上午9点​​重复。 这是我的代码到目前为止: @IBAction func scheduleLocal(sender: UIButton) { guard let settings = UIApplication.sharedApplication().currentUserNotificationSettings() else { return } if settings.types == .None { let ac = UIAlertController(title: "Cant Schedule", message: "No Permission", preferredStyle: .Alert) ac.addAction(UIAlertAction(title: "OK", style: .Default, handler: nil)) presentViewController(ac, animated: true, completion: nil) return } let notification = UILocalNotification() notification.fireDate = NSDate() notification.alertBody = […]

为什么在我打开localNotification中的string数组时返回nil?

notificationTime = ["2016-05-26 16:27:17 +0000","2016-05-24 13:29:37 +0000"] var num = 0 func locaNotification(num:Int) { let dateFormatter = NSDateFormatter() dateFormatter.locale = NSLocale.currentLocale() dateFormatter.dateStyle = NSDateFormatterStyle.FullStyle var dateAsString = notificationTime[num] dateFormatter.dateFormat = "yyyy-MM-dd HH:mm" var newDate = dateFormatter.dateFromString(dateAsString)! 它在这里展开时返回nil,newDate =上一行代码后的零! var arr = UIApplication.sharedApplication().scheduledLocalNotifications for localN:UILocalNotification in arr! { var notificationFireDate:NSDate = localN.fireDate! if notificationFireDate == newDate […]

应用程序终止后,使用NSNotification在UIViewController中处理UILocalNotification

我正在使用UILocalNotification ,我想通知我的控制器之一,即使应用程序已被终止,通知已收到。 在我的appDelegate中,我实现了这个function: -(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification { if ([application applicationState] == UIApplicationStateInactive) { [[NSNotificationCenter defaultCenter] postNotificationName:@"localNotificationReceived" object:notification.userInfo]; } } 在我的UIViewController我在viewDidLoad方法上实现了观察者 – (void)viewDidLoad { [super viewDidLoad]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didlocalNotificationReceived:) name:@"localNotificationReceived" object:nil]; } 它运行在后台运行的应用程序完美。 由于viewDidLoad方法已经被调用,Observer正在等待.. 问题是当我杀了应用程序。 然后,我的控制器的观察者不见了, didlocalNotificationReceived方法从不被调用。 我认为这是因为当我收到localNotification并再次运行应用程序。 didReceiveLocalNotification:方法在我的UIViewController的viewDidLoad之前调用。 然后在PostNotificationName之后创build观察者,然后观察者不收到任何东西。 我想知道是否有一些最佳实践或模式来处理这类问题。 我知道didFinishLaunchingWithOptions方法是在didlocalNotificationReceived之前didlocalNotificationReceived因此可能有些事情要做。 更新: 我也发现,当应用程序被终止。 一旦你点击通知,它打开应用程序,调用函数didFinishLaunchingWithOptions但从来没有调用didReceiveLocalNotification 。 所以我认为我会处理两种情况。

试图创build一个本地通知,但得到错误“不能调用非函数typesuilocalnotification值”在swift 2

import UIKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() var dateComp:NSDateComponents = NSDateComponents() dateComp.year = 2015; dateComp.month = 11; dateComp.day = 20; dateComp.hour = 0; dateComp.minute = 10; dateComp.timeZone = NSTimeZone.systemTimeZone() var calendar:NSCalendar = NSCalendar(calendarIdentifier: NSGregorianCalendar)! var date:NSDate = calendar.dateFromComponents(dateComp)! //var date:NSDate = calendar.dateFromComponents(dateComp) var notification:UILocalNotification = UILocalNotification() notification.category = "FIRST_CATEGORY" notification.alertBody = […]

本地横幅通知终止应用程序

我想在用户退出应用程序时显示标题通知。 点击该横幅我想要打开我的应用程序。 func showBanner() { UIApplication.shared.cancelAllLocalNotifications() let notif = UILocalNotification.init() notif.alertBody = "Your Message Here…" localNotif.soundName = UILocalNotificationDefaultSoundName UIApplication.shared.presentLocalNotificationNow(notif) } 如果我把这个代码在applicationDidEnterBackground它工作正常; 但是,当我把它放在applicationWillTerminate ,它不会。 任何解决方法? 编辑: 添加fireDate ,如下所示: var dc = DateComponents() dc.second = 2 // 2 seconds from current date time notif.fireDate = Calendar.current.date(byAdding: dc, to: Date()) 还是行不通。 任何想法?

每周本地通知

我有一个小问题,我怎么可以做每周本地通知。 我的应用程序是一个时间表,当用户在8点有一个class级,然后当用户打开开关时,有一个切换,这意味着他有一个通知在7:45每周留在他的同一时间。 我希望你能理解我。

UILocalNotification重复间隔不工作

我试图让UILocalNotification每秒重复一次,而且确实是重复的,但由于某种原因,并不是每一秒钟,它似乎都是每分钟重复一次,我还是新的UILocalNotifications,所以我可能做错了什么。 这里有一个notifs的图片: http ://imgur.com/Hzt38py 这是我用来创buildUILocalNotification的函数 func notificationCreater (date:NSDate, uuid:String) { let notification = UILocalNotification () notification.alertBody = "Test Run 9" notification.fireDate = date notification.repeatInterval = NSCalendarUnit.CalendarUnitSecond //notification.userInfo = ["UUID": uuid] // notification.soundName = "alarmSound.m4a" // notification.alertAction = "he" // notification.soundName = "alarmSound.m4a" // notification.alertTitle = "Test Title" println("schld") UIApplication.sharedApplication().scheduleLocalNotification(notification) } 这是View Controller的其余部分 class AddTaskViewController: UIViewController,AVAudioPlayerDelegate{ […]