How do I code a share button into my SpriteKit Scene? I've seen tutorials on how to make it however this is in the Main.storyboard and ViewController.swift, I'm coding it in my MenuScene.swift (Cocoa Touch Class) and displaying it in MenuScene.sks (SpriteKit Scene). I am using Swift 4 and the latest version of Xcode (9.4.1), my application is for iOS 9 and above.
Thanks in advance!
This code will bring up an activity view and will let you share whatever you want with it.
if var top = scene?.view?.window?.rootViewController {
while let presentedViewController = top.presentedViewController {
top = presentedViewController
}
let activityVC = UIActivityViewController(activityItems: ["This is an array of items that will be shared. Including Images, Numbers, and text (like this)"], applicationActivities: nil)
activityVC.popoverPresentationController?.sourceView = view
top.present(activityVC, animated: true, completion: nil)
}
Of course, it will need to be called in the touchesBegan
method or a function. To share something, you will need to put it into the array that is in activityVC
.
This isn't a share button, this is just the code that is used to share something to another app. You need to put it into a function or in touchesBegan
and call it separately whenever you want to share something.