开发者

IOS Safari detect Skype

开发者 https://www.devze.com 2023-03-10 10:18 出处:网络
On iPhone, is it possible to detect on the webpage whether Skype is installed or not? The reason I ask is that I\'d like to change a link\'s href based on that: if Skype isn\'t installed, show a popu

On iPhone, is it possible to detect on the webpage whether Skype is installed or not?

The reason I ask is that I'd like to change a link's href based on that: if Skype isn't installed, show a popup explaining what Skype is and how to install it, if it is installed, change the link to skype:my.contact.name?call so the click will start a call.

I already trie开发者_如何学运维d solution discussed before Javascript to detect Skype but it only works on desktop browser but not on the mobile.


Here is the logic to determine whether Skype is installed. In the else statement you handle how you want to present the installation instructions to install Skype. Obviously this will work for any custom url scheme implemented for an iOS app so long as you update the url scheme accordingly on a per app basis.

NSString *contactName = @"user123";
NSURL *skypeURL = [NSURL URLWithString:[NSString stringWithFormat:@"skype://%@?call", contactName]];
if ([[UIApplication sharedApplication] canOpenURL:skypeURL]) {
  [[UIApplication sharedApplication] openURL:skypeURL];
} else {
  // Display to the user how to install skype.
}

Update:

I just noticed that tag was for Mobile-Safari so I presume that this is looking for a web-based solution. I don't think what you are trying to achieve will be possible then. The only way I can think about doing it was having an XMLHTTPRequest call the URL to see if the URL causes an error 404. The problem is any domain your executing the Javascript code from will not have the skype:// scheme in it and will undoubtedly throw a security error. This is because Javascript does not allow XMLHttpRequest to go onto domains other than the origin domain where your code is hosted.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号