2017-01-22 14 views
0

私は、特定の時刻(午前8時)にユーザー入力なしで通知を送信し、非表示のUILocalNotificationの代わりに新しいUNMutableNotificationContentを使用し、トリガーにユーザー入力を使用しない方法を見つけようとしていますそれはむしろ時間です。すべての説明が見つかった場合は古いですが、ios 10とswift 3は含まれません。毎日通知Swift 3

これまでの内容

認可ViewController.swiftでお知らせ

let localNotification = UNMutableNotificationContent() 
// localNotification.fireDate = dateFire 
    localNotification.title = "title" 
    localNotification.body = "body" 
    localNotification.badge = 1 
    localNotification.sound = UNNotificationSound.default() 

Notification.swift

override func viewDidLoad() { 

     UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge], completionHandler: {didAllow, error in 
     }) 
    } 

私は、私は他のものの間のトリガと要求を設定する必要があります知っているが、それを得るために正確にどのようにイムわかりません働く

答えて

0

このチュートリアルをチェックしてくださいすることができ - Hacking with swift Notification center

日付コンポーネントの一部である必要なもの。

func scheduleLocal() { 
     let center = UNUserNotificationCenter.current() 

    let localNotification = UNMutableNotificationContent() 
    localNotification.title = "title" 
    localNotification.body = "body" 
    localNotification.badge = 1 
    localNotification.sound = UNNotificationSound.default() 

     var dateComponents = DateComponents() 
     dateComponents.hour = 10 
     dateComponents.minute = 30 
     let trigger = UNCalendarNotificationTrigger(dateMatching: dateComponents, repeats: true) 

     let request = UNNotificationRequest(identifier: UUID().uuidString, content: localNotification, trigger: trigger) 
     center.add(request) 
    } 

詳しくはチュートリアルをご覧ください。それは速い3 iOS 10で書かれている同じのためHere's github repo

0

第1工程:

import UserNotifications 

と判断して、ユーザが通知

UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { 
granted, error in 
    if granted { 
     // determine whether the user allows notification 
    } 
} 

第二ステップ許可するかどうかを:あなたがフィン可能通知

// 1. create notification's content 
let content = UNMutableNotificationContent() 
content.title = "Time Interval Notification" 
content.body = "My first notification" 

// 2. create trigger 
//custom your time in here 
var components = DateComponents.init() 
components.hour = 8 
let trigger = UNCalendarNotificationTrigger(dateMatching: components, repeats: false) 

// 3. send request identifier 
let requestIdentifier = "com.xxx.usernotification.myFirstNotification" 

// 4. create send request 
let request = UNNotificationRequest(identifier: requestIdentifier, content: content, trigger: trigger) 

// add request to send center 
UNUserNotificationCenter.current().add(request) { error in 
    if error == nil { 
     print("Time Interval Notification scheduled: \(requestIdentifier)") 
    } 
} 

を作成

をd詳細はApple Documentation

関連する問題