how to open instagram app on button click

[亡魂溺海] 提交于 2019-12-11 00:59:36

问题


  1. 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!