NimbleKit - fast iOS app development

Is App Installed?

Ask questions and share your skills here

Is App Installed?

Postby cactuscraig » Wed Oct 19, 2011 7:44 pm

I think I have asked this before - but did not get any where with it.
I need to check if an App is installed.
ie: reserve://opentable.com/18910?partySize=2 will open the Open Table App.

My plan is that is the App is not installed, then I would goto the Website instead (www). I am sure this might be simple, using some Objective C code using "canOpenURL"

Can anyone help?
User avatar
cactuscraig
 
Posts: 846
Joined: Thu Feb 03, 2011 5:15 pm
Location: Scottsdale, AZ

Re: Is App Installed?

Postby blazeman » Wed Oct 19, 2011 7:51 pm

Check the Objective-C blueprint. Look at the jailbreak check. Might be able to use similar code

The way you have it. Unless each app will have shortcode defined in the plist... it will be hard to tell for sure
User avatar
blazeman
NimbleKit Expert
 
Posts: 712
Joined: Sat May 30, 2009 5:58 pm

Re: Is App Installed?

Postby cactuscraig » Wed Oct 19, 2011 8:11 pm

After some long hard Googling... I figured it out.
See attached.

I have submitted request to make this part of NimbleKit as I think it could be pretty useful.

I have tested with several schemes on my iPad:
fb (facebook)
youtube
tel (False on iPad)
reserve (OpenTable)
http (Safari mobile)
imdb
tweetie (twitter client)


see http://wiki.akosma.com/IPhone_URL_Schemes

I hope you enjoy!
Attachments
URL-Schemas.zip
(42.47 KiB) Downloaded 72 times
User avatar
cactuscraig
 
Posts: 846
Joined: Thu Feb 03, 2011 5:15 pm
Location: Scottsdale, AZ

Re: Is App Installed?

Postby HalfMoon » Thu Oct 20, 2011 1:15 pm

Nice one Craig - adding this to nK Blueprint Obj-C
:D
User avatar
HalfMoon
NimbleKit Guru
 
Posts: 662
Joined: Thu Jun 04, 2009 6:21 pm
Location: Brighton, UK

Re: Is App Installed?

Postby carroll.megs » Sat Nov 19, 2011 4:55 am

Okay, so I'm still very new to all of this and I cannot figure out how to implement this code. I have two buttons that I want to set so that when the user taps the button it either opens the app or takes them to a website. It seems like that is what the code above should do, but I don't know how to get it to work with my app. I copied the myscheme.m and myscheme.h directly and pasted this code into my .html file.

Code: Select all
   // Register Class
   NKRegisterClass("myscheme");
   
   // Check for scheme
   function isInstalled()
   {
      myScheme = textField.getString() + ":";
      var canWeOpenScheme = CallNKitAction('canOpenScheme?className=myscheme&sync=yes&scheme=' + myScheme);
      NKLog (canWeOpenScheme);
      NKAlert ("Can we open " + myScheme + "?",canWeOpenScheme);
      
   }


What do I change in the code above to get it to look at the buttons rather than a text field? And where do I put the alternate site urls (for the websites to go to if the user doesn't have the app)? If it helps you, this is what my buttons look like:

Code: Select all
 var twitterButton = new NKButton();
            twitterButton.init(20, 20, 80, 80, "twitterLink");
            twitterButton.setImage('twitter-128x128.png');
            twitterButton.show();
           
            function twitterLink() {
                NKOpenURLInSafari('twitter://user?screen_name=kind_post');
            }
           
            var fbButton = new NKButton();
            fbButton.init(120, 20, 80, 80, "fbLink");
            fbButton.setImage('facebook-128x128.png');
            fbButton.show();
           
            function fbLink() {
                NKOpenURLInSafari('fb://page/306311346061753');
            }


Sorry, I know this must be pretty basic but it's all very new to me. I would really appreciate any help. Thanks.
carroll.megs
 
Posts: 5
Joined: Thu Nov 17, 2011 4:36 pm

Re: Is App Installed?

Postby cactuscraig » Sun Nov 20, 2011 11:05 pm

Button calls a function
Code: Select all
myButton.init(l,t,w,h,"functionFB()");


Function checks if app is installed. If TRUE then open app, else open www page.

Code: Select all
function functionFB()
{
If (isInstalled("fb")==TRUE)
  {
    Nkopenurlinsafari("fb://etc")
   } else {
   nkopenurlinsafari("http://www.facebook.com/etc")
   }
}


And change the isinstalled function to read a variable
Code: Select all
function isInstalled(myurl)
{
// check it here
var canWeOpenScheme = CallNKitAction('canOpenScheme?className=myscheme&sync=yes&scheme=' +  myurl + ':');
}


I am doing this from iPad so code may have errors but should be close for you.
I would recommend learning about JavaScript as this is pretty basic changes.
User avatar
cactuscraig
 
Posts: 846
Joined: Thu Feb 03, 2011 5:15 pm
Location: Scottsdale, AZ

Re: Is App Installed?

Postby carroll.megs » Mon Nov 21, 2011 4:29 am

Thank you, cactuscraig. I knew it would be something simple, but I just started learning Javascript and I wasn't sure exactly what to do. Thanks for taking the time to help me. I appreciate it!
carroll.megs
 
Posts: 5
Joined: Thu Nov 17, 2011 4:36 pm

Re: Is App Installed?

Postby carroll.megs » Mon Nov 21, 2011 6:39 pm

Cactuscraig, your code was missing a couple of quotes and a return statement. Once I added those, it worked perfectly. I thought I would share what my final code looks like in case anyone else wants to do the same thing. Here's what you do:

First save the myscheme.m and myscheme.h files from the example above and set a function in your HTML to register the class.

Code: Select all
NKRegisterClass("myscheme");


Then create the button and call a function to either open the app or open the website if the app is not installed.

Code: Select all
var fbButton = new NKButton();
            fbButton.init(c_x-b_w/2+space, c_y-b_h/2 , b_w , b_h, "functionFB()");
            fbButton.setImage('facebook.png');
            fbButton.show();
           
            function functionFB() {
                if (isInstalled("fb")=="TRUE")
                {
                    NKOpenURLInSafari("fb://page/306311346061753")
                }
                else {
                    NKOpenURLInSafari("http://www.facebook.com/kindpost")
                }
            }


Next, create the isInstalled function and set it to check if the app is installed. Don't forget to include the return statement.

Code: Select all
 function isInstalled(myurl)
            {
                // check it here
                var canWeOpenScheme = CallNKitAction('canOpenScheme?className=myscheme&sync=yes&scheme=' +  myurl + ':');
                return canWeOpenScheme;
            }


I left in my specific URLs so you can see exactly where you need to edit the code to get it to work for you. Thanks again to cactuscraig for his invaluable help in getting this to work.
carroll.megs
 
Posts: 5
Joined: Thu Nov 17, 2011 4:36 pm

Re: Is App Installed?

Postby cactuscraig » Mon Nov 21, 2011 10:11 pm

Yep - not easy debugging from an iPad :D Glad you got it working ok. I have asked them (the "devs") to include this as an NK function... so maybe they will.
Seems like an important function have. Took me a long time to get it up and running.
User avatar
cactuscraig
 
Posts: 846
Joined: Thu Feb 03, 2011 5:15 pm
Location: Scottsdale, AZ

Re: Is App Installed?

Postby HalfMoon » Sun Dec 04, 2011 6:26 pm

This website has a great list of available URL Schemes:
handleopenurl.com
8-)
User avatar
HalfMoon
NimbleKit Guru
 
Posts: 662
Joined: Thu Jun 04, 2009 6:21 pm
Location: Brighton, UK

Next

Return to How To...

Who is online

Users browsing this forum: Google [Bot] and 0 guests