我如何链接到我的应用程序在App Store(iTunes)?

我想在我的应用程序中有一个function,用户可以通过iTunes URL将电子邮件发送给我的应用程序。 这怎么可能?

谢谢。

您可以创build更简单,更合乎逻辑的App Store链接,而不是通常看到的漫长而迷惑的url。 iTunes商店有一个隐藏的URL格式,更合乎逻辑。 根据您链接到的内容,您只需要使用以下格式之一构buildurl:

  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

只需在您创build的电子邮件正文中包含此格式的url即可。

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

(另外请注意,如果这不适合你,iTunes链接制造商在这里 )

你的代码将是这样的(从我的提取,匿名和未经testing)

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中做更好的事情,但我不能谈论这些。

在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,等等。

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

此代码根据应用程序名称自动生成应用程序商店链接 ,不需要其他任何东西, 拖放

 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的链&#x63A5;

顺便说一下,通过访问您的应用程序的应用程序商店,并点击“告诉朋友”,然后发送一封电子邮件给自己,可以find通过其ID的应用程序的链接。 我发现这是非常丰富的。