When i open an attachment from iPhone or iPad mail application, there is a popup that can transfert the file to a third party application.
This iOS popup is called UIActivityViewController.
I wand to add my own iOS application (written in swift) in this popup and i do not know how to do...
Thanks
I believe you are asking about two separate things.
UIActivityViewController:
Here's my code in my app.
let vc = UIActivityViewController(activityItems: [shareImage], applicationActivities: [])
vc.excludedActivityTypes = [
UIActivityType.airDrop,
UIActivityType.assignToContact,
UIActivityType.addToReadingList,
//UIActivityType.copyToPasteboard,
//UIActivityType.mail,
//UIActivityType.message,
//UIActivityType.openInIBooks,
//UIActivityType.postToFacebook,
//UIActivityType.postToFlickr,
UIActivityType.postToTencentWeibo,
//UIActivityType.postToTwitter,
UIActivityType.postToVimeo,
UIActivityType.postToWeibo,
UIActivityType.print,
//UIActivityType.saveToCameraRoll
]
present(vc,
animated: true,
completion: nil)
vc.popoverPresentationController?.sourceView = self.view
vc.completionWithItemsHandler = {(activity, success, items, error) in
}
Pay attention to the excludedActiviyTypes code. My app is an image effect app, so I commented out the things I wish to have in the popup - Weibo, print, assignToContact, ReadingList, Vimeo, and TencentWeibo. Here's the thing - I kept the full list of activities for quick reference. (I've never found it on ADC and end up getting it by using code complete.)
UIActivityType is an extended struct, so if you want to go the route of using it this way I think you'll have to (1) subclass UIActivityViewController, (2) write your own extension to UIActivityType, and (3) provide any/all code needed to use a service that isn't listed above.
A Document Provider is what I think you are looking for. Either that, or Universal - sometimes called Deep - Linking. (The links are to Apple documentation for using each.)
I've obviously used UIActivityiewController, but haven't (yet) had any need to these other two.
If you have questions about setting up a UIActivityViewController, post them in the comments. If someone else has a way to "extend" it in any way other than I described, let me know and I'll remove this answer.
Related
I am using the following code to share text using iOS sharing extension (UIActivityViewController).
let vc = UIActivityViewController(activityItems: ["File URL"], applicationActivities: [])
presentViewController(vc, animated: true, completion: nil)
It shows a popup to share using text sharing applications like following:
But, I want the sharing app portion in my view into a page control like below:
How can I do this? If there is any alternative way to achieve this requirement, kindly suggest.
i want share the image on Facebook in iWatch kit now problem occur in one line need help
if SLComposeViewController.isAvailableForServiceType(SLServiceTypeTwitter) { var twitterSheet:SLComposeViewController = SLComposeViewController(forServiceType: SLServiceTypeTwitter)
twitterSheet.setInitialText("Share on Twitter")
self.presentViewController(twitterSheet, animated: true, completion: nil)
}
Now problem in last line code the error is this classname does not have a member name presentViewController
There's a few issues here:
WatchKit does not include the Social framework.
WKInterfaceController does not include the method presentViewController.
You may want to look into using Handoff to share the item from the user's phone, instead.
I Made a game where the player can share its highscore with an UIActivityviewcontroller. But when pressed share with facebook for example, there comes a screen where the player can edit the text that I have set, So if I set level 9, the player can change it self to level 120.. How can I avoid this?
The piece of code I am using for the sharing:
let text = "I made it to level /(level)!"
let actviewcon = UIActivityViewController(activityItems: [text], applicationActivities: nil)
self.presentViewController(actviewcon, animated: true, completion: nil)
If you're going to use UIActivityViewController and permit a built-in activity like Facebook, you cannot alter or prevent the user's interaction with that activity's built-in interface.
So, if you don't like that, and you want to allow the user to post to Facebook, you would need to provide your own interface for doing that. You can post directly to Facebook yourself on the user's behalf thanks to the Accounts framework which lets you employ the user's credentials without seeing them.
I saw that it's possible — iBooks application does it.
Is it any way to do it?
I wrote a category to support image for UIMenuItem. It's based on method swizzling, but should be safe in most cases.
https://github.com/cxa/UIMenuItem-CXAImageSupport
There is nothing in the current official API do that. UIMenuItem can only be initialised with -initWithTitle:action:
I suspect that Apple either using a private API or have implemented a custom control. Probably the former.
Asked previously here
Check Emoji & Symbols, perhaps it will fit to your purpose.
Go to your Xcode Menu -> Edit -> Emoji & Symbols.
Ex.:
let menuItemYes = UIMenuItem(title: "✅", action: "doSomething")
Good luck!
I saw that it's possible — iBooks application does it.
Is it any way to do it?
I wrote a category to support image for UIMenuItem. It's based on method swizzling, but should be safe in most cases.
https://github.com/cxa/UIMenuItem-CXAImageSupport
There is nothing in the current official API do that. UIMenuItem can only be initialised with -initWithTitle:action:
I suspect that Apple either using a private API or have implemented a custom control. Probably the former.
Asked previously here
Check Emoji & Symbols, perhaps it will fit to your purpose.
Go to your Xcode Menu -> Edit -> Emoji & Symbols.
Ex.:
let menuItemYes = UIMenuItem(title: "✅", action: "doSomething")
Good luck!