关于ios:如何链接到应用商店中的应用

How to link to apps on the app store

我正在创建我的iPhone游戏的免费版本。我想在免费版本中有一个按钮,可以让人们进入应用商店的付费版本。如果我使用标准链接

http://itunes.apple.com/webobjects/mzstore.woa/wa/viewsoftware?ID=300136119&MT=8

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

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


编辑日期:2016-02-02

从iOS 6开始,引入了skstoreproductviewcontroller类。你可以在不离开应用程序的情况下链接应用程序。这里是Swift 3.x/2.x和Objective-C中的代码段。

A SKStoreProductViewController object presents a store that allows the
user to purchase other media from the App Store. For example, your app
might display the store to allow the user to purchase another app.

来自苹果开发者的新闻和公告。

Drive Customers Directly to Your App
on the App Store with iTunes Links
With iTunes links you can provide your
customers with an easy way to access
your apps on the App Store directly
from your website or marketing
campaigns. Creating an iTunes link is
simple and can be made to direct
customers to either a single app, all
your apps, or to a specific app with
your company name specified.

To send customers to a specific
application:
http://itunes.com/apps/appname

To send
customers to a list of apps you have
on the App Store:
http://itunes.com/apps/developername

To send customers to a specific app
with your company name included in the
URL:
http://itunes.com/apps/developername/appname

附加说明:

您可以用itms://itms-apps://替换http://以避免重定向。

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

https://developer.apple.com/library/content/qa/qa1633//u index.html。

编辑(截至2015年1月):

iTunes.com/apps链接应更新为appstore.com/apps。见上述QA1633,已更新。新的QA1629建议从应用程序启动商店的步骤和代码:

  • 在计算机上启动iTunes。
  • 搜索要链接到的项目。
  • 右键单击或控制单击iTunes中项目的名称,然后从弹出菜单中选择"复制iTunes存储URL"。
  • 在应用程序中,使用复制的iTunes URL创建一个NSURL对象,然后将该对象传递给UIApplicationopenURL方法,以便在应用程序存储中打开您的项目。
  • 样例代码:

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

    斯威夫特3

    1
    2
    3
    4
    5
    6
    7
       let urlStr ="itms://itunes.apple.com/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)!)
        }


    如果要直接打开应用程序到应用程序商店,应使用:

    ITMS应用程序:/ /…

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

    希望有帮助。

    编辑:2017年4月。iTMS应用程序:/,实际上在iOS10中再次有效。我测试了它。

    编辑:2013年4月。这不再适用于ios5及更高版本。只使用

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

    而且没有更多的重定向。


    从iOS6开始,使用skstoreProductViewController类是正确的方法。

    斯威夫特3×:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    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")

    You can get the app's itunes item identifier like this: (instead of a static one)

    斯威夫特3.2

    1
    2
    3
    4
    5
    6
    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)

    斯威夫特2×:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    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")

    ObjultC:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    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];
    }

    You can get kAppITunesItemIdentifier (app's itunes item identifier) like this: (instead of a static one)

    1
    2
    3
    4
    5
    6
    7
    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]];


    2015年夏季以后…

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

    将"ID1234567890"替换为"ID"和"您的十位数"

  • 这在所有设备上都能很好地工作。

  • 它直接进入应用程序商店,没有重定向。

  • 所有国家商店都可以。

  • 的确,你应该转向使用loadProductWithParameters,但是如果链接的目的是更新你实际使用的应用程序:使用这种"老式"方法可能更好。


  • 苹果刚刚公布了appstore.com的网址。

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

    There are three types of App Store Short Links, in two forms, one for iOS apps, another for Mac Apps:

    Company Name

    iOS: http://appstore.com/ for example, http://appstore.com/apple

    Mac: http://appstore.com/mac/ for example, http://appstore.com/mac/apple

    App Name

    iOS: http://appstore.com/ for example, http://appstore.com/keynote

    Mac: http://appstore.com/mac/ for example, http://appstore.com/mac/keynote

    App by Company

    iOS: http://appstore.com// for example, http://appstore.com/apple/keynote

    Mac: http://appstore.com/mac// for example, http://appstore.com/mac/apple/keynote

    Most companies and apps have a canonical App Store Short Link. This canonical URL is created by changing or removing certain characters (many of which are illegal or have special meaning in a URL (for example,"&")).

    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.

    Listing 2 Punctuation characters that must be removed.

    !?"#$%'()*+,-./:;<=>??@[]^_`{|}~

    Below are some examples to demonstrate the conversion that takes place.

    App Store

    Company Name examples

    Gameloft => http://appstore.com/gameloft

    Activision Publishing, Inc. => http://appstore.com/activisionpublishinginc

    Chen's Photography & Software => http://appstore.com/chensphotographyandsoftware

    App Name examples

    Ocarina => http://appstore.com/ocarina

    Where’s My Perry? => http://appstore.com/wheresmyperry

    Brain Challenge? => http://appstore.com/brainchallenge


    此代码在iOS上生成应用商店链接

    1
    2
    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应用程序:

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

    在iOS上打开URL:

    1
    [[UIApplication sharedApplication] openURL:appStoreURL];

    雨衣:

    1
    [[NSWorkspace sharedWorkspace] openURL:appStoreURL];


    只需在应用程序链接中将"itunes"更改为"phobos"。

    http://phobos.apple.com/webobjects/mzstore.woa/wa/viewsoftware?ID=300136119&MT=8

    现在它将直接打开应用商店


    要在不重定向的情况下拥有直接链接,请执行以下操作:

  • 使用itunes link maker http://itunes.apple.com/linkmaker/获取真正的直接链接
  • itms-apps://替换http://
  • [[UIApplication sharedApplication] openURL:url];打开链接
  • 注意,这些链接只在实际设备上工作,而不是在模拟器中。

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


    这对我来说非常有效,只使用app id:

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

    重定向次数为零。


    许多答案建议使用"itms"或"itms应用程序",但苹果并未特别推荐这种做法。他们只提供以下方式打开应用商店:

    清单1从iOS应用程序启动app store

    1
    2
    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/u index.html,自2014年3月起更新。

    对于支持iOS 6及更高版本的应用程序,苹果提供了一种应用程序内机制来展示应用程序商店:SKStoreProductViewController

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    - (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
    }];

    请注意,在IO6上,如果存在错误,则不能调用完成块。这似乎是一个在iOS7中解决的错误。


    如果要链接到开发人员的应用程序,并且开发人员的名称带有标点符号或空格(例如,Development Company,LLC),请按如下方式设置URL:

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

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


    您可以通过链接制作器在应用商店或iTunes中获取特定项目的链接,网址为:http://itunes.apple.com/linkmaker/


    这在IO5中起作用并直接链接

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

    这是在应用商店中重定向/链接其他现有应用程序的简单快捷的方法。

    1
    2
    3
    4
    5
    6
     NSString *customURL = @"http://itunes.apple.com/app/id951386316";

     if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:customURL]])
     {
           [[UIApplication sharedApplication] openURL:[NSURL URLWithString:customURL]];
     }


    对于Xcode 9.1和Swift 4:

  • 导入存储套件:
  • 1
    import StoreKit

    2.遵守协议

    1
    SKStoreProductViewControllerDelegate

    3.执行协议

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    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)
            }
        }  
    }

    三点一

    1
    2
    3
    func productViewControllerDidFinish(_ viewController: SKStoreProductViewController) {
        viewController.dismiss(animated: true, completion: nil)
    }
  • 如何使用:
  • 1
    openStoreProductWithiTunesItemIdentifier(identifier:"here_put_your_App_id")

    注:

    It is very important to enter the exact ID of your APP. Because this cause error (not show the error log, but nothing works fine because of this)


    我可以确认,如果您在iTunes Connect中创建了一个应用程序,那么在提交之前,您会先获取您的应用程序ID。

    因此…

    1
    2
    3
    4
    5
    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];

    奏效


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

    有一个名为iLink的开放源码库可以帮助您。

    这个库的优点是可以在运行时找到并创建链接(库将检查运行的应用程序ID和操作系统,并确定应该创建什么链接)。最好的一点是,在使用它之前,您几乎不需要配置任何东西,这样就不会出错,并且可以一直工作。如果你在同一个项目中没有几个目标,所以你不必记住要使用哪个应用ID或链接,那也很好。如果商店中有新版本(内置,通过简单的标志关闭),如果用户同意,此库还将提示用户升级应用程序,直接指向应用程序的升级页面。

    将2个库文件复制到项目(ilink.h&ilink.m)。

    在您的appdelegate.m上:

    1
    2
    3
    4
    5
    6
    7
    #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.
    }

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

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

    别忘了在同一个文件中导入ilink.h。

    那里有一个非常好的文档库,还有一个iPhone和Mac的示例项目。


    至少iOS 9及以上

    • 直接在应用商店中打开

    一个应用程序

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

    开发者应用列表

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

    尽管这里有很多答案,但是链接到开发人员应用程序的所有建议似乎都不再有效。

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

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

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

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


    如果你有应用商店ID,你最好使用它。尤其是如果将来您可能更改应用程序的名称。

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

    如果您没有THA应用商店ID,则可以基于此文档创建一个URL:https://developer.apple.com/library/ios/qa/qa1633//u index.html

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    + (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\
    ]" withString:@"" options:NSRegularExpressionSearch range:NSMakeRange(0, resourceSpecifier.length)];

        resourceSpecifier = [resourceSpecifier lowercaseString];
        return resourceSpecifier;
    }

    通过此测试

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    - (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);
    }

    根据苹果最新的文件你需要使用

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

    1
    SKStoreProductViewController


    试试这个方法

    http://itunes.apple.com/lookup?id="your app id here"返回json。在此,查找键"trackviewurl",value是所需的url。使用这个URL(只需将https://替换为itms-apps://),这样就可以了。

    例如,如果您的应用程序ID是XYZ,则转到此链接http://itunes.apple.com/lookup?ID=XYZ

    然后找到"trackviewurl"键的URL。这是应用程序商店中应用程序的URL,若要在Xcode中使用此URL,请尝试此操作

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

    谢谢