Skip to content

Commit

Permalink
added appendix/sample-sfsafariviewcontroller-chromecustomtabs/.
Browse files Browse the repository at this point in the history
  • Loading branch information
KojiNakamaru committed Aug 21, 2021
1 parent d9ed61f commit b426673
Show file tree
Hide file tree
Showing 44 changed files with 2,865 additions and 0 deletions.
71 changes: 71 additions & 0 deletions appendix/sample-sfsafariviewcontroller-chromecustomtabs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# This .gitignore file should be placed at the root of your Unity project directory
#
# Get latest from https://github.com/github/gitignore/blob/master/Unity.gitignore
#
/[Ll]ibrary/
/[Tt]emp/
/[Oo]bj/
/[Bb]uild/
/[Bb]uilds/
/[Ll]ogs/
/[Uu]ser[Ss]ettings/

# MemoryCaptures can get excessive in size.
# They also could contain extremely sensitive data
/[Mm]emoryCaptures/

# Asset meta data should only be ignored when the corresponding asset is also ignored
!/[Aa]ssets/**/*.meta

# Uncomment this line if you wish to ignore the asset store tools plugin
# /[Aa]ssets/AssetStoreTools*

# Autogenerated Jetbrains Rider plugin
/[Aa]ssets/Plugins/Editor/JetBrains*

# Visual Studio cache directory
.vs/

# Gradle cache directory
.gradle/

# Autogenerated VS/MD/Consulo solution and project files
ExportedObj/
.consulo/
*.csproj
*.unityproj
*.sln
*.suo
*.tmp
*.user
*.userprefs
*.pidb
*.booproj
*.svd
*.pdb
*.mdb
*.opendb
*.VC.db

# Unity3D generated meta files
*.pidb.meta
*.pdb.meta
*.mdb.meta

# Unity3D generated file on crash reports
sysinfo.txt

# Builds
*.apk
*.aab
*.unitypackage

# Crashlytics generated file
crashlytics-build.properties

# Packed Addressables
/[Aa]ssets/[Aa]ddressable[Aa]ssets[Dd]ata/*/*.bin*

# Temporary auto-generated Android Assets
/[Aa]ssets/[Ss]treamingAssets/aa.meta
/[Aa]ssets/[Ss]treamingAssets/aa/*
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using UnityEngine;

// cf. https://qiita.com/lucifuges/items/b17d602417a9a249689f

public class Main : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{

}

// Update is called once per frame
void Update()
{

}

void OnGUI()
{
if (GUI.Button(new Rect(10, 10, 150, 100), "Open")) {
LaunchURL("https://www.google.com");
}
}

#if UNITY_EDITOR
#elif UNITY_ANDROID
#elif UNITY_IOS
[DllImport("__Internal")]
static extern void launchURL(string url);
#endif

void LaunchURL(string url)
{
#if UNITY_EDITOR
Application.OpenURL(url);
#elif UNITY_ANDROID
using (var unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
using (var activity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity"))
using (var intentBuilder = new AndroidJavaObject("android.support.customtabs.CustomTabsIntent$Builder"))
using (var intent = intentBuilder.Call<AndroidJavaObject>("build"))
using (var uriClass = new AndroidJavaClass("android.net.Uri"))
using (var uri = uriClass.CallStatic<AndroidJavaObject>("parse", url))
intent.Call("launchUrl", activity, uri);
#elif UNITY_IOS
launchURL(url);
#endif
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<dependencies>
<androidPackages>
<androidPackage spec="com.android.support:customtabs:23.0.0" />
</androidPackages>
</dependencies>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#import <SafariServices/SafariServices.h>

extern UIViewController* UnityGetGLViewController();

extern "C"
{
void launchURL(const char *url)
{
UIViewController *uvc = UnityGetGLViewController();
NSURL *URL = [NSURL URLWithString:[[NSString alloc] initWithUTF8String:url]];
SFSafariViewController *sfvc = [[SFSafariViewController alloc] initWithURL:URL];
[uvc presentViewController:sfvc animated:YES completion:nil];
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b426673

Please sign in to comment.