2016-08-18 94 views
0

我有工作的手表前景通知背景通知

UNUserNotificationCenter.current().delegate = self 

收到前景通知:

func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Swift.Void) 
{ 
    print("Received Notification .....") 
    UNUserNotificationCenter.current().removeAllDeliveredNotifications() 
    let completionSound: UNNotificationPresentationOptions = [.sound, .alert] 
    completionHandler(completionSound) 
} 

加通知:

let content: UNMutableNotificationContent = UNMutableNotificationContent() 

    content.title = "TITLE" 
    content.subtitle = "sub title" 
    content.body = "message body" 
    content.sound = UNNotificationSound.default() 

    let trigger = UNTimeIntervalNotificationTrigger(timeInterval: duration, repeats: false) 

    let request = UNNotificationRequest(identifier: restOverIdentifier, 
             content: content, 
             trigger: trigger) 

    UNUserNotificationCenter.current().add(request) 
    { 
     (error) in // ... 
    } 

我已经尝试了SIM卡和设备,但没有运气在SIM卡锁定或主屏幕时收到通知,或者手表在屏幕变黑时不通过移动手臂。

我正在寻找的是一个简单的嘟嘟声,我甚至不需要通知提醒屏幕。

如果你有这方面的工作或确认这个功能不工作在手表上,请发布代码。

感谢

格雷格

回答

2

有是仅显示第一通知,watchOS 3中的错误:

临时改变我的代码:

let id: String = WatchNotify.getUUID() 

    //  let request = UNNotificationRequest(identifier: focusWarningIdentifier, 
    let request = UNNotificationRequest.init(identifier: id, 
             content: content, 
             trigger: trigger) 

    UNUserNotificationCenter.current().add(request) 

这个附加功能对于UUID:

class func getUUID() -> String 
{ 
    let uuidObj = CFUUIDCreate(nil) 
    let uuidString = CFUUIDCreateString(nil, uuidObj)! 
    return uuidString as String 
} 

虽然代理完成处理程序似乎还没有在手表上工作,似乎做的伎俩。