2017-04-12 3 views
0

매일 반복 될 때 로컬 알림에서 메시지를 업데이트하는 방법을 찾으려고합니다.iOS 10에서 일일 로컬 알림 메시지를 업데이트하는 방법은 무엇입니까?

func scheduler(at date: Date, numOfNotes: Int) 
{ 
    let calendar = Calendar(identifier: .gregorian) 

    let components = calendar.dateComponents(in: .current, from: date) 

    let newComponents = DateComponents(calendar: calendar, timeZone: .current, hour: components.hour, minute: components.minute) 

    let trigger = UNCalendarNotificationTrigger(dateMatching: newComponents, repeats: true) 

    content.badge = numOfNotes as NSNumber 

    content.body = "REMINDER: " + String(numOfNotes) + " needs to be looked at!" 

    content.sound = UNNotificationSound.default() 

    let request = UNNotificationRequest(identifier: "reminderNotification", content: content, trigger: trigger) 

    UNUserNotificationCenter.current().delegate = self 

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

    } 
} 

내가 UserDefaultsnumOfNotes를 저장하고 :

현재 내 AppDelegate에 다음 코드를 가지고있다. 지정된 시간에 매일 알림 반복을 가지고 truerepeats 매개 변수를 설정할 때, numOfNotes이 아니라 그러나

func remindMeSwitch(_ remindMeSwitch: UISwitch) 
{ 
    numOfNotes = UserDefaults.standard.integer(forKey: "Notes") 

    let delegate = UIApplication.shared.delegate as? AppDelegate 

    delegate?.scheduler(at: time, numOfNotes: numOfNotes) 
} 

: 나는 scheduler 기능과 같이 호출로 전환 될 때 내 UITableViewCell에서 UISwitch, 그이 나는 한 번 불렀다. 나는 UISwitch을 토글했다.

알림을 매일 알림으로 설정할 수 있지만 필요에 따라 알림 메시지를 계속 업데이트하려면 어떻게해야합니까?

감사합니다.

+1

은 당신이 이것을 달성하기 위해 적절한 메시지로 개별 비 반복 알림을 예약해야 할 것 보인다. – Losiowaty

+0

@Losiowaty, 나는 그럴 수 있었다고 생각하지만 카운트가 변경 될 때마다 일정을 다시 잡을 필요가 없기를 바랄 것입니다. – Pangu

+0

알림 서비스 앱 확장을 추가 할 수는 있지만 그 전화가 필요한지 확실하지 않습니다. 현지 알림. 또한 iOS 10에서만 사용할 수 있습니다. – Losiowaty

답변

0

일반적으로 로컬 알림을 변경할 가능성이 없습니다. 한 가지 방법 - 이전 알림을 삭제/취소하고 새 알림을 만듭니다. 하지만 복사 기능을 사용할 수 있습니다. 예를 들어

, 당신은 통지의 내용 변경하려는 경우 : 그것은 것

// create new content (based on old) 
if let content = notificationRequest.content.mutableCopy() as? UNMutableNotificationContent { 
    // any changes  
    content.title = "your new content's title" 
    // create new notification 
    let request = UNNotificationRequest(identifier: notificationRequest.identifier, content: content, trigger: notificationRequest.trigger) 
    UNUserNotificationCenter.current().add(request) 
}