2017-05-22 1 views
0

현재 내 코드가 작동하지 않습니다. 여전히 수동으로 새로 고쳐야합니다. 12 시간마다 자동으로 업데이트하고 싶습니다.Apple Watch 합병증을 자동으로 업데이트하는 방법은 무엇입니까?

func getTimelineStartDate(for complication: CLKComplication, withHandler handler: @escaping (Date?) -> Void) { 

    let date = Calendar.current.startOfDay(for: Date()) 
    print("timeline start date :\(date)") 
    handler(date) 
} 

func getTimelineEndDate(for complication: CLKComplication, withHandler handler: @escaping (Date?) -> Void) { 
    var date = Calendar.current.startOfDay(for: Date()) 
    date = Calendar.current.date(byAdding: .day, value: 2, to: date)! 
    print("timeline end date:\(date)") 
    handler(date) 
} 

func getNextRequestedUpdateDate(handler: @escaping (Date?) -> Void){ 
    handler(Date(timeIntervalSinceNow: 60*60*12)) 


} 

답변

0

데이터 소스 방법이 구현되지 않은 것 같다 참조하십시오. 새로 고침을 위해 구현해야합니다. 예약 업데이트의 시작에서

는 ClockKit은 합병증의 시간 예산의 상태에 따라 requestedUpdateDidBegin 또는 requestedUpdateBudgetExhausted 방법 중 하나를 호출 . 타임 라인에 데이터를 추가하려면 중 하나 또는 둘 모두를 구현해야합니다. 이러한 방법을 구현하면 필요에 따라 시간대를 연장하거나 다시로드해야합니다. 그렇게하면 ClockKit에서 데이터 소스의 새로운 타임 라인 항목을 요청합니다. 타임 라인을 확장하거나 다시로드하지 않으면 ClockKit에서 에 대해 새로운 타임 라인 항목을 묻지 않습니다.

func requestedUpdateDidBegin() { 
    let server=CLKComplicationServer.sharedInstance() 
    for complication in server.activeComplications { 
     server.reloadTimelineForComplication(complication) 
    } 
} 

자세한 내용은 this를 확인합니다.

0

다음 기능을 사용하여 데이터로 채워 넣을 수 있습니다.

func getCurrentTimelineEntry(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimelineEntry?) -> Void) { 
    // Call the handler with the current timeline entry 
    handler(nil) 
} 

func getTimelineEntries(for complication: CLKComplication, before date: Date, limit: Int, withHandler handler: @escaping ([CLKComplicationTimelineEntry]?) -> Void) { 
    // Call the handler with the timeline entries prior to the given date 
    handler(nil) 
} 

func getTimelineEntries(for complication: CLKComplication, after date: Date, limit: Int, withHandler handler: @escaping ([CLKComplicationTimelineEntry]?) -> Void) { 
    // Call the handler with the timeline entries after to the given date 
    handler(nil) 
} 

이 (가) App Programming Guide for watchOS

관련 문제