Question

I am a iPhone developer. I know that we can open iphone app from other apps using CustomURL Scheme and calling that from openURL: method.

What I am looking for I want to open my app which has some customURLScheme registered in plist file from a php web pages. I have a very little knowledge on PHP. I know that I can check that the client browser from where we got request is iphone safari or not.

now I have following logic to follow:

if(Client == iPhoneSafari) {
    //Open My App URL
}

For opening app from iphone to iphone we use following code:

[[UIApplication sharedApplication] openURL:myURL];

I have checked This Link and I want to make sure that the same code of iphone will work for web page opened in iphone safari or not??

If no than I want to know what code we need to write for samething to do in webpage for opening app.

I know this is very silly to ask for code here.. but I don't know about PHP and I am not aware with syntax.

Thanks In Advance

Was it helpful?

Solution

Presuming you have already setup the custom URL scheme in your plist file, you can do something like this in PHP:

<?php

function isIphone($user_agent=NULL) {
    if(!isset($user_agent)) {
        $user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
    }
    return (strpos($user_agent, 'iPhone') !== FALSE);
}

if(isIphone()) {
    //header('Location: myapp://
    //exit();
    ?><a href="myapp://">Tap this to launch application</a><?php
} else {
?><h1>Visit this page in iOS</h1><?php
}

// THE REST OF YOUR CODE HERE

?>

You check which browser it is using the UserAgent and then show a hyperlink leading to your custom URL scheme.

You can also use php-mobile-detect: http://code.google.com/p/php-mobile-detect/

This has a very convenient function for detecting iPad, iPhone and iPod browsers all in one. The above example works only for iPhone.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top