Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Custom Group Activities

Custom Group Activities

61a68b2172503ecdf7a7f7757df56071?s=128

Tachibana Kaoru

June 23, 2021
Tweet

Transcript

  1. Custom Group Activities @TachibanaKaoru 2021/06/23 #potatotips #74

  2. ࣗݾ঺հ @TachibanaKaoru Freelance iOS Engineer ࠓ೥ͷWWDC͸ΧφμͰݟ͍ͯ·ͨ͠ɻ ࠓ೔͸·ͩؼࠃޙͷೋिִؒ཭ظؒதɻ

  3. Custom Group Activitiesͱ͸ FaceTimeͷηογϣϯΛ࢖ͬͯΞϓϦಠࣗͷ৘ใΛ΍ΓͱΓ͢Δ͜ͱ͕ Ͱ͖Δ࢓૊Έɻ αʔόʔΛ༻ҙͤͣʹήʔϜͷάϧʔϓରઓ΍άϧʔϓ࡞ۀͳͲΛ࣮૷ ͢Δ͜ͱ͕Ͱ͖Δɻ iOS15͔Βαϙʔτ

  4. None
  5. None
  6. None
  7. None
  8. How to implement Group Activities add entitlement (com.apple.developer.group-session) de fi

    ne activity model prepareForActivation activate join
  9. de fi ne activity model struct TextTogetherActivity: GroupActivity{ static let

    activityIdentifier = "org.toyship.characters.text" } extension TextTogetherActivity{ var metadata: GroupActivityMetadata{ var data = GroupActivityMetadata() data.type = .generic data.title = "character" data.fallbackURL = URL(string: "") return data } }
  10. prepareForActivation let myActivity = TextTogetherActivity() async { switch await myActivity.prepareForActivation()

    { case .activationDisabled: prepareStateLabel.text = "(disable)" case .activationPreferred: prepareStateLabel.text = "prepare OK" case .cancelled: prepareStateLabel.text = "cancelled" default: prepareStateLabel.text = "(unknown status)" } }
  11. activate let myActivity = TextTogetherActivity() myActivity.activate()

  12. join async{ for await session in TextTogetherActivity.sessions(){ switch session.state{ case

    GroupSession<TextTogetherActivity>.State.joined: break case GroupSession<TextTogetherActivity>.State.waiting: session.join() default: break } } }
  13. Group Activities Session FaceTime session Group Activities session

  14. Group Activities Session FaceTime session ActivityΛ ࡞ͬͯ activate ͢Δ Group

    Activities session FactTimeͷsession͕͋Δঢ়ଶͰactivateΛ͢ΔͱɺଞͷࢀՃ ऀʹԻͰ௨஌͞Ε·͢ɻ
  15. Group Activities Session FaceTime session Group Activities session join APIͰjoinΛݺͿલʹɺsystem

    UIͰɺ ʮΞϓϦ໊ʯʹࢀՃ͠·͔͢ʁͱ͍ ͏μΠΞϩάʹOK͢Δඞཁ͋Γɻ
  16. System UI Dialog Here!

  17. Group Activities Session FaceTime session Group Activities session join

  18. Group Activities Session FaceTime session Group Activities session

  19. Session timeline prepareForActivation prepareForActivation activate join session owner (system UI

    Ͱ OK)
  20. How to send and receive messages de fi ne message

    model send message receive message
  21. de fi ne message model struct ShareText: Codable{ let id:

    UUID var name: String var position: CGPoint = CGPoint(x: 0, y: 0) var red: CGFloat = 1.0 var green: CGFloat = 1.0 var blue: CGFloat = 1.0 var alpha: CGFloat = 1.0 }
  22. send message let messenger = GroupSessionMessenger(session: session) let newData =

    ShareText(id: UUID(), name: "Hello") messenger.send(newData, completion: {error in // check error })
  23. receive message async{ for await session in TextTogetherActivity.sessions(){ let messenger

    = GroupSessionMessenger(session: session) let task: Task.Handle = detach { [weak self] in for await (message, _ ) in messenger.messages(of: ShareText.self){ await self?.checkReceivedText(message) } } tasks.insert(task) } }
  24. Session information ηογϣϯʹࢀՃ͍ͯ͠Δਓ਺͸֬ೝՄೳ ͨͩ͠ɺਓ਺૿ݮͷ௨஌ͳͲ͸ൃੜ͠ͳ͍ ηογϣϯʹࢀՃ͍ͯ͠Δਓͷ৘ใʢFaceTimeΞΧ΢ϯτ໊ͳͲʣ͸औಘͰ ͖ͳ͍ɻ ૹड৴ϝοηʔδʹ͸ɺࢀՃऀͷIDʢಗ໊IDʣ͸෇Ճ͞Ε͍ͯΔ͕ɺͦΕҎ্ ͷ৘ใ͸ͳ͍ͨΊɺඞཁͳ৔߹ʹ͸ɺૹड৴ϝοηʔδʹؚΊͨ΄͏͕Α͍ɻ

  25. Pros and Cons ηογϣϯΛ؅ཧ͢Δඞཁ͕ʢ͋·Γʣͳ͍ αʔόʔߏஙͷඞཁ͕ͳ͍

  26. Pros and Cons FaceTimeͷΞΧ΢ϯτ͕ඞཁ iOS15͕ඞཁ ࢀՃऀ΍୺຤ͷ৘ใ͕खʹೖΒͳ͍

  27. delay on Group Activities ݱ࣌఺Ͱ͸ɺηογϣϯΛషΔͷ·Ͱ͕͔͔࣌ؒΔ͜ͱ͕͋Δ ϝοηʔδૹड৴࣌ͷ஗Ԇ͸΄ͱΜͲײ͡ͳ͍͕ɺࢀՃਓ਺΍ωοτ ϫʔΫ؀ڥʹେ͖͘ґଘ͢ΔͱࢥΘΕΔ FaceTimeͷάϧʔϓ௨࿩͸࠷େ32ਓ͕ͩɺGroup ActivitiesͰԿਓ·Ͱ αϙʔτ͢Δͷ͔͸ෆ໌ɻ

  28. Environment Tips ಉ͡FaceTimeΞΧ΢ϯτʴෳ਺ͷσόΠεͰFaceTime SessionΛ࡞ͬͯ ΋͏·͍͔͘ͳ͍৔߹͕͋Δɻ WWDCͷϓϨθϯͰ͸͏·͍͍ͬͯ͘ΔΑ͏ʹݟ͑·͕ͨ͠ɺखݩͰ ͸͏·͍͖͘·ͤΜͰͨ͠ɻ ։ൃ༻ʹผFaceTimeΞΧ΢ϯτΛ༻ҙͨ͠ํ͕҆શɻ

  29. Environment Tips Group ActivitiesରԠΞϓϦͷTestFlightͰͷ഑෍͸ɺݱ࣌఺Ͱ͸αϙʔτ ͞Ε͍ͯ·ͤΜɻ Group ActivitiesͷΞϓϦͰ͸ɺGroupAcͰඞཁͳ com.apple.developer.group-sessionͷcode signing entitlement͕ඞཁͰ

    ͕͢ɺͦΕΛద༻͢ΔͱiTunes connectͰͷΞοϓϩʔυ࣌ʹΤϥʔ͕ ൃੜ͠·͢ɻ
  30. ·ͱΊ Custom Activities͸ɺάϧʔϓηογϣϯΛ؆୯ʹ࣮૷Ͱ͖Δͷ͕ັྗ తɻ ͨͩ͠ɺ։ൃ؀ڥΛ༻ҙ͢Δͷ͕গ͠େม͔΋ɻ iOS15୺຤͕ෳ਺͋ͬͨΒࢼͯ͠Έ·͠ΐ͏ɻ