2017-10-07 4 views
0
func scheduleNotification(inSeconds: TimeInterval, completion: @escaping (_ Success: Bool) ->()) { 

     let notif = UNNotificationContent() 

     notif.title = NSString.localizedUserNotificationString(forKey: "New Notification", arguments: nil) 
     notif.subtitle = "These are great!" 
     notif.body = "The new notification options are awesome!" 

     let notifTrigger = UNTimeIntervalNotificationTrigger(timeInterval: inSeconds, repeats: false) 

     let request = UNNotificationRequest(identifier: "myNotification", content: notif, trigger: notifTrigger) 

     UNUserNotificationCenter.current().add(request, withCompletionHandler: {error in 
      if error != nil { 
       print(error) 
       completion(false) 
      } else { 
       completion(true) 
      } 

     }) 
    } 

Udemy 비디오를 따라하고 있으며 로컬 알림의 제목, 부제목 및 본문을 설정하는 데 문제가 있습니다. 세 개의 할당 라인 모두에 대해 동일한 오류가 발생합니다.로컬 알림의 제목, 부제목 및 본문 선언하기

속성에 할당 할 수 없습니다. 'xxx'는 get 전용 속성입니다.

답변

0

신속하게 문서에서 찾았습니다. 그것은 :

직접이 클래스의 인스턴스를 만들지 마십시오. (...) 지역 알림의 경우 UNMutableNotificationContent 개체를 만들고 대신 해당 개체의 내용을 구성합니다.

출처 : https://developer.apple.com/documentation/usernotifications/unnotificationcontent

나는이 수업 정말 익숙하지 않아요하지만 난 UNNotificationContent 생각은 수신 된 데이터에서 자동으로 콘텐츠를 채 웁니다.

나는 이것이 당신이 찾고있는 경우 완전히 확실하지 않다,하지만 어쩌면 UNNotificationContent 대신 UNMutableNotificationContent를 사용해보십시오 :

let notif = UNMutableNotificationContent() 
관련 문제