0
0
iOS Swiftmobile~10 mins

Share sheet (UIActivityViewController) in iOS Swift - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a share sheet with a text message.

iOS Swift
let textToShare = "Hello from my app!"
let activityVC = UIActivityViewController(activityItems: [[1]], applicationActivities: nil)
Drag options to blanks, or click blank then click option'
Anil
Bself
CtextToShare
Dview
Attempts:
3 left
💡 Hint
Common Mistakes
Passing self or view instead of the text variable.
Not putting the item inside an array.
2fill in blank
medium

Complete the code to present the share sheet from the current view controller.

iOS Swift
present(activityVC, animated: [1], completion: nil)
Drag options to blanks, or click blank then click option'
Atrue
B0
Cnil
Dfalse
Attempts:
3 left
💡 Hint
Common Mistakes
Passing false disables animation and is less user-friendly.
Passing nil or 0 causes errors.
3fill in blank
hard

Fix the error in the code to avoid a crash on iPad by setting the popoverPresentationController's sourceView.

iOS Swift
if let popover = activityVC.popoverPresentationController {
    popover.sourceView = [1]
}
Drag options to blanks, or click blank then click option'
AUIApplication.shared
Bnil
CactivityVC
Dself.view
Attempts:
3 left
💡 Hint
Common Mistakes
Setting sourceView to nil causes a crash on iPad.
Using activityVC or UIApplication.shared is incorrect.
4fill in blank
hard

Fill both blanks to share an image named "photo.png" from the app bundle.

iOS Swift
if let image = UIImage(named: [1]) {
    let activityVC = UIActivityViewController(activityItems: [[2]], applicationActivities: nil)
}
Drag options to blanks, or click blank then click option'
A"photo.png"
B"photo"
Cimage
Dself
Attempts:
3 left
💡 Hint
Common Mistakes
Including the file extension in the image name.
Passing the string instead of the image variable to activityItems.
5fill in blank
hard

Fill all three blanks to share a URL and exclude the AirDrop activity from the share sheet.

iOS Swift
if let url = URL(string: [1]) {
    let activityVC = UIActivityViewController(activityItems: [url], applicationActivities: nil)
    activityVC.excludedActivityTypes = [[2]]
    present(activityVC, animated: [3], completion: nil)
}
Drag options to blanks, or click blank then click option'
A"https://example.com"
B.airDrop
Ctrue
Dfalse
Attempts:
3 left
💡 Hint
Common Mistakes
Not quoting the URL string.
Using wrong activity type to exclude.
Passing false to animated parameter.