Challenge - 5 Problems
Share Sheet Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2:00remaining
What happens when you present UIActivityViewController without excluding any activity types?
You create and present a UIActivityViewController with a text string to share, but you do not set any excludedActivityTypes. What will the user see?
iOS Swift
let textToShare = "Hello from my app!"
let activityVC = UIActivityViewController(activityItems: [textToShare], applicationActivities: nil)
present(activityVC, animated: true)Attempts:
2 left
💡 Hint
Think about what happens if you don't limit or exclude any sharing options.
✗ Incorrect
If you do not set excludedActivityTypes, the UIActivityViewController shows all available sharing options installed on the device, including third-party apps.
📝 Syntax
intermediate2:00remaining
Which code snippet correctly excludes the AirDrop option from the share sheet?
You want to present a UIActivityViewController but exclude the AirDrop option. Which code snippet does this correctly?
Attempts:
2 left
💡 Hint
Check the correct enum type and syntax for excludedActivityTypes.
✗ Incorrect
excludedActivityTypes expects an array of UIActivity.ActivityType values. The correct syntax uses the enum with the full type name.
❓ lifecycle
advanced2:00remaining
What happens if you present UIActivityViewController on iPad without setting popoverPresentationController sourceView?
You present a UIActivityViewController on an iPad but forget to set the popoverPresentationController's sourceView or barButtonItem. What is the expected behavior?
iOS Swift
let text = "Check this out!"
let activityVC = UIActivityViewController(activityItems: [text], applicationActivities: nil)
present(activityVC, animated: true)Attempts:
2 left
💡 Hint
iPad requires a popover anchor for modal presentations like UIActivityViewController.
✗ Incorrect
On iPad, UIActivityViewController must have its popoverPresentationController's sourceView or barButtonItem set, otherwise the app crashes at runtime.
advanced
2:00remaining
How to dismiss UIActivityViewController programmatically after sharing completes?
You want to dismiss the UIActivityViewController automatically after the user finishes sharing. Which approach correctly detects completion and dismisses it?
iOS Swift
let activityVC = UIActivityViewController(activityItems: ["Hello"], applicationActivities: nil)
// What to add here?
present(activityVC, animated: true)Attempts:
2 left
💡 Hint
UIActivityViewController has a completion handler property for this purpose.
✗ Incorrect
The completionWithItemsHandler closure is called when the user finishes or cancels sharing, allowing you to dismiss the controller programmatically.
🧠 Conceptual
expert3:00remaining
Why should you avoid sharing UIImages directly in UIActivityViewController on iOS 16+?
Starting with iOS 16, sharing UIImages directly in UIActivityViewController can cause issues. What is the recommended approach and why?
Attempts:
2 left
💡 Hint
Think about how large images affect memory and how file URLs can help.
✗ Incorrect
Sharing large UIImages directly can cause memory pressure and crashes. Using file URLs to saved images is more efficient and recommended on iOS 16 and later.