I created a game in Sprite Kit using swift and I am at the point where I would like to implement a 'share' button, where when you press it the Activity View Controller pops up and let you decide how you would like to share something.
In the share, a screenshot needs to be taken and a standard text needs to be added. So far I came up with this next code, however I need to call this in a SKScene. This code only allows me to call it while I'm in a ViewController. Any help would be much appreciated.
let textToShare = "Swift is awesome! Check out this website about it!"
if let myWebsite = NSURL(string: "http://www.codingexplorer.com/")
{
let objectsToShare = [textToShare, myWebsite]
let activityVC = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)
//New Excluded Activities Code
activityVC.excludedActivityTypes = [UIActivityTypeAirDrop, UIActivityTypeAddToReadingList]
//
self.presentViewController(activityVC, animated: true, completion: nil)
}
As UIActivityViewController is called on ViewController you have to create a method in ViewController presenting the UIActivityViewController. Then on the scene call this method.
Related
Currently I can send custom type Data from one device to another via email but I'm now trying to use AirDrop with my incomplete code below . I think the problem is I need to add my custom file type in the excludedActivityTypes but not sure how ??
I believe I need to add my document type and exported type identifier but not sure how ? (I've added screen shots below of my declared custom file)
enter code here let dataToShare: NSMutableArray = self.quizDataBase
let controller = UIActivityViewController(activityItems: [dataToShare], applicationActivities: nil)
controller.excludedActivityTypes = nil
self.present(controller, animated: true, completion: nil)
In an app I'm building, see screenshot, I want to make use of the sharing option. The user can make lists and reorder the rows. I would than like to be able to share the complete TableView but I don't know how to implement the code in the UIActivityViewController. How do I get the full TableView output as an activityItem?
The code I'm using.
#IBAction func shareButton(_ sender: Any) {
let activityVC = UIActivityViewController(activityItems: [how to get the TableView output here?], applicationActivities: nil)
self.present(activityVC, animated: true, completion: nil)
}
Image: app-screenshot
I just started in this fantastic Swift-world and are proud what I made by now, but I really need a helping hand on this one! Thanks in advance!
I'd like to be able to AirDrop a text file and an image at the same time using the UIActivityViewController. The code below works fine to send both file types via iMessage or eMail, but it fails when I try to use AirDrop. The code works fine for AirDropping 2 images or 2 text files, but not for one of each.
#IBAction func shareImage(_ sender: UIButton)
{
// can't seem to AirDrop a mixture of file types. ie. can send 2 images, or 2 data files, but not an image and a data file
let fileToSend: NSURL = NSURL(fileURLWithPath: dataFile!)
let image = imageView.image!
let objectsToShare = [fileToSend, image] as [Any]
let controller = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)
controller.excludedActivityTypes = [UIActivityType.postToFacebook, UIActivityType.postToTwitter, UIActivityType.postToWeibo, UIActivityType.print, UIActivityType.copyToPasteboard, UIActivityType.assignToContact, UIActivityType.saveToCameraRoll, UIActivityType.postToFlickr, UIActivityType.postToTencentWeibo]
self.present(controller, animated: true, completion: nil)
}
AirDrop to an iOS device does not support sending multiple different types, but sending to a mac does. Until Apple changes that there is no code change that you can do to "fix" this.
I'm looking for a way to show a dynamically show a popup within a view controller when a user selects a particular word within a label.
For example
Click here for a link, click here for another link
The label text is pulled from a database so is dynamically added based on the content a user is viewing, i was hoping to use the URL schemes within Swift to show the correct popup depending on what a user selected, but when i add the following within app delegate the popup shows within a separate view controller and not as a pop up view controller.
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let navVC = storyboard.instantiateViewControllerWithIdentifier("glossaryPopupID") as! UIViewController
self.window?.rootViewController?.presentViewController(navVC, animated: true, completion: nil)
return true
When the popup is close the screen behind is now blank rather than showing the original view controller.
SO my question is, whether this is the best way to achieve this as im not sure its best practice to used URL links within an app to link to other parts of the same app, or is there another way i am missing.
Think i have resolved this now, using the following;
let storyboard = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("test") as! ViewController
let popOverVC = UIStoryboard(name:"Main", bundle: nil).instantiateViewControllerWithIdentifier("sbPopUpID") as! PopUpViewController
storyboard.addChildViewController(popOverVC)
popOverVC.view.frame = storyboard.view.frame
storyboard.view.addSubview(popOverVC.view)
popOverVC.didMoveToParentViewController(storyboard)
self.window?.rootViewController?.presentViewController(storyboard, animated: true, completion: nil)
Hey I am developing an app for the version iOS7 and above, where I have to share a content via mail or message. I use the following code
let textToShare = "Just click the following link to view "
let urlToShare = NSURL(string: "croding.com://crodid/crodname")
let objectsToShare = [textToShare, urlToShare]
let activityVC = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)
self.presentViewController(activityVC, animated: true, completion: nil)
I have added the croding.com in plist. Its working fine (open our app from mail exactly what I want) only if the app is installed already otherwise this thing is just a text instead of link. I need to show it as link even app is not installed.
croding.com://crodid/crodname