I tried including UIActivityViewController
in my Xcode project (swift), but as I ran the app in the simulator, the UIActivityViewController
didn't include any options of sharing the content (I thought once you include it you can get all the options such as "share on Facebook" and "share on Twitter"
Here's my code:
import UIKit
class ViewController: UIViewController {
@IBAction func shareTextButton(_ sender: UIButton) {
let text = "This is some text that I want to share."
let textToShare = [ text ]
let activityViewController = UIActivityViewController(activityItems: textToShare, applicationActivities: nil)
activityViewController.popoverPresentationController?.sourceView = self.view // so that iPads won't crash
self.present(activityViewController, animated: true, completion: nil)
}
@IBAction func shareImageButton(_ sender: UIButton) {
let image = UIImage(named: "Portrait")
let imageToShare = [ image! ]
let activityViewController = UIActivityViewController(activityItems: imageToShare, applicationActivities: nil)
activityViewController.popoverPresentationController?.sourceView = self.view // so that iPads won't crash
self.present(activityViewController, animated: true, completion: nil)
}
}
Here's what appeared in the debug console:
2017-04-05 18:32:34.902268-0700 AA[26541:4024236] [MC] System group container for systemgroup.com.apple.configurationprofiles path is /Users/cuiboy/Library/Developer/CoreSimulator/Devices/55F2DE69-127A-4F0E-871F-4E431586D8AF/data/Containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles objc[26541]: Class PLBuildVersion is implemented in both /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/AssetsLibraryServices.framework/AssetsLibraryServices (0x11a182cc0) and /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/PhotoLibraryServices.framework/PhotoLibraryServices (0x119f996f0). One of the two will be used. Which one is undefined. 2017-04-05 18:32:35.141398-0700 AA[26541:4024236] [core] SLComposeViewController extensionIdentifierForActivityType: com.apple.UIKit.activity.PostToTwitter => com.apple.share.Twitter.post 2017-04-05 18:32:35.141532-0700 AA[26541:4024236] [core] SLComposeViewController extensionIdentifierForActivityType: com.apple.UIKit.activity.PostToFacebook => com.apple.share.Facebook.post 2017-04-05 18:32:35.141629-0700 AA[26541:4024236] [core] SLComposeViewController extensionIdentifierForActivityType: com.apple.UIKit.activity.PostToWeibo => com.apple.share.SinaWeibo.post 2017-04-05 18:32:35.141728-0700 AA[26541:4024236] [core] SLComposeViewController extensionIdentifierForActivityType: com.apple.UIKit.activity.TencentWeibo => com.apple.share.TencentWeibo.post 2017-04-05 18:32:35.141801-0700 AA[26541:4024236] [core] SLComposeViewController extensionIdentifierForActivityType: com.apple.UIKit.activity.PostToFlickr => com.apple.share.Flickr.post 2017-04-05 18:32:35.141904-0700 AA[26541:4024236] [core] SLComposeViewController extensionIdentifierForActivityType: com.apple.UIKit.activity.PostToVimeo => com.apple.share.Vimeo.post 2017-04-05 18:32:35.325040-0700 AA[26541:4024236] [MC] Reading from private effective user settings.
Does anybody know what is wrong? What can I do to make Facebook and twitter and other social media options appear in the activity view controller? Thanks