无需启动应用即可处理本地通知

时间:2016-05-16 15:50:16

标签: ios swift uilocalnotification

有没有办法为本地通知创建一个动作而不启动IOS应用程序? 例如,我需要通过短信或电子邮件发送通知的alertBody,而不是启动应用程序或将其保留在后台

UPD

我想在应用程序处于非活动状态时显示activityViewController的视图

这是我的代码

class MyClass {
  class func SendTxt(text: String) {

    if let topVc = getTopMostController() {

        let objectsToShare: [AnyObject] = [ text ]
        let activityViewController = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)
        activityViewController.popoverPresentationController?.sourceView = topVc.view 

        activityViewController.excludedActivityTypes = [ UIActivityTypeAirDrop, UIActivityTypePostToFacebook ]

        topVc.presentViewController(activityViewController, animated: true, completion: nil)
    }
  }
}

//AppDelegate

func application(application: UIApplication, handleActionWithIdentifier identifier: String?, forLocalNotification notification: UILocalNotification, completionHandler: () -> Void) {

    print("handleActionWithIdentifier = \(identifier)")

    if application.applicationState == .Background ||  application.applicationState == .Inactive {

        if identifier == "send" {
            MyClass.SendTxt("Hello world")
        }
    }
    completionHandler()
}

0 个答案:

没有答案