0

In Android I can for example open mp4 files in user's apps from my own app (using Intents). In the next example - intent for playing a video:

enter image description here

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(newVideoPath));
intent.setDataAndType(Uri.parse(newVideoPath), "video/mp4");
startActivity(intent);

Is there something similar for iOS? Can I open from my app for example url (of video) in Photos, VLC or another player (which are installed on iPhone/iPad)

if yes, any example in Swift?

user25
  • 2,873
  • 2
  • 30
  • 66

2 Answers2

0

You should look at the documentation for Document interaction programming.

You can register file types that your app supports/can handle and then when a user selects a particular file from the files app or downloads from another app the system will offer a list of apps that can open this file, including yours.

Scriptable
  • 19,402
  • 5
  • 56
  • 72
  • My app records videos in mp4, only this file type I need to play with any user preinstalled app which can play videos (Photos, VLC,...). I will look at documentation, but I mean it's easy to find examples for Android, no examples for iOS at all? – user25 Feb 27 '18 at 12:56
  • ah then in that case you more than likely want to look at [UIDocumentInteractionController](https://developer.apple.com/documentation/uikit/uidocumentinteractioncontroller). I dont know of any examples, I haven't needed to do this in iOS yet – Scriptable Feb 27 '18 at 12:57
0

UIActivityViewController might fit your needs.

For example,

let url = // URL to your .mp4 file
let activityVC = UIActivityViewController(activityItems: [url], applicationActivities: nil)
present(activityVC, animated: true, completion: nil)
Samantha
  • 2,269
  • 2
  • 13
  • 25
  • `2018-02-27 16:44:22.028603+0200 ExampleApp[1408:759585] *** Terminating app due to uncaught exception 'NSGenericException', reason: 'Your application has presented a UIActivityViewController (). In its current trait environment, the modalPresentationStyle of a ` – user25 Feb 27 '18 at 14:52
  • fixed by `activityVC.popoverPresentationController?.sourceView = self.view`, but anyway - this is for file sharing and it displays many apps – user25 Feb 27 '18 at 14:57
  • Yeah, it won't give you open in video apps only, but you can mess around with `activityVC.excludedActivityTypes` to remove some of those options (like email, post to Facebook/Twitter, etc.) to maybe suit your needs better. Activity type documentation is here: https://developer.apple.com/documentation/uikit/uiactivitytype – Samantha Feb 27 '18 at 16:49
  • I mean it doesn't give me anything but copy, I guess iOS just doesn't really have such option, only for sharing/copying – user25 Feb 27 '18 at 17:09
  • Yes, iOS is a bit more restrictive than Android. It's also worth noting that in order for apps to show up in this list, their developers need to implement those capabilities from their end. – Samantha Feb 27 '18 at 17:10
  • as you see VLC for Android did it (and all other players) – user25 Feb 27 '18 at 17:19