Ios 如何使用UILocalNotification打开包含CoreData的spesific视图
我正在开发一个应用程序,用户可以在其中设置通知提醒,将CoreData实例的密码更改为设置提醒的密码 当用户点击“第一个动作”按钮时,我希望他被重定向到第二个和第四个视图 这就是我想要的 来自my AirlineViewController.swift和AppDelegate.swift的相关代码Ios 如何使用UILocalNotification打开包含CoreData的spesific视图,ios,xcode,swift,core-data,uilocalnotification,Ios,Xcode,Swift,Core Data,Uilocalnotification,我正在开发一个应用程序,用户可以在其中设置通知提醒,将CoreData实例的密码更改为设置提醒的密码 当用户点击“第一个动作”按钮时,我希望他被重定向到第二个和第四个视图 这就是我想要的 来自my AirlineViewController.swift和AppDelegate.swift的相关代码 func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
//Actions
var firstAction:UIMutableUserNotificationAction = UIMutableUserNotificationAction()
firstAction.identifier = "FIRST_ACTION"
firstAction.title = "First Actions"
firstAction.activationMode = UIUserNotificationActivationMode.Foreground
firstAction.destructive = true
firstAction.authenticationRequired = false
var secondAction:UIMutableUserNotificationAction = UIMutableUserNotificationAction()
secondAction.identifier = "SECOND_ACTION"
secondAction.title = "Second Actions"
secondAction.activationMode = UIUserNotificationActivationMode.Foreground
secondAction.destructive = false
secondAction.authenticationRequired = false
var thirdAction:UIMutableUserNotificationAction = UIMutableUserNotificationAction()
thirdAction.identifier = "THIRD_ACTION"
thirdAction.title = "Third Actions"
thirdAction.activationMode = UIUserNotificationActivationMode.Background
thirdAction.destructive = false
thirdAction.authenticationRequired = false
//Category
var firstCategory:UIMutableUserNotificationCategory = UIMutableUserNotificationCategory()
firstCategory.identifier = "FIRST_CATEGORY"
let defaultActions:NSArray = [firstAction, secondAction, thirdAction]
let minimalActions:NSArray = [firstAction, secondAction]
firstCategory.setActions(defaultActions as [AnyObject], forContext: UIUserNotificationActionContext.Default)
firstCategory.setActions(minimalActions as [AnyObject], forContext: UIUserNotificationActionContext.Minimal)
//NSSet of all our categories
let categories:NSSet = NSSet(objects: firstCategory)
let types:UIUserNotificationType = UIUserNotificationType.Alert | UIUserNotificationType.Badge
let mySettings:UIUserNotificationSettings = UIUserNotificationSettings(forTypes: types, categories: categories as Set<NSObject>)
UIApplication.sharedApplication().registerUserNotificationSettings(mySettings)
return true
}
func application(application: UIApplication!,
handleActionWithIdentifier identifier:String!,
forLocalNotification notification:UILocalNotification!,
completionHandler: (() -> Void)!){
if (identifier == "FIRST_ACTION"){
NSNotificationCenter.defaultCenter().postNotificationName("actionOnePressed", object: nil)
}else if (identifier == "SECOND_ACTION"){
NSNotificationCenter.defaultCenter().postNotificationName("actionTwoPressed", object: nil)
}
completionHandler()
}
AirlineViewController.swift:
@IBAction func buttonTapped(sender: AnyObject) {
NSNotificationCenter.defaultCenter().addObserver(self, selector:"showAMessage:", name: "actionOnePressed", object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector:"drawAShape:", name: "actionTwoPressed", object: nil)
var dateComp:NSDateComponents = NSDateComponents()
dateComp.year = 2015;
dateComp.month = 08;
dateComp.day = 03;
dateComp.hour = 21;
dateComp.minute = 03;
dateComp.timeZone = NSTimeZone.systemTimeZone()
var calender:NSCalendar = NSCalendar(calendarIdentifier: NSCalendarIdentifierGregorian)!
var date:NSDate = calender.dateFromComponents(dateComp)!
var notification:UILocalNotification = UILocalNotification()
notification.category = "FIRST_CATEGORY"
notification.alertBody = "Hi, I am a notification"
notification.fireDate = date
UIApplication.sharedApplication().scheduleLocalNotification(notification)
}
func drawAShape(notification:NSNotification){
println("drawAShape")
var view:UIView = UIView(frame:CGRectMake(10, 10, 100, 100))
view.backgroundColor = UIColor.redColor()
self.view.addSubview(view)
println("drawAShape")
}
func showAMessage(notification:NSNotification){
var message:UIAlertController = UIAlertController(title: "A Notification Message", message: "Hello there", preferredStyle: UIAlertControllerStyle.Alert)
message.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(message, animated: true, completion: nil)
}
AppDelegate.swift
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
//Actions
var firstAction:UIMutableUserNotificationAction = UIMutableUserNotificationAction()
firstAction.identifier = "FIRST_ACTION"
firstAction.title = "First Actions"
firstAction.activationMode = UIUserNotificationActivationMode.Foreground
firstAction.destructive = true
firstAction.authenticationRequired = false
var secondAction:UIMutableUserNotificationAction = UIMutableUserNotificationAction()
secondAction.identifier = "SECOND_ACTION"
secondAction.title = "Second Actions"
secondAction.activationMode = UIUserNotificationActivationMode.Foreground
secondAction.destructive = false
secondAction.authenticationRequired = false
var thirdAction:UIMutableUserNotificationAction = UIMutableUserNotificationAction()
thirdAction.identifier = "THIRD_ACTION"
thirdAction.title = "Third Actions"
thirdAction.activationMode = UIUserNotificationActivationMode.Background
thirdAction.destructive = false
thirdAction.authenticationRequired = false
//Category
var firstCategory:UIMutableUserNotificationCategory = UIMutableUserNotificationCategory()
firstCategory.identifier = "FIRST_CATEGORY"
let defaultActions:NSArray = [firstAction, secondAction, thirdAction]
let minimalActions:NSArray = [firstAction, secondAction]
firstCategory.setActions(defaultActions as [AnyObject], forContext: UIUserNotificationActionContext.Default)
firstCategory.setActions(minimalActions as [AnyObject], forContext: UIUserNotificationActionContext.Minimal)
//NSSet of all our categories
let categories:NSSet = NSSet(objects: firstCategory)
let types:UIUserNotificationType = UIUserNotificationType.Alert | UIUserNotificationType.Badge
let mySettings:UIUserNotificationSettings = UIUserNotificationSettings(forTypes: types, categories: categories as Set<NSObject>)
UIApplication.sharedApplication().registerUserNotificationSettings(mySettings)
return true
}
func application(application: UIApplication!,
handleActionWithIdentifier identifier:String!,
forLocalNotification notification:UILocalNotification!,
completionHandler: (() -> Void)!){
if (identifier == "FIRST_ACTION"){
NSNotificationCenter.defaultCenter().postNotificationName("actionOnePressed", object: nil)
}else if (identifier == "SECOND_ACTION"){
NSNotificationCenter.defaultCenter().postNotificationName("actionTwoPressed", object: nil)
}
completionHandler()
}
func应用程序(应用程序:UIApplication,didfishlaunchingwithoptions启动选项:[NSObject:AnyObject]?)->Bool{
//行动
var firstAction:UIMutableUserNotificationAction=UIMutableUserNotificationAction()
firstAction.identifier=“第一步行动”
firstAction.title=“第一个操作”
firstAction.activationMode=UIUserNotificationActivationMode.前台
firstAction.com=true
firstAction.authenticationRequired=false
var secondAction:UIMutableUserNotificationAction=UIMutableUserNotificationAction()
secondAction.identifier=“第二个动作”
secondAction.title=“第二个操作”
secondAction.activationMode=UIUserNotificationActivationMode.Foreground
secondAction.destructive=false
secondAction.authenticationRequired=false
var thirdAction:UIMutableUserNotificationAction=UIMutableUserNotificationAction()
thirdAction.identifier=“第三个动作”
thirdAction.title=“第三次行动”
thirdAction.activationMode=UIUserNotificationActivationMode.Background
第三次破坏性=错误
thirdAction.authenticationRequired=false
//类别
var firstCategory:UIMutableUserNotificationCategory=UIMutableUserNotificationCategory()
firstCategory.identifier=“第一类”
让defaultActions:NSArray=[firstAction,secondAction,thirdAction]
让最小动作:NSArray=[firstAction,secondAction]
setActions(默认操作为[AnyObject],forContext:UIUserNotificationActionContext.Default)
setActions(MinimaActions作为[AnyObject],forContext:UIUserNotificationActionContext.Minimal)
//我们所有类别的NSSet
let categories:NSSet=NSSet(对象:firstCategory)
let类型:UIUserNotificationType=UIUserNotificationType.Alert | UIUserNotificationType.Badge
让mySettings:UIUserNotificationSettings=UIUserNotificationSettings(forTypes:types,categories:categories as Set)
UIApplication.sharedApplication().registerUserNotificationSettings(mySettings)
返回真值
}
func应用程序(应用程序:UIApplication!,
handleActionWithIdentifier标识符:字符串!,
forLocalNotification通知:UILocalNotification!,
completionHandler:(()->Void)!){
如果(标识符==“第一步行动”){
NSNotificationCenter.defaultCenter().postNotificationName(“actionOnePressed”,对象:nil)
}else if(标识符=“第二个动作”){
NSNotificationCenter.defaultCenter().postNotificationName(“actionTwoPressed”,对象:nil)
}
completionHandler()
}
此代码的问题在于,如果应用程序完全关闭,它只会打开最后一个视图或第一个视图
有人能帮我吗据我所知,没有内置机制可以让
UILocalNotification
直接将您带到应用程序UI的特定部分
您可以在发布前将userInfo
词典附加到UILocalNotification
然后,您可以查询userInfo字典,找出它应该将用户带到UI中的何处,并编写自定义代码将用户带到应用UI的该部分
我正在为一个客户端开发一个应用程序。我嵌入了让应用程序调用相关屏幕所需的信息。(具体取决于应用程序的设计,该应用程序使用自定义表单描述文件来描述应用程序中视图控制器的层次结构。)据我所知,没有内置机制可以让
UILocalNotification
直接将您带到应用程序UI的特定部分
您可以在发布前将userInfo
词典附加到UILocalNotification
然后,您可以查询userInfo字典,找出它应该将用户带到UI中的何处,并编写自定义代码将用户带到应用UI的该部分
我正在为一个客户端开发一个应用程序。我嵌入了让应用程序调用相关屏幕所需的信息。(具体细节取决于应用程序的设计,该应用程序使用自定义表单描述文件来描述应用程序中视图控制器的层次结构。)可能重复的可能重复的