如何连接到我的应用程序商店(iTunes)?

时间:2021-08-18 07:32:00

I want to have a feature in my app where the user can send an email to a friend with the iTunes URL to my application. How is it possible?

我希望在我的应用程序中有一个功能,用户可以通过iTunes URL向我的应用程序发送电子邮件。怎么可能?

Thanks.

谢谢。

5 个解决方案

#1


46  

Rather than the long and confusing urls that you usually see, you can create App Store links that are much simpler and more logical. The iTunes Store has a hidden URL format that’s much more logical. Depending on what you’re linking to, you just need to build a URL in one of these formats:

您可以创建更简单、更符合逻辑的App Store链接,而不是通常看到的冗长而混乱的url。iTunes商店有一种隐藏的URL格式,更符合逻辑。根据你所链接的内容,你只需要在以下格式中建立一个URL:

  1. Artist’s name or App Store developer’s name: http://itunes.com/Artist_Or_Developer_Name
  2. 艺术家的名字或应用程序商店开发者的名字:http://itunes.com/Artist_Or_Developer_Name。
  3. Album name: http://itunes.com/Artist_Name/Album_Name
  4. 专辑名称:http://itunes.com/Artist_Name/Album_Name
  5. Apps: http://itunes.com/app/App_Name
  6. 应用程序:http://itunes.com/app/App_Name
  7. Movies: http://itunes.com/movie/Movie_Title
  8. 电影:http://itunes.com/movie/Movie_Title
  9. TV: http://itunes.com/tv/Show_Title
  10. 电视:http://itunes.com/tv/Show_Title

Just include a url of this format in the body of the email you create.

只要在你创建的电子邮件正文中包含这个格式的url。

(Note that spaces might cause problems, but I found that omitting them entirely worked for me - http://itunes.com/app/FrootGroove redirects to the app called "Froot Groove".)

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

(Also note that if this doesn't work for you, the iTunes link maker is here)

(也要注意,如果这对你不起作用,iTunes链接器就在这里)

Your code will be something like this (extracted from mine, anonymised and not tested)

您的代码将是这样的(从我的代码中提取,匿名并没有测试)

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

You can do better things in iPhone 3.0, but I can't talk about those yet.

你可以在iphone3.0中做更好的事情,但是我还不能说。

#2


4  

In OS 3.0 you can use the MessageUI framework to do this without leaving the app (using Jane's code as the fallback for pre-3.0 devices):

在OS 3.0中,你可以使用MessageUI框架来实现这一点,而不用离开应用程序(使用Jane的代码作为pre-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];
}

Note that your class must adopt the MFMailComposeViewControllerDelegate protocol. You can also include attachments, use HTML in the body, and more.

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

#3


3  

You can now use appstore.com/APP_NAME to launch an app in iTunes. This works on the desktop and on iOS devices. This is not as reliable as other methods however. See answer here How to create vanity url for apple appStore?

现在可以使用appstore.com/APP_NAME在iTunes中启动一个应用程序。这适用于桌面和iOS设备。然而,这并不像其他方法那样可靠。在这里可以看到如何创建苹果appStore的虚荣心url ?

#4


1  

This code generates the app store link automatically based on the app name, nothing else is required, drag & drop:

此代码根据app名称自动生成app store链接,不需要其他任何东西,拖放:

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

It gives you a link like http://itunes.com/app/angrybirds

它会给你一个链接,比如http://itunes.com/app/angrybirds

#5


0  

By the way, the link to the application by its ID can be found by visiting the Apps Store for your application and clicking on the "Tell A Friend" -- then send an email to yourself. I found this to be very informative.

顺便说一下,通过ID连接到应用程序的链接可以通过访问应用程序商店找到,点击“告诉一个朋友”——然后给自己发一封邮件。我发现这是非常有用的。

#1


46  

Rather than the long and confusing urls that you usually see, you can create App Store links that are much simpler and more logical. The iTunes Store has a hidden URL format that’s much more logical. Depending on what you’re linking to, you just need to build a URL in one of these formats:

您可以创建更简单、更符合逻辑的App Store链接,而不是通常看到的冗长而混乱的url。iTunes商店有一种隐藏的URL格式,更符合逻辑。根据你所链接的内容,你只需要在以下格式中建立一个URL:

  1. Artist’s name or App Store developer’s name: http://itunes.com/Artist_Or_Developer_Name
  2. 艺术家的名字或应用程序商店开发者的名字:http://itunes.com/Artist_Or_Developer_Name。
  3. Album name: http://itunes.com/Artist_Name/Album_Name
  4. 专辑名称:http://itunes.com/Artist_Name/Album_Name
  5. Apps: http://itunes.com/app/App_Name
  6. 应用程序:http://itunes.com/app/App_Name
  7. Movies: http://itunes.com/movie/Movie_Title
  8. 电影:http://itunes.com/movie/Movie_Title
  9. TV: http://itunes.com/tv/Show_Title
  10. 电视:http://itunes.com/tv/Show_Title

Just include a url of this format in the body of the email you create.

只要在你创建的电子邮件正文中包含这个格式的url。

(Note that spaces might cause problems, but I found that omitting them entirely worked for me - http://itunes.com/app/FrootGroove redirects to the app called "Froot Groove".)

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

(Also note that if this doesn't work for you, the iTunes link maker is here)

(也要注意,如果这对你不起作用,iTunes链接器就在这里)

Your code will be something like this (extracted from mine, anonymised and not tested)

您的代码将是这样的(从我的代码中提取,匿名并没有测试)

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

You can do better things in iPhone 3.0, but I can't talk about those yet.

你可以在iphone3.0中做更好的事情,但是我还不能说。

#2


4  

In OS 3.0 you can use the MessageUI framework to do this without leaving the app (using Jane's code as the fallback for pre-3.0 devices):

在OS 3.0中,你可以使用MessageUI框架来实现这一点,而不用离开应用程序(使用Jane的代码作为pre-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];
}

Note that your class must adopt the MFMailComposeViewControllerDelegate protocol. You can also include attachments, use HTML in the body, and more.

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

#3


3  

You can now use appstore.com/APP_NAME to launch an app in iTunes. This works on the desktop and on iOS devices. This is not as reliable as other methods however. See answer here How to create vanity url for apple appStore?

现在可以使用appstore.com/APP_NAME在iTunes中启动一个应用程序。这适用于桌面和iOS设备。然而,这并不像其他方法那样可靠。在这里可以看到如何创建苹果appStore的虚荣心url ?

#4


1  

This code generates the app store link automatically based on the app name, nothing else is required, drag & drop:

此代码根据app名称自动生成app store链接,不需要其他任何东西,拖放:

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

It gives you a link like http://itunes.com/app/angrybirds

它会给你一个链接,比如http://itunes.com/app/angrybirds

#5


0  

By the way, the link to the application by its ID can be found by visiting the Apps Store for your application and clicking on the "Tell A Friend" -- then send an email to yourself. I found this to be very informative.

顺便说一下,通过ID连接到应用程序的链接可以通过访问应用程序商店找到,点击“告诉一个朋友”——然后给自己发一封邮件。我发现这是非常有用的。