A type that tells the system which scene to associate with an incoming
group activity.
Use a ``SceneAssociationBehavior`` type to match SharePlay activities to
your app’s scenes. The static accessors of this type offer different
scene-selection behaviors. For example, you can match each activity type
to a specific scene, match scenes dynamically based on the contents of
the activity, or prevent matching altogether. Select one of these behaviors
and assign the related type to your ``GroupActivity`` object’s metadata.
On some platforms, the system adds a custom indicator to a scene to let
people know that SharePlay is active.
Add activation conditions to your SwiftUI or UIKit scenes to tell the
system which activities they support. An activation condition is a custom
string that identifies one of your app’s supported activities. You add
these strings to your scenes to direct different types of external events
to them. In SwiftUI, specify the activation conditions for a scene using
the <doc://com.apple.documentation/documentation/swiftui/scene/handlesexternalevents(matching:)>
modifier. In the following example, the scene handles two app-related
activities, including a group activity.
```
let activationConditions : Set = ["com.mycompany.MySharePlayActivity",
"com.mycompany.MyUserActivity"]
var body: some Scene {
WindowGroup {
ContentView()
}
.handlesExternalEvents(matching: activationConditions)
```
To handle the same activation condition in a UIKit app, add rules to the
<doc://com.apple.documentation/documentation/uikit/uiscene/activationconditions>
property of your <doc://com.apple.documentation/documentation/uikit/uiscene> object.
Assign these rules in the <doc://com.apple.documentation/documentation/uikit/uiscenedelegate/scene(_:willconnectto:options:)>
method when you first configure your scene for use. Use the
<doc://com.apple.documentation/documentation/uikit/uisceneactivationconditions/preferstoactivatefortargetcontentidentifierpredicate>
property when the scene is the preferred choice for handling the action.
The following example shows how to configure a scene to handle two
app-related activities, including a group activity.
```
let activationConditions = ["com.example.MySharePlayActivity", "com.example.MyUserActivity"]
func scene(_ scene: UIScene,
willConnectTo session: UISceneSession,
options connectionOptions: UIScene.ConnectionOptions) {
// Specify the activities that this scene prefers to handle.
scene.activationConditions.prefersToActivateForTargetContentIdentifierPredicate
= NSPredicate(format: "self in %@", activationConditions)
}
```
Members (3)
get · iOS 17.0+
none
TypeScript
static get none(): SceneAssociationBehavior
Swift declaration
static let none: SceneAssociationBehavior
A behavior that doesn't match any scenes to the activity.
Choose this option when you don’t want the system to associate one
of your scenes with the SharePlay activity. You might choose this
option when you handle an activity separately from your app’s scenes.
A behavior that matches the activity to a scene using a custom
string that you supply.
- Parameters:
- contentIdentifier: The string to compare against the scene's defined
activation conditions. This string has a similar purpose to the
<doc://com.apple.documentation/documentation/foundation/nsuseractivity/targetcontentidentifier>
of an <doc://com.apple.documentation/documentation/foundation/nsuseractivity> object.
- Returns: A ``SceneAssociationBehavior`` type with the specified identifier.
Use this option when you want more control over the scene-selection
process for your ``GroupActivity`` object. You might use it to direct
the activity to different scenes, or to direct the activity to a specific
instance of a scene. For example, a drawing app might direct the activity
to the specific canvas someone wants to share, and not to
a new or unrelated canvas that uses the same scene type.
get · iOS 17.0+
default
TypeScript
static get default(): SceneAssociationBehavior
Swift declaration
static let `default`: SceneAssociationBehavior
A behavior that matches the activity to a scene using the
identifier of your activity object.
With this option, the system uses the string in the ``GroupActivity/activityIdentifier-6jlef``
property of your ``GroupActivity`` object to locate an appropriate scene.
Choose this option if your app has only one scene, or if you always use
the same scene to display the intended activity.