【问题标题】:How can I link to my app in the App Store (iTunes)?如何在 App Store (iTunes) 中链接到我的应用程序?
【发布时间】:2009-05-04 06:17:32
【问题描述】:

我想在我的应用程序中添加一项功能,用户可以通过该功能向朋友发送电子邮件,其中包含指向我的应用程序的 iTunes URL。怎么可能?

谢谢。

【问题讨论】:

    标签: iphone ios app-store


    【解决方案1】:

    您可以创建更简单、更合乎逻辑的 App Store 链接,而不是您通常看到的冗长且令人困惑的 url。 iTunes Store 有一个更符合逻辑的隐藏 URL 格式。根据您要链接的内容,您只需使用以下格式之一构建 URL:

    1. 艺术家姓名或 App Store 开发者姓名:http://itunes.com/Artist_Or_Developer_Name
    2. 专辑名称:http://itunes.com/Artist_Name/Album_Name
    3. 应用程序:http://itunes.com/app/App_Name
    4. 电影:http://itunes.com/movie/Movie_Title
    5. 电视:http://itunes.com/tv/Show_Title

    只需在您创建的电子邮件正文中包含这种格式的网址即可。

    (请注意,空格可能会导致问题,但我发现省略它们完全适合我 - http://itunes.com/app/FrootGroove 重定向到名为“Froot Groove”的应用程序。)

    (另请注意,如果这对您不起作用,iTunes 链接制造商是here

    您的代码将是这样的(从我的中提取,匿名且未经测试)

    NSString* body = [NSString stringWithFormat:@"Get my app here - %@.\n",myUrl];
    
    #if __IPHONE_OS_VERSION_MIN_REQUIRED <= __IPHONE_2_2
    [NSThread sleepForTimeInterval:1.0];
    NSString* crlfBody = [body stringByReplacingOccurrencesOfString:@"\n" withString:@"\r\n"];
    NSString* escapedBody = [(NSString*)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,  (CFStringRef)crlfBody, NULL,  CFSTR("?=&+"), kCFStringEncodingUTF8) autorelease];
    
    NSString *mailtoPrefix = [@"mailto:xxx@wibble.com?subject=Get my app&body=" stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    // Finally, combine to create the fully escaped URL string
    NSString *mailtoStr = [mailtoPrefix stringByAppendingString:escapedBody];
    
    // And let the application open the merged URL
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:mailtoStr]];
    #endif
    

    你可以在 iPhone 3.0 中做更好的事情,但我还不能谈论这些。

    【讨论】:

    • 哇,我不知道你能做到这一点。感谢这篇文章!
    • 一个快速的问题 - 如果我的应用程序显示名称(在 info.plist 中)和 iTunes 名称(在 iTunes Connect 中指定)不同,我应该在 URL 中使用哪一个?再次感谢
    • 我不确定,但怀疑 iTunes 名称。
    • 那么 OS 3.0 中的新功能是什么?
    • 这确实有效,但它似乎重定向到搜索。如果您是该搜索的唯一匹配项,那么您就是黄金。如果没有,很遗憾没有。
    【解决方案2】:

    在 OS 3.0 中,您可以使用 MessageUI 框架来执行此操作而无需离开应用程序(使用 Jane 的代码作为 3.0 之前设备的后备):

    - (void)sendEmail
    {
        NSString* body = [NSString stringWithFormat:@"Get my app here - %@.\n",myUrl];
    
    #if __IPHONE_OS_VERSION_MIN_REQUIRED <= __IPHONE_2_2
        Class mailClass = (NSClassFromString(@"MFMailComposeViewController"));
        if (mailClass != nil && [mailClass canSendMail])
        {
            MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
            picker.mailComposeDelegate = self;
            picker.subject = @"Get my app";
            [picker setToRecipients:[NSArray arrayWithObject:@"xxx@wibble.com"];
            [picker setMessageBody:body isHTML:NO];
    
            [self presentModalViewController:picker animated:NO];
            [picker release];
        } else {
            [NSThread sleepForTimeInterval:1.0];
            NSString* crlfBody = [body stringByReplacingOccurrencesOfString:@"\n" withString:@"\r\n"];
            NSString* escapedBody = [(NSString*)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,  (CFStringRef)crlfBody, NULL,  CFSTR("?=&+"), kCFStringEncodingUTF8) autorelease];
    
            NSString *mailtoPrefix = [@"mailto:xxx@wibble.com?subject=Get my app&body=" stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
            // Finally, combine to create the fully escaped URL string
            NSString *mailtoStr = [mailtoPrefix stringByAppendingString:escapedBody];
    
            // And let the application open the merged URL
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:mailtoStr]];
        }
    #endif
    }
    
    #pragma mark -
    #pragma mark Mail Composer Delegate
    - (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error 
    {
        if (result == MFMailComposeResultFailed) {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:[error localizedDescription] message:[error localizedFailureReason] delegate:nil cancelButtonTitle:NSLocalizedString(@"OK", @"OK") otherButtonTitles:nil];
            [alert show];
            [alert release];
        }
        [self dismissModalViewControllerAnimated:YES];
    }
    

    请注意,您的班级必须采用MFMailComposeViewControllerDelegate 协议。您还可以包含附件、在正文中使用 HTML 等等。

    【讨论】:

      【解决方案3】:

      您现在可以使用 appstore.com/APP_NAME 在 iTunes 中启动应用程序。这适用于桌面和 iOS 设备。然而,这不像其他方法那样可靠。在这里查看答案How to create vanity url for apple appStore?

      【讨论】:

        【解决方案4】:

        此代码根据应用名称自动生成应用商店链接,无需其他任何内容,拖放

        NSCharacterSet *trimSet = [[NSCharacterSet characterSetWithCharactersInString:@"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLKMNOPQRSTUVWXYZ0123456789"] invertedSet];    
        NSArray *trimmedAppname = [[NSString stringWithString:[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"]] componentsSeparatedByCharactersInSet:trimSet];
        NSString *appStoreLink = @"http://itunes.com/app/"; 
        for (NSString *part in trimmedAppname) appStoreLink = [NSString stringWithFormat:@"%@%@",appStoreLink,part];
        NSLog(@"App store URL:%@",appStoreLink);
        

        它会给你一个类似http://itunes.com/app/angrybirds的链接

        【讨论】:

        • 你不能只这样做。 Apple 还将所有特殊字符(如撇号、逗号、& 符号等)替换为连字符
        • 好点,我没有这些唯一的空间。但是对于大多数情况,可以从应用名称中提取 URL,而无需知道应用 ID 或其他任何内容。有机会我会更新代码。这个应该适用于大多数人,但不是所有人。
        • 我更新了代码,它应该过滤掉所有非字母数字字符。感谢您的提示!
        【解决方案5】:

        顺便说一句,通过访问您的应用程序的应用商店并单击“告诉朋友”,可以找到按 ID 指向应用程序的链接,然后向您自己发送一封电子邮件。我发现这非常有用。

        【讨论】:

        • 或者在 iTunes(桌面应用)中右击应用名称并复制链接。这也给了你链接:)
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-03-28
        • 2011-05-15
        • 2014-10-23
        • 2015-09-06
        相关资源
        最近更新 更多