[swift] UILocalNotificationの実装

UILocalNotificationの実装

UILocalNotificationとは自分が自分宛てに送信できるNotification機能。
こちらの場合でもNotification許可は必要

サンプルコード

func showNotification(){
        
        // Notificationの生成する.
        let myNotification: UILocalNotification = UILocalNotification()
        
        // メッセージを代入する.
        myNotification.alertBody = "This is Local Notification"
        
        // 再生サウンドを設定する.
        myNotification.soundName = UILocalNotificationDefaultSoundName
        
        // Timezoneを設定する.
        myNotification.timeZone = NSTimeZone.defaultTimeZone()
        
        // 10秒後に設定する.
        myNotification.fireDate = NSDate(timeIntervalSinceNow: 10)
        
        // Notificationを表示する.
        UIApplication.sharedApplication().scheduleLocalNotification(myNotification)
    }

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です