我希望在我的应用中有一个功能,用户可以通过iTunes URL将电子邮件发送给我的应用程序。怎么可能?
感谢。
答案 0 :(得分:47)
您可以创建更简单,更符合逻辑的App Store链接,而不是您经常看到的长而混乱的网址。 iTunes Store有一个隐藏的URL格式,更合乎逻辑。根据您要链接的内容,您只需要使用以下格式之一构建URL:
只需在您创建的电子邮件正文中包含此格式的网址。
(请注意,空格可能会导致问题,但我发现省略它们完全适用于我 - 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中做得更好,但我还不能谈论那些。
答案 1 :(得分:4)
在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等。
答案 2 :(得分:3)
您现在可以使用appstore.com/APP_NAME在iTunes中启动应用。这适用于桌面和iOS设备。然而,这并不像其他方法那样可靠。请在此处查看答案How to create vanity url for apple appStore?
答案 3 :(得分:1)
此代码根据应用名称自动生成应用商店链接,不需要其他任何内容,拖放&amp;降强>:
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);
之类的链接
答案 4 :(得分:0)
顺便说一句,可以通过访问应用程序的Apps Store并点击“告诉朋友”找到其ID的应用程序链接 - 然后发送电子邮件给自己。我发现这是非常有用的。