如何在按钮点击时打开Instagram应用程序

时间:2016-08-06 11:32:42

标签: ios instagram

  1. 大家好我想点击按钮打开Instagram应用,但不是 能够将url方案设置为plist中的instagram

    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];
    

    我确实喜欢这个,但应用程序没有打开iOS新的任何帮助都可以 理解

2 个答案:

答案 0 :(得分:3)

您可以按用户名

打开Instagram应用
 NSURL *instagramURL = [NSURL URLWithString:@"instagram://user?username=USERNAME"];
if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {
    [[UIApplication sharedApplication] openURL:instagramURL];
}

您可以参考iPhone Hooks of Instagram了解有关api的更多方式和详细信息!!!

更新:

替换下面的行,

 NSString *instagramURL = @"instagram://app"; 

   NSURL *instagramURL = [NSURL URLWithString:@"instagram://app"];

您直接将字符串指定为url !!

答案 1 :(得分:3)

在Info.plist文件中添加键值

<key>LSApplicationQueriesSchemes</key>
    <array>
        <string>instagram</string>
        <string>twitter</string>
    </array>