App Store(iTunes)で自分のアプリにリンクするにはどうすればよいですか?

StackOverflow https://stackoverflow.com/questions/818973

  •  03-07-2019
  •  | 
  •  

質問

ユーザーが自分のアプリケーションのiTunes URLをメールで友人に送信できる機能をアプリに追加したい。どうして可能ですか?

ありがとう。

役に立ちましたか?

解決

通常表示される長くてわかりにくい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. TV: 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ではより良いことをすることができますが、それらについてはまだ話せません。

他のヒント

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デバイスで機能します。ただし、これは他の方法ほど信頼性がありません。こちらの回答をご覧ください Apple AppStoreのバニティURLを作成する方法

このコードは、アプリ名に基づいてアプリストアリンクを自動的に生成します。他には何も必要ありません。ドラッグ&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);

http://itunes.com/app/angrybirds

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

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top