20201009 iOS 14 ウィジェットをつくってみた

70adfe7679427fa498899769e632b672?s=47 Kei Ito
October 09, 2020

20201009 iOS 14 ウィジェットをつくってみた

70adfe7679427fa498899769e632b672?s=128

Kei Ito

October 09, 2020
Tweet

Transcript

  1. J04΢ΟδΣοτΛ ͭͬͯ͘Έͨ .PCJMF"DU0/-*/& JUPL!ͦΒ͔ͥ

  2. JUPL!ͦΒ͔ͥ w ͍ͱ͏͚͍ʢJUPLʣ w ɹɹɹɹɹɹͷதͷਓ w ϞόΠϧΞϓϦΤϯδχΞ݉$&0 w ෭ۀͰϑϦʔϥϯεత w

    IUUQTJUPLKQ IUUQTTPSBLB[FDPKQ !JUPLKQ
  3. ॴࡏ஍ɿژ౎ࢢதژ۠ ࣾһਓࣗ෼

  4. ࣮੷ डୗ ࣗࣾ

  5. J04"OESPJENBD048JOEPXTαʔό ҰਓͰ΍ͬͯ·͢ʢσβΠϯҎ֎ʣ

  6. iOS൛ v10.0.0

  7. None
  8. J04 ΢ΟδΣοτΛ ͭͬͯ͘Έͨ

  9. ·ͣ஫ҙࣄ߲

  10. 4XJGU6*ඞਢ

  11. 6*,JU࢖͑·ͤΜ

  12. 6*7JFX3FQSFTFOUBCMFΛ ࢖͏ͱ͜͏ͳΔ

  13. ࢀߟ w 88%$ w 8JEHFU,JUʹ͍ͭͯ w 8JEHFU$PEF"MPOHʙ

  14. ΢ΟδΣοτͷछྨ

  15. TNBMM NFEJVN MBSHF ֎ݟ ૢ࡞ શମλοϓͷΈ શମ ೚ҙͷྖҬλοϓ

  16. ૢ࡞ w શମλοϓ w ೚ҙͷྖҬλοϓ { }.widgetURL(url) Link(destination: url) {

    }
  17. جຊߏ଄ 8JEHFU 8JEHFU$POpHVSBUJPO 5JNFMJOF1SPWJEFS 7JFX 5JNFMJOF&OUSZ

  18. جຊߏ଄ struct MyWidget: Widget { public var body: some WidgetConfiguration

    { StaticConfiguration(kind: kind, provider: MyProvider()) { entry in MyWidgetEntryView(entry: entry) } } } struct MyProvider: TimelineProvider { func getTimeline(in context: Context, completion: @escaping (Timeline<MyEntry>) -> Void) { ... completion(Timeline(entries: entries, policy: .atEnd)) } } struct MyWidgetEntryView : View { var entry: MyEntry var body: some View { ... } }
  19. ઃఆʢTUBUJDʣ͋Γ 8JEHFU 8JEHFU$POpHVSBUJPO *OUFOU 7JFX 5JNFMJOF&OUSZ 5JNFMJOF1SPWJEFS

  20. ઃఆʢEZOBNJDʣ͋Γ 8JEHFU 8JEHFU$POpHVSBUJPO *OUFOU 7JFX 5JNFMJOF&OUSZ 5JNFMJOF1SPWJEFS *OUFOU&YUFOTJPO

  21. ઃఆ͋Γ struct MyWidget: Widget { public var body: some WidgetConfiguration

    { IntentConfiguration(kind: kind, intent: MySelectionIntent.self, provider: MyIntentProvider()) { entry in MyWidgetEntryView(entry: entry) } } } struct MyIntentProvider: IntentTimelineProvider { func getTimeline(for configuration: MySelectionIntent, in context: Context, completion: @escaping (Timeline<MyEntry>) -> Void) { ... completion(Timeline(entries: entries, policy: .after(date))) } }
  22. IntentHandler.swift class IntentHandler: INExtension, MySelectionIntentHandling { func provideParameterOptionsCollection( for intent:

    MySelectionIntent, with completion: @escaping (INObjectCollection<MyType>?, Error?) -> Void) { completion(INObjectCollection(items: items), nil) } *OUFOU&YUFOTJPO .Z4FMFDUJPOJOUFOUEFpOJUJPO
  23. ߋ৽ public struct TimelineReloadPolicy : Equatable { // entries͕શ෦ऴΘͬͨΒߋ৽ public

    static let atEnd: TimelineReloadPolicy // ߋ৽͠ͳ͍ public static let never: TimelineReloadPolicy // ࢦఆ࣌ؒʹߋ৽ public static func after(_ date: Date) -> TimelineReloadPolicy } // ΞϓϦଆ͔Βߋ৽Λଅ͢͜ͱ΋ WidgetCenter.shared.reloadAllTimelines() ࣮ࡍͷߋ৽λΠϛϯά͸ ࠷ऴతʹ04͕͍͍ײ͡ʹௐ੔͢ΔͷͰ஫ҙ
  24. ෳ਺΢ΟδΣοτ 8JEHFU#VOEMF 8JEHFUᶄ 8JEHFUᶃ *OUFOU&YUFOTJPO @main struct Bundle: WidgetBundle {

    @WidgetBundleBuilder var body: some Widget { Widget1() Widget2() } }
  25. ͍͞͝ʹ w ΢ΟδΣοτରԠ͍ͯ͜͠͏ʂ w Ͱ΋ΞϓϦຊମ΁ͷ༠ಋ΋େࣄʁʢϏδωεతʹʣ w ΄ͲΑ͍৘ใͷόϥϯε۩߹ΛݟۃΊͯ