2016-07-14 11 views

答えて

3

かなり簡単です。

AppDelegate

あなたのアクションで次に
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 
    application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: [.Alert, .Sound, .Badge], categories: nil)) 
    return true 
} 

func application(application: UIApplication, didReceiveLocalNotification notification: UILocalNotification) { 
    print("Local notification received (tapped, or while app in foreground): \(notification)") 
} 

@IBAction func welcomeMe(sender: AnyObject) { 
    let notification = UILocalNotification() 
    notification.alertBody = "Welcome to the app!" // text that will be displayed in the notification 

    notification.fireDate = NSDate(timeIntervalSinceNow: 2) 
    notification.soundName = UILocalNotificationDefaultSoundName 

    notification.userInfo = ["title": "Title", "UUID": "12345"]   
    UIApplication.sharedApplication().scheduleLocalNotification(notification) 
} 

アプリがバックグラウンドで動作している場合さて、あなたはプッシュ通知を参照してください。それが前景にある場合は、didReceiveLocalNotificationが代わりに発砲します。通知をタップすると、アプリケーションはフォアグラウンドに起動し、didReceiveLocalNotificationも起動します。

0

YouTubeでは、Jared Davidsonが素晴らしいiOSチュートリアルを提供しています。 彼は、通知の2を持っています

この1つはあなたが必要なものだけです:

https://www.youtube.com/watch?v=tqJFJzUPpcI

...とリモート通知の1(ないボタン付き)があります

https://www.youtube.com/watch?v=LBw5tuTvKd4

+0

注:AppCodaに**素晴らしいチュートリアルがあります:https://www.appcoda.com/push-notification-ios/ – penatheboss

+0

私は実際にはプッシュ通知を定期的な通知ではなく、とにかく感謝しています。 – SwiftyJD

関連する問題