Giter Site home page Giter Site logo

pinkdiamond1 / unity-ios-can-open-url Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nrjwolf/unity-ios-can-open-url

0.0 1.0 0.0 6 KB

With this plugin you can check is some app installed on ios device

License: MIT License

C# 52.28% Objective-C 47.72%

unity-ios-can-open-url's Introduction

Unity IOS Can Open URL

Install

Copy/paste into your unity Assets folder

What I can do?

You can check is some application installed on iOS. Keep in mind that you need to know checking app URL sheme. More information about this here

Example

In this example I checking is instagram installed. If yes, will open application link, if no, will open it in browser.

private void OpenInstagramApp()
{
    var link = "https://www.instagram.com/nrjwolf.games/";
    // check to open in app IOS ONLY
    var iosAppLink = "instagram://user?username=nrjwolf.games";
    if (IOSCanOpenURL.CheckUrl(iosAppLink))
    {
        link = iosAppLink;
    }
    Application.OpenURL(link);
}

Also, you need to add instagram in your LSApplicationQueriesSchemes. You can do it manualy, or by code using IPostprocessBuildWithReport, lioke this :

using System.IO;
using UnityEngine;

using UnityEditor;
using UnityEditor.Build.Reporting;
using UnityEditor.Build;

#if UNITY_IOS
using UnityEditor.iOS.Xcode;
#endif

public class BuildCommand : IPostprocessBuildWithReport
{
    public int callbackOrder
    {
        get { return 2; }
    }

    public void OnPostprocessBuild(BuildReport report)
    {
        Debug.Log("OnPostprocessBuild for " + report.summary.platform);
        switch (report.summary.platform)
        {
            case BuildTarget.iOS:
                {
#if UNITY_IOS
                    const string projectName = "Unity-iPhone";
                    var pbxProjPath = Path.Combine(Path.Combine(report.summary.outputPath, projectName + ".xcodeproj"), "project.pbxproj");
                    Debug.Log("xcode project path: " + pbxProjPath);

                    var pbxProject = new PBXProject();
                    pbxProject.ReadFromFile(pbxProjPath);
                    var mainTargetGuid = pbxProject.TargetGuidByName("Unity-iPhone");

                    var plistPath = Path.Combine(report.summary.outputPath, "Info.plist");
                    var plist = new PlistDocument();
                    plist.ReadFromFile(plistPath);

                    // Add UIApplication url
                    var LSApplicationQueriesSchemesArray = plist.root.CreateArray("LSApplicationQueriesSchemes");
                    LSApplicationQueriesSchemesArray.AddString("instagram");

                    plist.WriteToFile(plistPath);
#else
                    Debug.Log("Can't build Unity iOS without UNITY_IOS define!");
#endif
                    break;
                }

            default:
                Debug.Log("no post-processing logic for platform " + report.summary.platform);
                break;
        }
    }
}

I'm on reddit
Discord server

unity-ios-can-open-url's People

Contributors

nrjwolf avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.