system.canOpenURL does not work correct !

 Hi there

i try to see if another App is installed via:

if ( system.canOpenURL( “pic2shop://scan?callback=http://xxxx.com” ) ) then

     system.openURL("pic2shop://scan?callback=http://guruk.com")

else

   print (“pic2Shop is not installed”

end

anyhow on Android it worked first, than i deleted pic2shop from the device and it still say its ‘installed’

when i would try another name (like:  pic2shopB) it says again app not installed

on iPhone it says always ‘not installed’ till i set in plist:  LSApplicationQueriesSchemes = { “pic2shopla”},

than even if the app is not installed it says: “App installed”

for iPhone i have in pList:

LSApplicationQueriesSchemes = { “pic2shop”},

CFBundleURLTypes =

{

{

CFBundleURLSchemes =

{

“pic2shopla”, – example scheme for pic2shop

}

}

},

for Android:

  intentFilters =

      {

         {

            label = “Open pic2shop”,

            actions = { “android.intent.action.VIEW” },

            categories =

            {

               “android.intent.category.DEFAULT”,

               “android.intent.category.BROWSABLE”,

            },

            data = { scheme = “pic2shop” },

         },

         – You can add more intent filters here.

      },

so how to get this system.canOpenURL work fine?

thanks

chris

this is my log on iphone

Apr  7 12:19:02 Christians-iPhone VideoStore[1307] <Warning>: start qrscanner

Apr  7 12:19:02 Christians-iPhone VideoStore[1307] <Warning>: YEAHH: pic2shop app is installed on iOS!

>>> (here i checked with canOpenUrl)

Apr  7 12:19:02 Christians-iPhone VideoStore[1307] <Warning>: WARNING: /Users/snowwhitesinai/Dropbox/Orga/SourceCodes/corona/IN WORK/videostore/videostore.lua:169: system.openURL() failed to open URL: pic2shop://scan?callback=http://guruk.com

>>>> and anyhow I get a warning not able to open !!

You’re probably hitting the ATS policy. https://docs.coronalabs.com/guide/hardware/appleATS/index.html
 
Put this in your iphone --> plist (in build.settings):

 NSAppTransportSecurity = { NSAllowsArbitraryLoads = true, },

Ex:
 
https://docs.coronalabs.com/guide/hardware/appleATS/index.html#configuring-connections

https://docs.coronalabs.com/guide/hardware/appleATS/index.html#bypassing-ats

thanks for trying… also did not helped

it says " pic2shop’ is installed even if its not

my plist

iphone =

{

plist =

{

UIApplicationExitsOnSuspend = “false”,

UIViewControllerBasedStatusBarAppearance = “false”,

   UIPrerenderedIcon = “true”,

       CFBundleIconFile = “Icon.png”,

            LSApplicationQueriesSchemes = { “pic2shop”,“videostore”},

CFBundleURLTypes =

{

{

CFBundleURLSchemes =

{

“pic2shop”, – example scheme for pic2shop

“videostore”, – example scheme for pic2shop

}

}

},

       CFBundleIconFiles = {

          “Icon.png”, 

          “Icon@2x.png”, 

          “Icon-72.png”, 

       },

NSAppTransportSecurity =

          {

             NSAllowsArbitraryLoads = true

          },

},

any updates on that?? this canopenurl just does not work on my side

greets

chris

I did a test. Everything works fine. Here is my test:

When app is deleted, other app updates to “false”.

https://gist.github.com/Shchvova/d9805871df99a7e6ffa89d18b7338f2a

thanks for testing.

anyhow it works with the 2 testapps u made fine. but not with an external app like pic2shop (the qr scanner)

please do a copy of the appb , and change all AppA names into pic2shop 

when pic2shop is installed it will say TRUE and when u uninstall pic2shop it will also say true !! :frowning:

chris

What did you expect? canOpenURL shows if you can open URL, not which app is handling it. You can have several apps associated with same URL scheme, as long as any of them is installed it would return true. This is how it suppose to work.

i expected that it does what it say 'can i open the url!"

not if the other app i like to open has my app in his scheme.

when i do openurl and it opens the app… canopenurl also should tell me ‘true’

if i do openurl and the other app is not there and cant be opened…canopenurl should tell me ‘false’

is that wrong? 

so i can only check for other apps that have MY App in his urlscheme? 

yes, than i missunderstood the concept and canopenurl is not useful for me.

As I would need to check if the 3rd Party App ‘pic2shop’ is installed on the user device, if not i tell the user to install it. 

if the app is already installed, it will open, scan a barcode and go back to my app.

I’m really confused of what is your problem. So, Lets put some concepts first:

  1. In iOS apps can handle URL schemes. For example, “http” and “https” are URL schemes handled by Safari. There are many url schemes though, like “instagram” which is usually handled by Instagram app, or “fb” which is usually handled by Facebook. When you open “instagram://” user expects to see Instagram app. You can open url with

[lua]local success = system.openUrl(“instagram://”)[/lua]

  1. Anyone can register for any URL. It is considered super bad practice to register your app for URL which is already used by some other app. To register for URL you have to add CFBundleURLTypes/CFBundleURLSchemes to your plist. If you’ll add, say “testtesttest” scheme, if you’ll open URL “testtesttest://…” your app would be started. Anything can open this URL. It can be done with even with browser.

  2. In iOS apps can test if they would be able to open URL. For example, system.canOpenURL(“testtesttest://…”) returns if there any app which can handle “testtesttest” URL scheme. It doesn’t say if URL is valid, of if SPECIFIC app is installed. It gives answer if there is anything which can open app. You can not just query arbitrary URL scheme. You can list up to 50 URL schemes in LSApplicationQueriesSchemes.

So. As a result, you CAN test if app is installed. Just add “pic2shop” to LSApplicationQueriesSchemes and this is ALL changes you need to do. DO NOT add pic2shop to CFBundleURLTypes/CFBundleURLSchemes because it will make your app handle this URL. Of course, it would return true in that case.

I see, thank you so much for ur explanation, i will try immediatly.

and how is about Android?

there i have now:

  intentFilters =

      {

         {

            label = “Open pic2shop”,

            actions = { “android.intent.action.VIEW” },

            categories =

            {

               “android.intent.category.DEFAULT”,

               “android.intent.category.BROWSABLE”,

            },

            data = { scheme = “pic2shop” },

         },

         {

            label = “Open VideoStore”,

            actions = { “android.intent.action.VIEW” },

            categories =

            {

               “android.intent.category.DEFAULT”,

               “android.intent.category.BROWSABLE”,

            },

            data = { scheme = “videostore” },

         },

the Videostore (my app) is there, because in the pic2shop app i can give a url it opens after the barcode scan, so i simple said videostore://xxxx and works well.

but also there i have the problem, when pic2shop is NOT installed, the canopenurl, tells me app is installed.

but strangwise it works fine when the app was never installed before. when i install it and uninstall it still says installed.

does android does not remove the urlscheme when the app is uninstalled? 

anyhow… i just need for Android also a simple solution to check if another app (pic2shop) is installed or not.

greets

chris

I can be wrong, but what happens if you remove this:

         {

            label = “Open pic2shop”,

            actions = { “android.intent.action.VIEW” },

            categories =

            {

               “android.intent.category.DEFAULT”,

               “android.intent.category.BROWSABLE”,

            },

            data = { scheme = “pic2shop” },

         },

thanks I will try.!!!
 

another thing… i really have problems with the simulator/build for android/copy to device

it never finds the adb… i made already    launchctl setenv ANDROID_SDK <path-to-sdk>

but still no success.  my adb is in this folder:

/Users/snowwhitesinai/Dropbox/Orga/SourceCodes/android/newsdk/platform-tools/adb 

 

so i do  launchctl setenv ANDROID_SDK /Users/snowwhitesinai/Dropbox/Orga/SourceCodes/android/newsdk/platform-tools/

 

what else can i do?  What exactly the simulator is looking for?!

 

thanks

chris

super… i did removed what u said from android intent

now it works :slight_smile:

if u still could help me with the problem of ADB search path, so i could install automatically to my android device

would be also amazing.

thanks so much… great advices !!

this is my log on iphone

Apr  7 12:19:02 Christians-iPhone VideoStore[1307] <Warning>: start qrscanner

Apr  7 12:19:02 Christians-iPhone VideoStore[1307] <Warning>: YEAHH: pic2shop app is installed on iOS!

>>> (here i checked with canOpenUrl)

Apr  7 12:19:02 Christians-iPhone VideoStore[1307] <Warning>: WARNING: /Users/snowwhitesinai/Dropbox/Orga/SourceCodes/corona/IN WORK/videostore/videostore.lua:169: system.openURL() failed to open URL: pic2shop://scan?callback=http://guruk.com

>>>> and anyhow I get a warning not able to open !!

You’re probably hitting the ATS policy. https://docs.coronalabs.com/guide/hardware/appleATS/index.html
 
Put this in your iphone --> plist (in build.settings):

 NSAppTransportSecurity = { NSAllowsArbitraryLoads = true, },

Ex:
 
https://docs.coronalabs.com/guide/hardware/appleATS/index.html#configuring-connections

https://docs.coronalabs.com/guide/hardware/appleATS/index.html#bypassing-ats

thanks for trying… also did not helped

it says " pic2shop’ is installed even if its not

my plist

iphone =

{

plist =

{

UIApplicationExitsOnSuspend = “false”,

UIViewControllerBasedStatusBarAppearance = “false”,

   UIPrerenderedIcon = “true”,

       CFBundleIconFile = “Icon.png”,

            LSApplicationQueriesSchemes = { “pic2shop”,“videostore”},

CFBundleURLTypes =

{

{

CFBundleURLSchemes =

{

“pic2shop”, – example scheme for pic2shop

“videostore”, – example scheme for pic2shop

}

}

},

       CFBundleIconFiles = {

          “Icon.png”, 

          “Icon@2x.png”, 

          “Icon-72.png”, 

       },

NSAppTransportSecurity =

          {

             NSAllowsArbitraryLoads = true

          },

},

any updates on that?? this canopenurl just does not work on my side

greets

chris

I did a test. Everything works fine. Here is my test:

When app is deleted, other app updates to “false”.

https://gist.github.com/Shchvova/d9805871df99a7e6ffa89d18b7338f2a

thanks for testing.

anyhow it works with the 2 testapps u made fine. but not with an external app like pic2shop (the qr scanner)

please do a copy of the appb , and change all AppA names into pic2shop 

when pic2shop is installed it will say TRUE and when u uninstall pic2shop it will also say true !! :frowning:

chris