viewController.swiftの[Localnotificationをスケジュールし、そこから表示制御部]のviewDidLoadで
func scheduleLocal() {
let settings = UIApplication.sharedApplication(). currentUserNotificationSettings()
if settings!.types == .None {
let ac = UIAlertController(title: "Can't schedule", message: "Either we don't have permission to schedule notifications, or we haven't asked yet.", preferredStyle: .Alert)
ac.addAction(UIAlertAction(title: "OK", style: .Default, handler: nil))
presentViewController(ac, animated: true, completion: nil)
return
}
let notification = UILocalNotification()
notification.fireDate = NSDate(timeIntervalSinceNow: 15)
notification.alertBody = "Hey you! Yeah you! Swipe to unlock!"
notification.alertAction = "be awesome!"
notification.soundName = UILocalNotificationDefaultSoundName
notification.userInfo = ["CustomField1": "w00t"]
UIApplication.sharedApplication().scheduleLocalNotification(notification)
}
()applicationdidFinishlaunchingで
self.scheduleLocal()
()
let notificationSettings = UIUserNotificationSettings(forTypes:[.Alert, .Badge, .Sound] , categories: nil)
UIApplication.sharedApplication().registerUserNotificationSettings(notificationSettings)
if let options = launchOptions {
if let notification = options[UIApplicationLaunchOptionsLocalNotificationKey] as? UILocalNotification {
if let userInfo = notification.userInfo {
let customField1 = userInfo["CustomField1"] as! String
// do something neat here
}
}
}
この溶液
を試します
とは、最後にappdelegate.swiftに
func application(application: UIApplication, didReceiveLocalNotification notification: UILocalNotification) {
if let userInfo = notification.userInfo {
let customField1 = userInfo["CustomField1"] as! String
print("didReceiveLocalNotification: \(customField1)")
}
}
を試してみました:-)あなたが試したものを私たちに示し、そして見てくださいスタックオーバーフローにXcodeの上7.3.1 SWIFT 2.2
ようこそ働いた[尋ねます] と[mcve]。これは便利な答えを得るのに役立ちます。 – JimHawkins
なぜ、あなたは火の結果として何をしたいですか? – Wain
@Wainその後、iPhoneの音楽ライブラリから音楽を聴きたい。 – Jun