问题
Hi all am trying to open instagram app on a button click but am not able to i set Url scheme as instagram in plist also
NSString *instagramURL = @"instagram://app"; NSURL *ourURL = [NSURLURLWithString:instagramURL]; if ([[UIApplication sharedApplication]canOpenURL:ourURL]) { [[UIApplication sharedApplication]openURL:ourURL]; } else { //The App is not installed. It must be installed from iTunes code. NSString *iTunesLink = @"//Some other Url goes here"; [[UIApplication sharedApplication] openURL:[NSURL URLWithString:iTunesLink]]; UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"URL error" message:[NSString stringWithFormat: @"No custom URL defined for %@", ourURL] delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil]; [alert show];
i did like this but app not opening am new to iOS any help can be appreciated
回答1:
You can open instagram app by username like,
NSURL *instagramURL = [NSURL URLWithString:@"instagram://user?username=USERNAME"];
if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {
[[UIApplication sharedApplication] openURL:instagramURL];
}
You can refer iPhone Hooks of Instagram for more ways and details about api!!!
Update :
Replace below line,
NSString *instagramURL = @"instagram://app";
with
NSURL *instagramURL = [NSURL URLWithString:@"instagram://app"];
You are assigning directly string as url!!
回答2:
Add key Value In Info.plist File
<key>LSApplicationQueriesSchemes</key>
<array>
<string>instagram</string>
<string>twitter</string>
</array>
来源:https://stackoverflow.com/questions/38803801/how-to-open-instagram-app-on-button-click