Why Share Extension is not working on iOS 13? - ios

I was using a Share extension in my app in order to import audio files and it was working on iOS12. Now in iOS 13 is not working anymore, when I press the share button my app doesn't appear in the share sheet.
I think that maybe something has changed in the plist or similar but I coudn't find any information.
Does anyone have the same problem?
NB: I don't wanna use the copy - paste strategies, only the share extension.

Try this for iOS 13
DispatchQueue.main.async {
let activityItem = URL.init(fileURLWithPath: Bundle.main.path(forResource: "audio", ofType: "mp3")!)
let activityVC = UIActivityViewController(activityItems: [activityItem],applicationActivities: nil)
activityVC.popoverPresentationController?.sourceView = self.view
self.present(activityVC, animated: true, completion: nil)
}

For IOS 13 you Should add below code inside your open url method.
UISceneOpenExternalURLOptions * options = [[UISceneOpenExternalURLOptions alloc] init];
options.universalLinksOnly = false;

Related

How can I find custom UTIs App support in iOS?

I'm developing a custom UTI like "com.xyz".
All the apps supporting this UTI may be shown in the UIActivityViewController.
Code snippet:
let extensionItem = NSExtensionItem()
let data = NSItemProvider.init(item: nil, typeIdentifier: "com.xyz")
extensionItem.attachments = [data]
let activity = UIActivityViewController(
activityItems: [extensionItem],
applicationActivities: nil
)
present(activity, animated: true, completion: nil)
In order to have a better user experience, I would like to check if the iOS device has any App supporting "com.xyz" before presenting the UIActivityViewController.
Just like check URL:
UIApplication.shared.canOpenURL(URL(string: urlStr)!)
Otherwise the user may see an empty UIActivityViewController without any app.
As I know, there is an ActivityNotFoundException could be try and catch to handle the app not found situation in Android.
Does iOS support something like ActivityNotFoundException?
THANKS! 🙏

UIActivityViewController excludedActivityTypes not work

I want to exclude Weibo and WeChat, and set the following code:
let av = UIActivityViewController(activityItems: items, applicationActivities:nil)
av.excludedActivityTypes = [.postToWeibo, .postToTencentWeibo]
self.present(av, animated: true)
No matter what I did, the two apps still show up on UIActivityViewController. But excluding mail and copyToPasteboard are both work
av.excludedActivityTypes = [.postToWeibo, .postToTencentWeibo, .copyToPasteboard, .mail]
Any other way to exclude them? Thanks

Add frequently used app for fast sharing swift

I am working on a sharing functionality where I have achieved the basic sharing part and is working perfectly. Below is the code for same
let message = "Download the app from the link below"
//Set the link to share.
if let link = NSURL(string: "http://yoururl.com") {
let objectsToShare = [message,link] as [Any]
let activityVC = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)
activityVC.excludedActivityTypes = [UIActivityType.airDrop, UIActivityType.addToReadingList]
self.present(activityVC, animated: true, completion: nil)
}
The above code is working great and gives the output as seen in the screenshot
What I want is to have an extra icon/option to share the content for the frequently used app.
for e.g. I use Whatsapp frequently so the share window should show WhatsApp icon somewhere besides "More".
any help will be highly appreciated. TIA
This can't be done because the share sheet is a library provided by apple and only the user can rearrange icons on their own!

FBSDKShareDialog not appearing in case of video share

I am working on a project where I need to share an image and a video together on Facebook, but facing undefined behaviour.
Issue: When I am trying to share a video using FBSDKShareMediaContent class (using below code), the FBSDKShareDialog is not appearing, but it appears when I share only an image.
My code:
let photo: FBSDKSharePhoto = FBSDKSharePhoto.init(image: imageToShare, userGenerated: true)
let vid: FBSDKShareVideo = FBSDKShareVideo.init(videoURL: URL(string:vidUrl!.path))
// FBSDKShareDialog not appearing in this case
let shareContent: FBSDKShareMediaContent = FBSDKShareMediaContent()
shareContent.media = [photo, vid]
/*
// FBSDKShareDialog appearing
let shareContent: FBSDKShareMediaContent = FBSDKShareMediaContent()
shareContent.media = [photo] */
FBSDKShareDialog.show(from: self.getCurrentViewController(), with: shareContent, delegate: nil)
Video URL: file:///var/mobile/Containers/Data/Application/2E0E48B7-30E5-4567-8C0B-ACAC100AE389/Documents/AppName/1499773278.555753.mp4
Please help.
The solution i found is, the url path i was assigning is wrong as per the Facebook guidelines of sharing video.
The video URL videoURL must be an asset URL. You can get a video asset URL e.g. from UIImagePickerController.
See video sharing section inside the link.
UPDATE:
Final Solution to share image, video together using picker or document directory path whichever, this works.
let shareText = "Upload video, image and text."
let vc = UIActivityViewController(activityItems: [shareText, vidUrl, imageToShare], applicationActivities: [])
present(vc, animated: true)

Sharing Video PHAsset via UIActivityController

I am trying to share video PHAsset via UIActivityController using requestAVAsset. This works with Messaging, but not with AirDrop, indicating as 'Failed'.
PHCachingImageManager.default().requestAVAsset(forVideo: asset, options: nil, resultHandler:
{ (givenAsset, audioMix, info) in
let videoAsset = givenAsset as! AVURLAsset
let videoURL = videoAsset.url
DispatchQueue.main.async {
let activityViewController = UIActivityViewController(
activityItems: [videoURL],
applicationActivities: nil)
activityViewController.excludedActivityTypes = [UIActivityType.saveToCameraRoll]
if let popoverPresentationController = activityViewController.popoverPresentationController {
popoverPresentationController.barButtonItem = (sender)
}
self.present(activityViewController, animated: true, completion: nil)
}
})
This seems to properly put up UIActivityController and only work with certain activities:
Messaging - ✔️Works, properly exports video.
AirDrop - ✖️Shows "Failed"
Dropbox - ✖️Puts up the proper Dropbox View, yet says "Unknown error occurred"
I've run into similarly odd behavior when working with PHAssets. My guess is this is a (purposely) undocumented security/sandboxing restriction.
I was able to work around this problem by copying the underlying file to a user directory, and then performing the operation on the copied file.
I did this in a loop. Occasionally, the copy fails with a vague file permissions error. When it does, I retry it after a few seconds (using DispatchQueue.main.asyncAfter). Eventually, it works!

Resources