27

私のアプリに、ユーザーが私のアプリケーションのiTunesURLを使用して友人にメールを送信できる機能が必要です。どうしてそれは可能ですか?

ありがとう。

4

5 に答える 5

47

通常見られる長くて紛らわしい URL ではなく、よりシンプルで論理的な App Store リンクを作成できます。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

作成するメールの本文にこの形式の URL を含めるだけです。

(スペースは問題を引き起こす可能性があることに注意してください。ただし、それらを完全に省略してもうまくいくことがわかりました-http ://itunes.com/app/FrootGrooveは「Froot Groove」というアプリにリダイレクトします。)

(また、これがうまくいかない場合は、iTunes リンク メーカーがここにあります) 。

あなたのコードはこのようなものになります(私のものから抽出され、匿名化され、テストされていません)

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 ではもっと良いことができますが、それについてはまだお話しできません。

于 2009-05-04T07:05:31.733 に答える
4

OS 3.0では、MessageUIフレームワークを使用して、アプリを終了せずにこれを行うことができます(3.0より前のデバイスのフォールバックとしてJaneのコードを使用)。

- (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を使用したりすることもできます。

于 2009-07-10T17:37:34.500 に答える
3

appstore.com/APP_NAME を使用して、iTunes でアプリを起動できるようになりました。これは、デスクトップおよび iOS デバイスで機能します。ただし、これは他の方法ほど信頼性が高くありません。こちらの回答を参照してくださいApple appStore のバニティ URL を作成する方法は?

于 2013-02-11T19:54:13.273 に答える
1

このコードは、アプリ名に基づいてアプリ ストア リンクを自動的に生成します。他には何も必要ありません。ドラッグ アンド ドロップします

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のようなリンクが表示されます

于 2012-03-07T06:05:03.740 に答える
0

ところで、ID によるアプリケーションへのリンクは、アプリケーションの App Store にアクセスし、[友達に教える] をクリックして見つけることができます。その後、自分自身にメールを送信します。これは非常に有益であることがわかりました。

于 2012-01-19T16:20:27.493 に答える