首页 文章

如何链接到应用商店中的应用

提问于
浏览
641

我正在创建我的iPhone游戏的免费版本 . 我希望在免费版本中有一个按钮,可以将人们带到应用商店中的付费版本 . 如果我使用标准链接

http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=300136119&mt=8

iPhone首先打开Safari,然后打开应用程序商店 . 我使用过直接打开应用程序商店的其他应用程序,所以我知道这是可能的 .

有任何想法吗?应用商店的URL方案是什么?

23 回答

  • 25

    Edited on 2016-02-02

    从iOS 6 SKStoreProductViewController类开始介绍 . 您可以在不离开应用的情况下关联应用 . Swift 3.x/2.xObjective-C 中的代码段是here .

    SKStoreProductViewController对象提供了一个商店,允许用户从App Store购买其他媒体 . 例如,您的应用可能会显示商店以允许用户购买其他应用 .


    来自News and Announcement For Apple Developers .

    通过iTunes链接直接将应用程序驱动到App Store上的应用程序通过iTunes链接,您可以直接从您的网站或营销活动中为您的客户提供在App Store上访问应用程序的简便方法 . 创建iTunes链接很简单,可以将客户引导到单个应用程序,所有应用程序或指定公司名称的特定应用程序 . 要将客户发送到特定应用程序:http://itunes.com/apps/appname要将客户发送到App Store上的应用程序列表:http://itunes.com/apps/developername要将客户发送给具有您公司名称的特定应用程序包含在URL中:http://itunes.com/apps/developername/appname


    Additional notes:

    您可以将 http:// 替换为 itms://itms-apps:// 以避免重定向 .

    有关命名的信息,请参阅Apple QA1633:

    https://developer.apple.com/library/content/qa/qa1633/_index.html .

    Edit (as of January 2015):

    itunes.com/apps链接应更新到appstore.com/apps . 见上面的QA1633,已经更新 . 一个新的QA1629建议这些步骤和代码从应用程序启动商店:

    • 在您的计算机上启动iTunes .

    • 搜索要链接的项目 .

    • 右键单击或按住Control键并单击iTunes中项目的名称,然后从弹出菜单中选择"Copy iTunes Store URL" .

    • 在您的应用程序中,使用复制的iTunes URL创建 NSURL 对象,然后将此对象传递给 UIApplicationopenURL :方法以在App Store中打开您的项目 .

    示例代码:

    NSString *iTunesLink = @"itms://itunes.apple.com/us/app/apple-store/id375380948?mt=8";
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:iTunesLink]];
    

    Swift 3.0

    let urlStr = "itms://itunes.apple.com/us/app/apple-store/id375380948?mt=8"
        if #available(iOS 10.0, *) {
            UIApplication.shared.open(URL(string: urlStr)!, options: [:], completionHandler: nil)
    
        } else {
            UIApplication.shared.openURL(URL(string: urlStr)!)
        }
    
  • 15

    如果要直接向App Store打开应用程序,则应使用:

    ITMS-应用:// ...

    这样它将直接打开设备中的App Store应用程序,而不是先进入iTunes,然后只打开App Store(仅使用itms://)

    希望有所帮助 .


    编辑:APR,2017 . itms-apps://实际上在iOS10中再次运行 . 我测试了它 .

    编辑:APR,2013 . 这不再适用于iOS5及更高版本 . 只是用

    https://itunes.apple.com/app/id378458261
    

    而且没有更多的重定向 .

  • 10

    要简明扼要:

    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"itms://itunes.com/apps/appname"]];
    

    如果要发送给开发人员的所有应用程序,请使用

    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"itms://itunes.com/apps/developername"]];
    

    这些适用于iOS 4.1

    如果您想链接到开发人员的应用程序,并且开发人员的名称有标点符号或空格(例如Development Company,LLC),请构成您的URL,如下所示:

    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"itms-apps://itunes.com/apps/DevelopmentCompanyLLC"]];
    

    否则,它会在iOS 4.3.3上返回“此请求无法处理”

  • 32

    从iOS 6开始,正确的方法是使用 SKStoreProductViewController 类 .

    Swift 3.x

    func openStoreProductWithiTunesItemIdentifier(identifier: String) {
        let storeViewController = SKStoreProductViewController()
        storeViewController.delegate = self
    
        let parameters = [ SKStoreProductParameterITunesItemIdentifier : identifier]
        storeViewController.loadProduct(withParameters: parameters) { [weak self] (loaded, error) -> Void in
            if loaded {
                // Parent class of self is UIViewContorller
                self?.present(storeViewController, animated: true, completion: nil)
            }
        }
    }
    
    func productViewControllerDidFinish(_ viewController: SKStoreProductViewController) {
        viewController.dismiss(animated: true, completion: nil)
    }
    // Usage:
    openStoreProductWithiTunesItemIdentifier(identifier: "13432")
    

    您可以像这样获取应用程序的itunes项标识符:(而不是静态的)

    Swift 3.2

    var appID: String = infoDictionary["CFBundleIdentifier"]
    var url = URL(string: "http://itunes.apple.com/lookup?bundleId=\(appID)")
    var data = Data(contentsOf: url!)
    var lookup = try? JSONSerialization.jsonObject(with: data!, options: []) as? [AnyHashable: Any]
    var appITunesItemIdentifier = lookup["results"][0]["trackId"] as? String
    openStoreProductViewController(withITunesItemIdentifier: Int(appITunesItemIdentifier!) ?? 0)
    

    Swift 2.x

    func openStoreProductWithiTunesItemIdentifier(identifier: String) {
        let storeViewController = SKStoreProductViewController()
        storeViewController.delegate = self
    
        let parameters = [ SKStoreProductParameterITunesItemIdentifier : identifier]
        storeViewController.loadProductWithParameters(parameters) { [weak self] (loaded, error) -> Void in
            if loaded {
                // Parent class of self is UIViewContorller
                self?.presentViewController(storeViewController, animated: true, completion: nil)
            }
        }
    }
    
    func productViewControllerDidFinish(viewController: SKStoreProductViewController) {
        viewController.dismissViewControllerAnimated(true, completion: nil)
    }
    // Usage
    openStoreProductWithiTunesItemIdentifier("2321354")
    

    objective-C

    static NSInteger const kAppITunesItemIdentifier = 324684580;
    [self openStoreProductViewControllerWithITunesItemIdentifier:kAppITunesItemIdentifier];
    
    - (void)openStoreProductViewControllerWithITunesItemIdentifier:(NSInteger)iTunesItemIdentifier {
        SKStoreProductViewController *storeViewController = [[SKStoreProductViewController alloc] init];
    
        storeViewController.delegate = self;
    
        NSNumber *identifier = [NSNumber numberWithInteger:iTunesItemIdentifier];
    
        NSDictionary *parameters = @{ SKStoreProductParameterITunesItemIdentifier:identifier };
        UIViewController *viewController = self.window.rootViewController;
        [storeViewController loadProductWithParameters:parameters
                                       completionBlock:^(BOOL result, NSError *error) {
                                           if (result)
                                               [viewController presentViewController:storeViewController
                                                                  animated:YES
                                                                completion:nil];
                                           else NSLog(@"SKStoreProductViewController: %@", error);
                                       }];
    
        [storeViewController release];
    }
    
    #pragma mark - SKStoreProductViewControllerDelegate
    
    - (void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController {
        [viewController dismissViewControllerAnimated:YES completion:nil];
    }
    

    您可以像这样获得kAppITunesItemIdentifier(app的itunes项标识符):(而不是静态的)

    NSDictionary* infoDictionary = [[NSBundle mainBundle] infoDictionary];
        NSString* appID = infoDictionary[@"CFBundleIdentifier"];
        NSURL* url = [NSURL URLWithString:[NSString stringWithFormat:@"http://itunes.apple.com/lookup?bundleId=%@", appID]];
        NSData* data = [NSData dataWithContentsOfURL:url];
        NSDictionary* lookup = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
        NSString * appITunesItemIdentifier =  lookup[@"results"][0][@"trackId"]; 
        [self openStoreProductViewControllerWithITunesItemIdentifier:[appITunesItemIdentifier intValue]];
    
  • 0

    2015年夏季开始......

    -(IBAction)clickedUpdate
    {
        NSString *simple = @"itms-apps://itunes.apple.com/app/id1234567890";
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:simple]];
    }
    

    将'id1234567890'替换为'id'和'你的十位数'

    • 这完全适用于 all devices .

    • 它确实是 straight to 应用程序商店,没有重定向 .

    • 所有人都可以 national stores .

    • 如果链接的目的是更新你实际内在的应用程序,那么你应该 move to using loadProductWithParametersbut :使用这个"old-fashioned"方法可能更好 .

  • 3

    Apple刚刚发布了appstore.com网址 .

    https://developer.apple.com/library/ios/qa/qa1633/_index.html

    有三种类型的App Store短链接,有两种形式,一种用于iOS应用,另一种用于Mac应用:公司名称iOS:http://appstore.com/,例如http://appstore.com/apple Mac :http://appstore.com/mac/例如,http://appstore.com/mac/apple App App iOS:http://appstore.com/,例如,http://appstore.com/keynote Mac :http://appstore.com/mac/,例如http://appstore.com/mac/keynote App by Company iOS:http://appstore.com//,例如,http://appstore.com/ apple / keynote Mac:http://appstore.com/mac//例如,http://appstore.com/mac/apple/keynote大多数公司和应用程序都有一个规范的App Store Short Link . 此规范URL是通过更改或删除某些字符(其中许多字符是非法的或在URL中具有特殊含义(例如,“&”))来创建的 . 要创建App Store短链接,请将以下规则应用于您的公司或应用程序名称:删除所有空格将所有字符转换为小写全部删除版权所有(©),trademark(™)和注册商标(®)符号用“和”替换&符号(“&”)删除大多数标点符号(参见清单2中的集合)替换重音和其他“装饰”字符(ü,å等等,以其元素字符(u,a等)保留所有其他字符 . 清单2必须删除的标点字符 . !#“$%'()*, - . /:; <=>¿?@ [] ^ _` {|}〜下面是一些示例来演示发生的转换.App Store公司名称示例Gameloft = > http://appstore.com/gameloft Activision Publishing,Inc . => http://appstore.com/activisionpublishinginc陈的摄影和软件=> http://appstore.com/chensphotographyandsoftware应用名称示例Ocarina => http:/ /appstore.com/ocarina我的Perry在哪里?=> http://appstore.com/wheresmyperry Brain Challenge™=> http://appstore.com/brainchallenge

  • 1

    此代码在iOS上生成App Store链接

    NSString *appName = [NSString stringWithString:[[[NSBundle mainBundle] infoDictionary]   objectForKey:@"CFBundleName"]];
    NSURL *appStoreURL = [NSURL URLWithString:[NSString stringWithFormat:@"itms-apps://itunes.com/app/%@",[appName stringByReplacingOccurrencesOfString:@" " withString:@""]]];
    

    在Mac上用http替换itms-apps:

    NSURL *appStoreURL = [NSURL URLWithString:[NSString stringWithFormat:@"http:/itunes.com/app/%@",[appName stringByReplacingOccurrencesOfString:@" " withString:@""]]];
    

    在iOS上打开URL:

    [[UIApplication sharedApplication] openURL:appStoreURL];
    

    苹果电脑:

    [[NSWorkspace sharedWorkspace] openURL:appStoreURL];
    
  • 713

    只需在应用链接中将“itunes”更改为“phobos”即可 .

    http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=300136119&mt=8

    现在它将直接打开App Store

  • 12

    要在没有重定向的情况下拥有直接链接:

    • 使用iTunes链接制作工具http://itunes.apple.com/linkmaker/获取真正的直接链接

    • itms-apps:// 替换 http://

    • [[UIApplication sharedApplication] openURL:url]; 打开链接

    请注意,这些链接仅适用于实际设备,而不适用于模拟器 .

    资料来源:https://developer.apple.com/library/ios/#qa/qa2008/qa1629.html

  • 3

    这对我来说非常适合使用APP ID:

    NSString *urlString = [NSString stringWithFormat:@"http://itunes.apple.com/app/id%@",YOUR_APP_ID];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
    

    The number of redirects is ZERO.

  • 7

    许多答案建议使用'itms'或'itms-apps',但Apple并未特别推荐这种做法 . 他们只提供以下方式来打开App Store:

    Listing 1 从iOS应用程序启动App Store

    NSString *iTunesLink = @"https://itunes.apple.com/us/app/apple-store/id375380948?mt=8";
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:iTunesLink]];
    

    请参阅https://developer.apple.com/library/ios/qa/qa1629/_index.html上次更新于2014年3月,截至此答案 .

    对于支持iOS 6及更高版本的应用,Apple提供了一个用于展示App Store的应用内机制: SKStoreProductViewController

    - (void)loadProductWithParameters:(NSDictionary *)parameters completionBlock:(void (^)(BOOL result, NSError *error))block;
    
    // Example:
    SKStoreProductViewController* spvc = [[SKStoreProductViewController alloc] init];
    spvc.delegate = self;
    [spvc loadProductWithParameters:@{ SKStoreProductParameterITunesItemIdentifier : @(364709193) } completionBlock:^(BOOL result, NSError *error){ 
        if (error)
            // Show sorry
        else
            // Present spvc
    }];
    

    请注意,在iOS6上,如果有错误,可能无法调用完成块 . 这似乎是在iOS 7中解决的错误 .

  • 45

    如果您想链接到开发人员的应用程序,并且开发人员的名称有标点符号或空格(例如Development Company,LLC),请构成您的URL,如下所示:

    itms-apps://itunes.com/apps/DevelopmentCompanyLLC
    

    否则,它会在iOS 4.3.3上返回“此请求无法处理”

  • 35

    您可以通过链接制造商获取指向应用商店或iTunes中特定商品的链接:http://itunes.apple.com/linkmaker/

  • 163

    这在ios5中正常工作并直接链接

    NSString *iTunesLink = @"http://itunes.apple.com/app/baseball-stats-tracker-touch/id490256272?mt=8";  
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:iTunesLink]];
    
  • 3

    这是在app store上重定向/链接其他现有应用程序的简单而简短的方法 .

    NSString *customURL = @"http://itunes.apple.com/app/id951386316";
    
     if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:customURL]])
     {
           [[UIApplication sharedApplication] openURL:[NSURL URLWithString:customURL]];
     }
    
  • 27

    我可以确认,如果您在iTunes中创建应用程序,则在提交之前会获得您的应用程序ID .

    因此..

    itms-apps://itunes.apple.com/app/id123456789
    
    NSURL *appStoreURL = [NSURL URLWithString:@"itms-apps://itunes.apple.com/app/id123456789"];
        if ([[UIApplication sharedApplication]canOpenURL:appStoreURL])
            [[UIApplication sharedApplication]openURL:appStoreURL];
    

    工作一种享受

  • 329

    在支持多个操作系统和多平台时,创建链接可能会成为一个复杂的问题 . 例如,iOS 7(其中一些)不支持WebObjects,您创建的某些链接将打开另一个国家/地区商店,然后是用户等 .

    有一个名为iLink的开源库可以帮助你 .

    这个库的优点是 the links would be found and created at run time (该库将检查应用程序ID及其运行的操作系统,并确定应创建哪个链接) . 最好的一点是,如果你在同一个项目中有很少的目标,那么你也不会很好,所以你不必记住要使用的应用ID或链接 . 如果用户同意,如果商店中有新版本(这是内置的,您通过一个简单的标志关闭它),该库也会提示用户升级应用程序,直接指向应用程序的升级页面 .

    将2个库文件复制到项目中(iLink.h和iLink.m) .

    在你的appDelegate.m上:

    #import "iLink.h"
    
    + (void)initialize
    {
        //configure iLink
        [iLink sharedInstance].globalPromptForUpdate = YES; // If you want iLink to prompt user to update when the app is old.
    }
    

    在您要打开评级页面的地方,例如使用:

    [[iLink sharedInstance] iLinkOpenAppPageInAppStoreWithAppleID: YOUR_PAID_APP_APPLE_ID]; // You should find YOUR_PAID_APP_APPLE_ID from iTunes Connect
    

    不要忘记在同一文件中导入iLink.h .

    整个图书馆有一个非常好的文档和iPhone和Mac的示例项目 .

  • 3

    至少iOS 9及以上版本

    • 直接在App Store中打开

    一个应用程序

    itms-apps://itunes.apple.com/app/[appName]/[appID]
    

    开发人员应用列表

    itms-apps://itunes.apple.com/developer/[developerName]/[developerID]
    
  • 1

    对于Xcode 9.1和Swift 4:

    • 导入StoreKit:

    导入StoreKit

    2.遵守协议

    SKStoreProductViewControllerDelegate
    

    3.实施协议

    func openStoreProductWithiTunesItemIdentifier(identifier: String) {
        let storeViewController = SKStoreProductViewController()
        storeViewController.delegate = self
    
        let parameters = [ SKStoreProductParameterITunesItemIdentifier : identifier]
        storeViewController.loadProduct(withParameters: parameters) { [weak self] (loaded, error) -> Void in
            if loaded {
                // Parent class of self is UIViewContorller
                self?.present(storeViewController, animated: true, completion: nil)
            }
        }   
    }
    

    3.1

    func productViewControllerDidFinish(_ viewController: SKStoreProductViewController) {
        viewController.dismiss(animated: true, completion: nil)
    }
    
    • 如何使用:

    openStoreProductWithiTunesItemIdentifier(标识符:“here_put_your_App_id”)

    注意:

    输入APP的确切ID非常重要 . 因为这会导致错误(不显示错误日志,但由于这个原因,一切正常)

  • 0

    如果您拥有应用商店ID,则最好使用它 . 特别是如果您将来可能更改应用程序的名称 .

    http://itunes.apple.com/app/id378458261
    

    如果您没有应用商店ID,则可以根据此文档创建网址https://developer.apple.com/library/ios/qa/qa1633/_index.html

    + (NSURL *)appStoreURL
    {
        static NSURL *appStoreURL;
        static dispatch_once_t onceToken;
        dispatch_once(&onceToken, ^{
            appStoreURL = [self appStoreURLFromBundleName:[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleName"]];
        });
        return appStoreURL;
    }
    
    + (NSURL *)appStoreURLFromBundleName:(NSString *)bundleName
    {
        NSURL *appStoreURL = [NSURL URLWithString:[NSString stringWithFormat:@"itms-apps://itunes.com/app/%@", [self sanitizeAppStoreResourceSpecifier:bundleName]]];
        return appStoreURL;
    }
    
    + (NSString *)sanitizeAppStoreResourceSpecifier:(NSString *)resourceSpecifier
    {
        /*
         https://developer.apple.com/library/ios/qa/qa1633/_index.html
         To create an App Store Short Link, apply the following rules to your company or app name:
    
         Remove all whitespace
         Convert all characters to lower-case
         Remove all copyright (©), trademark (™) and registered mark (®) symbols
         Replace ampersands ("&") with "and"
         Remove most punctuation (See Listing 2 for the set)
         Replace accented and other "decorated" characters (ü, å, etc.) with their elemental character (u, a, etc.)
         Leave all other characters as-is.
         */
        resourceSpecifier = [resourceSpecifier stringByReplacingOccurrencesOfString:@"&" withString:@"and"];
        resourceSpecifier = [[NSString alloc] initWithData:[resourceSpecifier dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES] encoding:NSASCIIStringEncoding];
        resourceSpecifier = [resourceSpecifier stringByReplacingOccurrencesOfString:@"[!¡\"#$%'()*+,-./:;<=>¿?@\\[\\]\\^_`{|}~\\s\\t\\n]" withString:@"" options:NSRegularExpressionSearch range:NSMakeRange(0, resourceSpecifier.length)];
        resourceSpecifier = [resourceSpecifier lowercaseString];
        return resourceSpecifier;
    }
    

    通过这个测试

    - (void)testAppStoreURLFromBundleName
    {
        STAssertEqualObjects([AGApplicationHelper appStoreURLFromBundleName:@"Nuclear™"].absoluteString, @"itms-apps://itunes.com/app/nuclear", nil);
        STAssertEqualObjects([AGApplicationHelper appStoreURLFromBundleName:@"Magazine+"].absoluteString, @"itms-apps://itunes.com/app/magazine", nil);
        STAssertEqualObjects([AGApplicationHelper appStoreURLFromBundleName:@"Karl & CO"].absoluteString, @"itms-apps://itunes.com/app/karlandco", nil);
        STAssertEqualObjects([AGApplicationHelper appStoreURLFromBundleName:@"[Fluppy fuck]"].absoluteString, @"itms-apps://itunes.com/app/fluppyfuck", nil);
        STAssertEqualObjects([AGApplicationHelper appStoreURLFromBundleName:@"Pollos Hérmanos"].absoluteString, @"itms-apps://itunes.com/app/polloshermanos", nil);
        STAssertEqualObjects([AGApplicationHelper appStoreURLFromBundleName:@"Niños and niñas"].absoluteString, @"itms-apps://itunes.com/app/ninosandninas", nil);
        STAssertEqualObjects([AGApplicationHelper appStoreURLFromBundleName:@"Trond, MobizMag"].absoluteString, @"itms-apps://itunes.com/app/trondmobizmag", nil);
        STAssertEqualObjects([AGApplicationHelper appStoreURLFromBundleName:@"!__SPECIAL-PLIZES__!"].absoluteString, @"itms-apps://itunes.com/app/specialplizes", nil);
    }
    
  • 11

    根据Apple's latest document你需要使用

    appStoreLink = "https://itunes.apple.com/us/app/apple-store/id375380948?mt=8"
    

    要么

    SKStoreProductViewController
    
  • 8

    试试这种方式

    http://itunes.apple.com/lookup?id= "your app ID here"返回json.From这个,找到键“ trackViewUrl ”和value是所需的url . 使用这个网址(只需用 itms-apps:// 替换 https:// ) . 这很好用 .

    例如,如果您的应用ID是xyz,请转到此链接http://itunes.apple.com/lookup?id=xyz

    然后找到关键字“ trackViewUrl ”的网址 . 这是您的应用商店应用的网址,并在xcode中使用此网址尝试此操作

    NSString *iTunesLink = @"itms-apps://itunes.apple.com/us/app/Your app name/id Your app ID?mt=8&uo=4";
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:iTunesLink]];
    

    谢谢

  • 29

    尽管这里有大量的答案,但链接到开发人员应用程序的建议似乎都不再适用 .

    当我上次访问时,我能够使用以下格式使其工作:

    itms-apps://itunes.apple.com/developer/developer-name/id123456789
    

    这不再有效,但删除开发人员名称会:

    itms-apps://itunes.apple.com/developer/id123456789
    

相关问题