标签: uilocalnotification

了解UILocalNotification timeZone

来自文档:

fireDate中指定的日期将根据此属性的值进行解释.如果指定nil(默认值),则开火日期将被解释为绝对GMT时间,适用于倒数计时器等情况.如果为此属性分配有效的NSTimeZone对象,则开火日期将被解释为当时区发生变化时自动调整的挂钟时间; 适用于这种情况的一个例子是闹钟.

假设我在明天GMT(绝对时间)中午安排本地通知.我计划在西雅图下午1点(太平洋时间,格林威治标准时间-8),然后立即前往芝加哥,到达晚上11点(中部时间,格林威治标准时间-6).我的设备从太平洋时间调整到中部时间.请帮助我了解在以下三种情况下我的通知何时发生:

  1. UILocalNotification timeZone设置为nil.
  2. UILocalNotification timeZone设置为GMT.
  3. UILocalNotification timeZone设置为太平洋时间.

datetime ios uilocalnotification

21
推荐指数
2
解决办法
5693
查看次数

IOS版本中的本地和推送通知兼容

我开发local NotificationsiOS 10.它工作得很好.但现在我应该如何编码local notifications,push notification如果用户正在使用iOS 9及以上版本.有人可以帮忙吗?

下面是代码 iOS 10

import UIKit
import UserNotifications

@available(iOS 10.0, *)
class ViewController: UIViewController,UNUserNotificationCenterDelegate {
    override func viewDidLoad() {
       super.viewDidLoad()

       if #available(iOS 10.0, *) {
        //Seeking permission of the user to display app notifications
        UNUserNotificationCenter.current().requestAuthorization(options: [.alert,.sound,.badge], completionHandler: {didAllow,Error in })
        UNUserNotificationCenter.current().delegate = self

       }
   }

   //To display notifications when app is running  inforeground
   func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> …
Run Code Online (Sandbox Code Playgroud)

apple-push-notifications ios uilocalnotification swift

19
推荐指数
2
解决办法
3万
查看次数

从App Store更新后,应用程序失去了对本地通知的控制权

我在App Store有一个带有本地通知的应用程序.

在我的应用程序的最后4个版本更新中,有些客户遇到了一些奇怪的事情 - 该应用程序失去了对之前通知的控制权,他们不断在更新之前安排所有通知,即使他们应该被取消[[UIApplication sharedApplication] cancelAllLocalNotifications]!

在与这些客户沟通时,我告诉他们关闭提醒,执行某些操作cancelAllLocalNotifications,但他们声称不断收到提醒.

此外,重新安装应用程序并没有摆脱旧的通知!就好像iOS认为这是一个不同的应用程序.

它不会发生在我的大多数客户身上,只有极少数客户 - 但是,每次更新都会发生!

怎么会这样?

更新

3年后,它仍在发生.

每个更新一些客户不断收到本地通知,但应用程序无法看到这些,也无法控制它们.

任何人都可以解决这个问题或证明它是iOS的错误吗?

ios uilocalnotification

18
推荐指数
1
解决办法
1388
查看次数

当应用从iOS中的本地通知进入前台时触发特定操作?(使用swift)

我正在使用新语言Swift构建iOS应用程序.现在它是一个HTML5应用程序,使用UIWebView显示HTML内容.该应用程序具有本地通知,我想要做的是当应用程序通过单击(触摸)本地通知进入前台时触发UIWebView中的特定javascript方法.

我看过这个问题,但它似乎没有解决我的问题.我也遇到过这个问题,它告诉我使用UIApplicationState,这很好,因为这可以帮助我知道应用程序从通知进入前台.但是当应用程序恢复时,我如何在应用程序恢复时显示的视图的viewController中调用方法?

我想做的是获取我的ViewController的一个实例并将其中的属性设置为true.事情如下

class FirstViewController: UIViewController,UIWebViewDelegate { 
  var execute:Bool = false;
  @IBOutlet var tasksView: UIWebView!
}
Run Code Online (Sandbox Code Playgroud)

在我的AppDelegate中我有方法

func applicationWillEnterForeground(application: UIApplication!) {
    let viewController = self.window!.rootViewController;
    let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)

    var setViewController = mainStoryboard.instantiateViewControllerWithIdentifier("FirstView") as FirstViewController
    setViewController.execute = true;


}
Run Code Online (Sandbox Code Playgroud)

所以我想做的是当应用程序再次进入前台时,我想查看执行变量并按如下方式运行方法,

if execute{
 tasksView.stringByEvaluatingJavaScriptFromString("document.getElementById('sample').click()");
}
Run Code Online (Sandbox Code Playgroud)

我应该在哪里放置逻辑代码来从webview中触发javascript?它会在viewDidLoad方法,还是其中一个webView委托方法?我试图将该代码放在viewDidLoad方法中,但布尔执行的值设置为其初始值,而不是当应用程序进入前台时在委托中设置的值.

uiwebview ios uilocalnotification swift

18
推荐指数
2
解决办法
2万
查看次数

UILocalNotification根本不起作用

我有一些非常恼人的问题UILocalNotification.

在完成我几乎完成的应用程序时,我注意到无论我尝试了什么,我都无法获得本地通知.

所以我没有浪费时间,而是决定回到基础,看看我是否可以让他们工作.

我创建了一个新的基于XCode视图的应用程序,并替换-viewDidLoad为:

- (void)viewDidLoad
{
    UILocalNotification * theNotification = [[UILocalNotification alloc] init];
    theNotification.alertBody = @"Alert text";
    theNotification.alertAction = @"Ok";
    theNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:10];

    [[UIApplication sharedApplication] scheduleLocalNotification:theNotification];
}
Run Code Online (Sandbox Code Playgroud)

但是,这也没有做任何事情.
我希望在启动应用程序10秒后看到通知,但什么都没有出现.
另外,我在iPhone和模拟器上测试了这个.

我错过了一些非常关键的东西吗?(我搜索了Apple文档,找不到任何关于为什么会发生这种情况的信息)

谢谢

xcode objective-c ios uilocalnotification

17
推荐指数
3
解决办法
1万
查看次数

iOS UILocalNotification - 当应用程序在后台运行时触发没有委托方法,并且在通知时单击图标

iPhone版 - 5.1(9B176)

下面是本地通知期间的一系列事件,其中didFinishLaunchingWithOptions未调用哪种方法.

  1. 应用程序在后台运行.
  2. 得到本地通知 - 简单通知没有对话框.
  3. 单击显示徽章编号的应用程序图标.

根据Apple文档预期:

作为所呈现的通知的结果,用户点击警报的动作按钮或点击(或点击)应用程序图标.如果点击操作按钮(在运行iOS的设备上),系统将启动应用程序,应用程序将调用其委托didFinishLaunchingWithOptions方法(如果已实现); 它传递通知有效负载(用于远程通知)或本地通知对象(用于本地通知).

如果在运行iOS的设备上轻触应用程序图标,则应用程序会调用相同的方法,但不会提供有关通知的信息

实际:未 didFinishLaunchingWithOptions 调用.但applicationWillEnterForegroundapplicationDidBecomeActive被调用.

iphone notifications localnotification uilocalnotification ios5

17
推荐指数
1
解决办法
9836
查看次数

如何在swift中按下按钮取消localNotification?

我正在UILocalNotification通过单击按钮来安排位置.但是当我尝试通过再次单击相同的按钮取消localNotification时,它不会取消通知.我正在使用UIApplication.sharedApplication().cancelLocalNotification(localNotification) 取消我的预定位置的本地通知.我究竟做错了什么 ?这是我的实施

@IBAction func setNotification(sender: UIButton!) {
    if sender.tag == 999 {
        sender.setImage(UIImage(named: "NotificationFilled")!, forState: .Normal)
        sender.tag = 0
        regionMonitor() //function where notification get scheduled

    } else {
        sender.setImage(UIImage(named: "Notification")!, forState: .Normal)
        sender.tag = 999 }
Run Code Online (Sandbox Code Playgroud)

我该怎么进入else块,以便取消预定的通知.无法清除所有通知.这是didEnterRegion我触发本地通知的块代码

func locationManager(manager: CLLocationManager!, didEnterRegion region: CLRegion!) {
    localNotification.regionTriggersOnce = true
    localNotification.alertBody = "Stack Overflow is great"
    UIApplication.sharedApplication().scheduleLocalNotification(localNotification)
    NSLog("Entering region")
}
Run Code Online (Sandbox Code Playgroud)

iphone ios uilocalnotification swift ios8

17
推荐指数
2
解决办法
2万
查看次数

将@available与存储的属性一起使用

我有一个使用本地通知并支持iOS 10的应用程序.我正在尝试添加iOS 9支持,这需要我使用旧的位置通知API.我试图在我的iOS 10代码上使用@available和#available,我无法弄清楚如何将我的中心变量仅用于运行iOS 10的设备.

当我将目标从iOS 10设置为9时,我收到此变量的错误消息:"UNUserNotificationCenter仅适用于iOS 10.0或更高版本." 它建议我将"@available(iOS 10.0,*)"添加到我的整个班级,我不想这样做,因为这个类中的代码将用于iOS 9.我很感激有关如何限制我的任何建议中心属性到iOS 10.

class ViewController: UIViewController, UITextFieldDelegate {

  let center = UNUserNotificationCenter.current()
  ...
Run Code Online (Sandbox Code Playgroud)

ios uilocalnotification swift

17
推荐指数
4
解决办法
4849
查看次数

在iOS中的特定时间启动本地通知

我正在尝试创建一个计时器,在用户设置的时间触发本地通知.我遇到的问题是,我无法找到一种方法,可以设置本地通知在7:00 PM时关闭.研究此问题时发现的几乎所有方法都涉及从当前日期起一定时间内发出的本地通知.我试图允许用户选择晚上7点,然后在那时关闭通知.从逻辑上讲,这可以通过最终时间(用户选择的值)来实现 - 当前时间可以给你时差.但我不完全确定如何做到这一点.

非常感谢您对该主题的任何帮助,谢谢.以下是我目前用于触发本地通知的代码.

let center = UNUserNotificationCenter.current()

content.title = storedMessage
content.body = "Drag down to reset or disable alarm"
content.categoryIdentifier = "alarm"
content.userInfo = ["customData": "fizzbuzz"]
content.sound = UNNotificationSound.init(named: "1.mp3")
content.badge = 1

let trigger = UNTimeIntervalNotificationTrigger(timeInterval: timeAmount, repeats: false)
let request = UNNotificationRequest(identifier: "requestAlarm", content: content, trigger: trigger)
    center.add(request)


center.delegate = self
Run Code Online (Sandbox Code Playgroud)

time timer ios uilocalnotification swift

17
推荐指数
3
解决办法
3万
查看次数

UILocalNotification自定义声音不在iOS7中播放

我正在UILocalNotification申请中使用.

在应用程序中有两种声音有条件地播放 - 我已经为它们应用了适当的条件.

但是当我安装应用程序并在iOS 7设备上运行它时,它会触发本地通知,但声音不会在应用程序中播放.

下面给出了代码来设置通知:

    UILocalNotification *localNotification = [[UILocalNotification alloc] init];
    if (localNotification == nil)
        return;
    localNotification.fireDate = [pickerView date];

    localNotification.timeZone = [NSTimeZone defaultTimeZone];

    if (alarm_number == 1) {
        localNotification.alertBody = [NSString stringWithFormat:@"First Alarm"];
    }
    else
    {
        localNotification.alertBody = [NSString stringWithFormat:@"Second Alarm"];
    }

    localNotification.alertAction =@"Ok";

    NSString *message = [[NSString alloc]initWithString:@""];

    if(alarm_number == 1)
    {
        localNotification.soundName=@"Alarm_1.mp3";
        message = @"First Alarm Scheduled";
    }
    else
    {
        localNotification.soundName=@"Alarm_2.mp3";
        message = @"Second Alarm Scheduled";
    }

    localNotification.applicationIconBadgeNumber = 1;

    // …
Run Code Online (Sandbox Code Playgroud)

iphone audio ios uilocalnotification ios7

16
推荐指数
2
解决办法
1万
查看次数