小编Iva*_*van的帖子

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

当用户最小化应用程序时(通过单击iPhone的主页按钮或同时锁定手机),我试图向用户发送"推送通知样式"警报.

我的应用程序不断解析XML文件(每10秒钟),我希望应用程序继续运行,以便在我的程序中满足某些条件后向用户发送本地通知,即使用户已最小化应用程序或锁定了电话.

我已经从教程中反复出现,每个人似乎都"安排"通知,但这对我不起作用,因为我的通知不是基于时间的,而是基于满足条件.

到目前为止我做了什么:

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
}
Run Code Online (Sandbox Code Playgroud)

MapViewController.swift

// Some function
func someFunction(delta: Int) {
    if delta < 100 {
        // Send alert to user if app is open
        let alertView = UIAlertController(title: "This is an Alert!", message: "", preferredStyle: UIAlertControllerStyle.Alert)
        alertView.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))
        self.presentViewController(alertView, animated: true, completion: nil)

        // Send user …
Run Code Online (Sandbox Code Playgroud)

nstimer ios uilocalnotification swift uialertaction

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

标签 统计

ios ×1

nstimer ×1

swift ×1

uialertaction ×1

uilocalnotification ×1