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.