Recall & Review
beginner
What is UIActivityViewController used for in iOS development?
UIActivityViewController is used to present a share sheet that lets users share content like text, images, or URLs with other apps or services.
Click to reveal answer
beginner
How do you initialize a UIActivityViewController with items to share?
You create it by passing an array of items (like strings or images) to the initializer: UIActivityViewController(activityItems: [items], applicationActivities: nil).
Click to reveal answer
intermediate
Why should you set the
popoverPresentationController?.sourceView on iPad when using UIActivityViewController?On iPad, the share sheet appears as a popover. Setting
sourceView tells iOS where to anchor the popover, preventing crashes and ensuring correct display.Click to reveal answer
intermediate
Can you customize the activities shown in the share sheet?
Yes, by providing custom UIActivity objects in the
applicationActivities parameter or excluding some built-in activities using excludedActivityTypes.Click to reveal answer
intermediate
What happens after the user completes or cancels sharing in UIActivityViewController?
You can handle completion with the
completionWithItemsHandler closure to know if the user shared, cancelled, or if there was an error.Click to reveal answer
What parameter do you pass to UIActivityViewController to specify what to share?
✗ Incorrect
The correct parameter is activityItems, which is an array of items to share.
Which property must be set on iPad to avoid a crash when presenting UIActivityViewController?
✗ Incorrect
On iPad, popoverPresentationController?.sourceView must be set to anchor the popover.
How do you exclude some activities from the share sheet?
✗ Incorrect
excludedActivityTypes is used to hide unwanted activities from the share sheet.
What type of data can you share using UIActivityViewController?
✗ Incorrect
UIActivityViewController supports sharing various data types including text, images, URLs, and custom objects.
Which closure lets you know if the user completed or cancelled sharing?
✗ Incorrect
completionWithItemsHandler is the closure called after the share sheet finishes.
Explain how to present a share sheet using UIActivityViewController in an iOS app.
Think about what you want to share and how to show the share sheet safely on all devices.
You got /3 concepts.
Describe how you can customize which sharing options appear in the share sheet.
Consider how to control the user experience by limiting or adding sharing choices.
You got /3 concepts.