このチュートリアルは、アプリの通知に使用しますhttp://www.appcoda.com/local-notifications-ios8/
各通知にはアクションがあります-編集。viewDidLoad()メソッドにオブザーバーを追加します。
NSNotificationCenter.defaultCenter().addObserver(self, selector: "handleModifyListNotification", name: "modifyListNotification", object: nil)
通知で[編集]ボタンを押すと、アプリは次のメソッドを呼び出します。
func handleModifyListNotification() {
}
私が使用する割り当て通知の場合:
func scheduleLocalNotification() {
var dateComp:NSDateComponents = NSDateComponents()
dateComp.year = 2015;
dateComp.month = 02;
dateComp.day = 24;
dateComp.hour = 14;
dateComp.minute = 34;
dateComp.timeZone = NSTimeZone.systemTimeZone()
var calender:NSCalendar? = NSCalendar(calendarIdentifier: NSGregorianCalendar)
var date:NSDate = calender!.dateFromComponents(dateComp)!
var localNotification = UILocalNotification()
localNotification.fireDate = fixNotificationDate(date)
localNotification.alertBody = "Hey, you must go shopping, remember?"
localNotification.alertAction = "View List"
localNotification.category = "shoppingListReminderCategory"
UIApplication.sharedApplication().scheduleLocalNotification(localNotification)
}
しかし、どの通知がこのメソッドを呼び出すかを知るために、このメソッドにデータを送信するにはどうすればよいですか?
notification
次のように宣言し、
NSNotificationCenter.defaultCenter().addObserver(self, selector: "handleModifyListNotification:", name: "modifyListNotification", object: nil)
とcolon
の中でSelector
。
のPost your notification
ように、
NSNotificationCenter.defaultCenter().postNotificationName("modifyListNotification", object: "Your Object Value")
そしてあなたの機能は、
func handleModifyListNotification(notification: NSNotification) {
NSLog("Object is %@", notification.valueForKey("object") as String!)
}
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加