2017-09-12 7 views
0

배경 :여러 로컬 알림을 표시하는 방법

봇이 메시지를 보내는 응용 프로그램을 작성 중입니다. 이러한 메시지는 로컬 알림으로 수신 될 수 있습니다.

문제는 :

보트가 단기간 내에 복수의 통지를 송신한다 (각 메시지 사이 일초), 통지 센터는 하나의 메시지를 표시한다. 내가 예상 할 때마다 알림 소리가 들리 겠지만, 나는 여전히 첫 번째 메시지 만 볼 것입니다.

관련 코드 : 코드 문제

func postUserNotification(content: String, delay: TimeInterval, withDictionary dictionary: [String:String] = [:]) { 

    let notificationContent = UNMutableNotificationContent() 
    notificationContent.body = content 
    notificationContent.userInfo = dictionary 
    notificationContent.categoryIdentifier = "message" 

    let dateAfterDelay = Date(timeIntervalSinceNow: delay) 

    let dateComponents = Calendar.current.dateComponents([.year,.month,.day,.hour,.minute,.second], from: dateAfterDelay) 


    let trigger = UNCalendarNotificationTrigger(dateMatching: dateComponents, repeats: false) 

    let identifier = "identifier" + "\(NotificationManager.incrementor)" 

    let localNotification = UNNotificationRequest(identifier: identifier, content: notificationContent, trigger: trigger) 

    UNUserNotificationCenter.current().add(localNotification){ (error : Error?) in 
     if let theError = error { 
      print("the error is \(theError.localizedDescription)") 
     } 
    } 
} 
+0

Arnav가 언급했듯이 이것은 예상되는 기능이므로 이제 질문은 좋은 해결 방법은? – osebas15

+0

문제는 앱이 비활성 상태 임에도 불구하고 앱에서 알림을 보내려고한다는 것입니다. 이 사실을 깨닫고 앱이 실제로 활성 상태를 잃기 전에 다가오는 모든 알림을 대기열에 올려 놓음으로써 해결되었습니다. – osebas15

답변

1

아무것도 :

당신이 당신의 질문에 쓴 것처럼,이는 애플의 문서에서 언급 한 :

If you are sending multiple notifications to the same device or 
computer within a short period of time, the push service will send only 
the last one. 

https://developer.apple.com/library/content/technotes/tn2265/_index.html#//apple_ref/doc/uid/DTS40010376-CH1-TNTAG23

+0

답장과 링크에 감사 드리며 해결 방법을 가르쳐 줄 수 있습니까? – osebas15