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

Custom Group Activities

Custom Group Activities

Tachibana Kaoru

June 23, 2021
Tweet

More Decks by Tachibana Kaoru

Other Decks in Technology

Transcript

  1. Custom Group Activities
    @TachibanaKaoru


    2021/06/23 #potatotips #74

    View full-size slide

  2. ࣗݾ঺հ
    @TachibanaKaoru


    Freelance iOS Engineer


    ࠓ೥ͷWWDC͸ΧφμͰݟ͍ͯ·ͨ͠ɻ


    ࠓ೔͸·ͩؼࠃޙͷೋिִؒ཭ظؒதɻ

    View full-size slide

  3. Custom Group Activitiesͱ͸
    FaceTimeͷηογϣϯΛ࢖ͬͯΞϓϦಠࣗͷ৘ใΛ΍ΓͱΓ͢Δ͜ͱ͕
    Ͱ͖Δ࢓૊Έɻ


    αʔόʔΛ༻ҙͤͣʹήʔϜͷάϧʔϓରઓ΍άϧʔϓ࡞ۀͳͲΛ࣮૷
    ͢Δ͜ͱ͕Ͱ͖Δɻ


    iOS15͔Βαϙʔτ

    View full-size slide

  4. How to implement Group Activities
    add entitlement (com.apple.developer.group-session)


    de
    fi
    ne activity model


    prepareForActivation


    activate


    join

    View full-size slide

  5. 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


    }


    }

    View full-size slide

  6. 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)"




    }


    }


    View full-size slide

  7. activate
    let myActivity = TextTogetherActivity()




    myActivity.activate()


    View full-size slide

  8. join
    async{


    for await session in TextTogetherActivity.sessions(){




    switch session.state{


    case GroupSession.State.joined:


    break


    case GroupSession.State.waiting:


    session.join()


    default:


    break


    }




    }


    }

    View full-size slide

  9. Group Activities Session
    FaceTime session
    Group Activities


    session

    View full-size slide

  10. Group Activities Session
    FaceTime session
    ActivityΛ
    ࡞ͬͯ


    activate


    ͢Δ
    Group Activities


    session
    FactTimeͷsession͕͋Δঢ়ଶͰactivateΛ͢ΔͱɺଞͷࢀՃ
    ऀʹԻͰ௨஌͞Ε·͢ɻ

    View full-size slide

  11. Group Activities Session
    FaceTime session
    Group Activities


    session
    join
    APIͰjoinΛݺͿલʹɺsystem UIͰɺ
    ʮΞϓϦ໊ʯʹࢀՃ͠·͔͢ʁͱ͍
    ͏μΠΞϩάʹOK͢Δඞཁ͋Γɻ

    View full-size slide

  12. System UI Dialog
    Here!

    View full-size slide

  13. Group Activities Session
    FaceTime session
    Group Activities


    session
    join

    View full-size slide

  14. Group Activities Session
    FaceTime session
    Group Activities


    session

    View full-size slide

  15. Session timeline
    prepareForActivation prepareForActivation
    activate
    join
    session owner
    (system UI Ͱ OK)

    View full-size slide

  16. How to send and receive messages
    de
    fi
    ne message model


    send message


    receive message

    View full-size slide

  17. 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


    }


    View full-size slide

  18. send message
    let messenger = GroupSessionMessenger(session: session)


    let newData = ShareText(id: UUID(), name: "Hello")




    messenger.send(newData,


    completion: {error in


    // check error


    })


    View full-size slide

  19. 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)




    }


    }


    View full-size slide

  20. Session information
    ηογϣϯʹࢀՃ͍ͯ͠Δਓ਺͸֬ೝՄೳ


    ͨͩ͠ɺਓ਺૿ݮͷ௨஌ͳͲ͸ൃੜ͠ͳ͍


    ηογϣϯʹࢀՃ͍ͯ͠Δਓͷ৘ใʢFaceTimeΞΧ΢ϯτ໊ͳͲʣ͸औಘͰ
    ͖ͳ͍ɻ


    ૹड৴ϝοηʔδʹ͸ɺࢀՃऀͷIDʢಗ໊IDʣ͸෇Ճ͞Ε͍ͯΔ͕ɺͦΕҎ্
    ͷ৘ใ͸ͳ͍ͨΊɺඞཁͳ৔߹ʹ͸ɺૹड৴ϝοηʔδʹؚΊͨ΄͏͕Α͍ɻ

    View full-size slide

  21. Pros and Cons
    ηογϣϯΛ؅ཧ͢Δඞཁ͕ʢ͋·Γʣͳ͍


    αʔόʔߏஙͷඞཁ͕ͳ͍

    View full-size slide

  22. Pros and Cons
    FaceTimeͷΞΧ΢ϯτ͕ඞཁ


    iOS15͕ඞཁ


    ࢀՃऀ΍୺຤ͷ৘ใ͕खʹೖΒͳ͍

    View full-size slide

  23. delay on Group Activities
    ݱ࣌఺Ͱ͸ɺηογϣϯΛషΔͷ·Ͱ͕͔͔࣌ؒΔ͜ͱ͕͋Δ


    ϝοηʔδૹड৴࣌ͷ஗Ԇ͸΄ͱΜͲײ͡ͳ͍͕ɺࢀՃਓ਺΍ωοτ
    ϫʔΫ؀ڥʹେ͖͘ґଘ͢ΔͱࢥΘΕΔ


    FaceTimeͷάϧʔϓ௨࿩͸࠷େ32ਓ͕ͩɺGroup ActivitiesͰԿਓ·Ͱ
    αϙʔτ͢Δͷ͔͸ෆ໌ɻ

    View full-size slide

  24. Environment Tips
    ಉ͡FaceTimeΞΧ΢ϯτʴෳ਺ͷσόΠεͰFaceTime SessionΛ࡞ͬͯ
    ΋͏·͍͔͘ͳ͍৔߹͕͋Δɻ


    WWDCͷϓϨθϯͰ͸͏·͍͍ͬͯ͘ΔΑ͏ʹݟ͑·͕ͨ͠ɺखݩͰ
    ͸͏·͍͖͘·ͤΜͰͨ͠ɻ


    ։ൃ༻ʹผFaceTimeΞΧ΢ϯτΛ༻ҙͨ͠ํ͕҆શɻ

    View full-size slide

  25. Environment Tips
    Group ActivitiesରԠΞϓϦͷTestFlightͰͷ഑෍͸ɺݱ࣌఺Ͱ͸αϙʔτ
    ͞Ε͍ͯ·ͤΜɻ


    Group ActivitiesͷΞϓϦͰ͸ɺGroupAcͰඞཁͳ
    com.apple.developer.group-sessionͷcode signing entitlement͕ඞཁͰ
    ͕͢ɺͦΕΛద༻͢ΔͱiTunes connectͰͷΞοϓϩʔυ࣌ʹΤϥʔ͕
    ൃੜ͠·͢ɻ

    View full-size slide

  26. ·ͱΊ
    Custom Activities͸ɺάϧʔϓηογϣϯΛ؆୯ʹ࣮૷Ͱ͖Δͷ͕ັྗ
    తɻ


    ͨͩ͠ɺ։ൃ؀ڥΛ༻ҙ͢Δͷ͕গ͠େม͔΋ɻ


    iOS15୺຤͕ෳ਺͋ͬͨΒࢼͯ͠Έ·͠ΐ͏ɻ

    View full-size slide