Open the youtube app from flutter app on iOS

frankenapps

I basically want to open a specific youtube video from my app, when a button is pressed. If the youtube app is installed on the user's device, then the video should be opened in the youtube app (and not in the browser or a separate webview).

I used the url_launcher package for that, and it works fine on android. However on iOS the youtube app is not opened even if it is installed, instead a separate web window is opened, where the corresponding youtube url is shown as a webpage.

I thought, that I could override this behaviour like so:

_launchURL() async {
  if (Platform.isIOS) {
    if (await canLaunch('youtube://www.youtube.com/channel/UCwXdFgeE9KYzlDdR7TG9cMw')) {
      await launch('youtube://www.youtube.com/channel/UCwXdFgeE9KYzlDdR7TG9cMw');
    } else {
      if (await canLaunch('https://www.youtube.com/channel/UCwXdFgeE9KYzlDdR7TG9cMw')) {
        await launch('https://www.youtube.com/channel/UCwXdFgeE9KYzlDdR7TG9cMw');
      } else {
        throw 'Could not launch https://www.youtube.com/channel/UCwXdFgeE9KYzlDdR7TG9cMw';
      }
    }
  } else {
    const url = 'https://www.youtube.com/channel/UCwXdFgeE9KYzlDdR7TG9cMw';
    if (await canLaunch(url)) {
      await launch(url);
    } else {
      throw 'Could not launch $url';
    }
  }
}

but it didn’t work. In case you wonder, I use the following imports:

import 'dart:io' show Platform;
import 'package:url_launcher/url_launcher.dart';

I am pretty sure, the youtube:// URL-Scheme works (launches the YouTube app), because I tested it on third party apps (Launch Center Pro and Pythonista).

The last thing I was not able to test, is if the Platform.isIOS is really true on my IPhone.

Is there a working way, to open the YouTube App from flutter?

frankenapps

I fixed it. I had to set forceSafariVC: false, because it is true on default, which causes the url to be opened inside a sort of webview inside the app.

_launchURL() async {
  if (Platform.isIOS) {
    if (await canLaunch('youtube://www.youtube.com/channel/UCwXdFgeE9KYzlDdR7TG9cMw')) {
      await launch('youtube://www.youtube.com/channel/UCwXdFgeE9KYzlDdR7TG9cMw', forceSafariVC: false);
    } else {
      if (await canLaunch('https://www.youtube.com/channel/UCwXdFgeE9KYzlDdR7TG9cMw')) {
        await launch('https://www.youtube.com/channel/UCwXdFgeE9KYzlDdR7TG9cMw');
      } else {
        throw 'Could not launch https://www.youtube.com/channel/UCwXdFgeE9KYzlDdR7TG9cMw';
      }
    }
  } else {
    const url = 'https://www.youtube.com/channel/UCwXdFgeE9KYzlDdR7TG9cMw';
    if (await canLaunch(url)) {
      await launch(url);
    } else {
      throw 'Could not launch $url';
    }
}

This is actually documented in the url_launcher docs, but somewhat hidden...

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Flutter : open video in YouTube App in iOS version

How to Open YouTube app with YouTube id on a button click in iOS

Open iOS app from browser

Open a existing app from own app ios

Flutter app when I open the app in iOS freeze on the splashscreen

How to open app from other app within app in iOS

Open iOS app from a Safari without "Open in <app>" prompt

How to open an application from a Flutter app?

How to open a page from within a Flutter app

How to open Youtube app from another app after clicking a button with a query searched in youtube?

Open App From Widget IOS with Swift

iOS Open Document with External App from UIWebVIew

How to open iOS app from within extension?

Open eMail from App with predefined text in iOS

iOS 10 UNNotificationAction Open App from Background

Open link to Facebook page from iOS app

Open iOS app from URL AND Pass Parameters

Open Facebook Messenger from iOS app

Open Twitter from iOS App Not Working Correctly

How to open a Youtube video link directly from android app?

on click launch whastapp from flutter app in IOS

Open Settings App from another App in iOS - React Native

How to programmatically open Apple Watch companion app from iOS app

How to open IOS Linkedin Learning App from my app

How to open VK app from my ios app

How to open the ios Native dialer app from my App

How to open Dropbox app from an another App in IOS Xamarin?

How to open a watch app from parent iOS app?

Is it possible to always allow "Open this page in WhatsApp" dialog on iOS Flutter App?