如何在应用商店中链接到应用程序

762

我正在制作我的iPhone游戏的免费版本。我想在免费版本中放置一个按钮,可以将人们带到应用商店中的付费版本。如果我使用标准链接

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

iPhone首先会打开Safari,然后再进入应用商店。我已经使用过其他应用程序,它们可以直接打开应用商店,所以我知道这是可能的。

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


1
对于 SWIFT 3.X 和本地化应用程序,这个答案可能会有所帮助:https://dev59.com/3XA75IYBdhLWcg3wv77A#41765175 - LukeSideWalker
27个回答

4
尽管这里有很多答案,但是似乎没有任何一种链接到开发者应用的建议还能够正常工作。我最近访问时,曾使用以下格式使之运作起来:
itms-apps://itunes.apple.com/developer/developer-name/id123456789

这个方法已经不再适用,但是删除开发者名称可以解决问题:

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

4

至少需要iOS 9及以上版本

  • 可以直接在App Store中打开

一款应用程序

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

开发人员应用程序列表

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

appName 不是必需的。 - DawnSong

3
这里的大部分解决方案都已经过时和废弃了。
对于那些寻找最新可行解决方案的人。
// let appStoreLink = "https://apps.apple.com/app/{app-name}/{app-id}"

guard let url = URL(string: Constants.App.appStoreLink) else { return }
UIApplication.shared.open(url)

1
这在2023年对我来说似乎有效。似乎所有之前不包括应用程序ID的方法都不再起作用。在Mac上使用itms-apps://apps.apple.com/app/{app-name}/{app-id}后缀也可以工作,并且可能会减少浏览器中的负载。 - mobob

3

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

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

如果您没有应用程序商店ID,可以根据此文档创建一个基于URL的链接: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);
}

1
它将直接打开App Store。
NSString *iTunesLink = @"itms-apps://itunes.apple.com/app/ebl- 
skybanking/id1171655193?mt=8";

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:iTunesLink]];

0

在SwiftUI - IOS 15.0中

//
//  Test.swift
//  PharmaCodex
//

import SwiftUI

struct Test: View {
    
    var body: some View {
        
        VStack {
            
            Button(action: {
                guard let writeReviewURL = URL(string: "https://apps.apple.com/app/id1629135515?action=write-review") else {
                    fatalError("Expected a valid URL")
                }
                UIApplication.shared.open(writeReviewURL, options: [:], completionHandler: nil)
                
            }) {
                Text("Rate/Review")
            }
            
            
        }
    }
}

struct Test_Previews: PreviewProvider {
    static var previews: some View {
        Test()
    }
}

0

尝试这种方式

http://itunes.apple.com/lookup?id="在此处输入您的应用程序ID"返回json。从中找到键“trackViewUrl”,其值是所需的URL。使用此URL(只需将https://替换为itms-apps://)。这很有效。

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

然后找到键“trackViewUrl”的URL。这是您的应用程序在应用商店中的URL,要在Xcode中使用此URL,请尝试以下操作

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

谢谢


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接