0
0
iOS Swiftmobile~20 mins

Share sheet (UIActivityViewController) in iOS Swift - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Share Sheet Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2: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)
AThe share sheet shows only the default iOS apps like Messages and Mail, excluding third-party apps.
BThe share sheet shows all available sharing options including Messages, Mail, and social media apps installed.
CThe share sheet shows no options because excludedActivityTypes is nil.
DThe app crashes because excludedActivityTypes must be set before presenting.
Attempts:
2 left
💡 Hint
Think about what happens if you don't limit or exclude any sharing options.
📝 Syntax
intermediate
2: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?
A
activityVC.excludedActivityTypes = [.airDrop]
present(activityVC, animated: true)
B
activityVC.excludedActivityTypes = .airDrop
present(activityVC, animated: true)
C
activityVC.excludedActivityTypes = ["airDrop"]
present(activityVC, animated: true)
D
activityVC.excludedActivityTypes = [UIActivity.ActivityType.airDrop]
present(activityVC, animated: true)
Attempts:
2 left
💡 Hint
Check the correct enum type and syntax for excludedActivityTypes.
lifecycle
advanced
2: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)
AThe share sheet appears but with a warning in the console only.
BThe share sheet appears centered on the screen without any issues.
CThe app crashes with a runtime exception about missing popover sourceView.
DThe share sheet does not appear and the app freezes.
Attempts:
2 left
💡 Hint
iPad requires a popover anchor for modal presentations like UIActivityViewController.
navigation
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)
ASet activityVC.completionWithItemsHandler to a closure that calls dismiss(animated: true).
BSet activityVC.delegate = self and implement activityViewControllerDidFinish to dismiss.
CCall dismiss(animated: true) immediately after present(activityVC, animated: true).
DUse NotificationCenter to listen for UIActivityViewControllerDidFinish notification and dismiss.
Attempts:
2 left
💡 Hint
UIActivityViewController has a completion handler property for this purpose.
🧠 Conceptual
expert
3: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?
AUse file URLs pointing to saved images instead of UIImage objects to avoid memory and performance issues.
BAlways convert UIImages to Data before sharing to ensure compatibility with all apps.
CSharing UIImages directly is recommended for best performance and no issues exist on iOS 16+.
DWrap UIImages inside a custom UIActivity subclass to fix sharing problems on iOS 16+.
Attempts:
2 left
💡 Hint
Think about how large images affect memory and how file URLs can help.