您的位置:首页 > 移动开发

从iPhone应用中启动App Store

2012-12-28 15:55 246 查看

如何从我自己的应用中启动App Store?同时如何链接到商店中我自己的应用?
-[UIApplication openURL:]
可以处理传入的链接到应用和媒体
NSURL
对象,启动对应的商店应用。根据以下步骤获取链接,可以是应用,歌曲,itunes中的专辑,同时链接它到你的iPhone应用。在电脑中启动iTunes搜索你要添加的项目右击或者control点击在iTunes中的项目名称在弹出菜单中循选择"Copy iTunes Store URL"使用
-[UIApplication openURL:]
打开修改的URL字符串和
NSURL
对象。注意:你也可以使用iTunes Link Maker 工具来获取应用歌曲或者保存在iTuns中的专辑的链接。参见iTunes Link Maker FAQ了解更多关于工具的信息。下面是从原生应用中启动App Store的例子。
NSString *iTunesLink = @http://itunes.apple.com/us/app/id284417350?mt=8;
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:iTunesLink]];
有一些iTunes链接,包括iTunes相关链接,在链接到对应的应用程序前会返回多个重定向。你可以使用
NSURLConnection静默的处理这些重定向,并在重定向完成时打开最终的URL。这能够让你的应用支持直接转换到商店而无需启动Safari。下面是展示如何完成这个动作。
注意:如果你的iTunes链接时在UIWebView中你可以使用这个方法在
-[UIWebViewDelegate webView:shouldStartLoadWithRequest:navigationType:]
委托方法中拦截链接。在iPhone中处理iTunes相关的链接
// Process a LinkShare/TradeDoubler/DGM URL to something iPhone can handle
- (void)openReferralURL:(NSURL *)referralURL
{
NSURLConnection *con = [[NSURLConnection alloc] initWithRequest:[NSURLRequest requestWithreferralURL]  delegate:self startImmediately:YES];
[con release];
}
// Save the most recent URL in case multiple redirects occur
// "iTunesURL" is an NSURL property in your class declaration
- (NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)response
{
self.iTunesURL = [response URL];
if( [self.iTunesURL.host hasSuffix:@"itunes.apple.com"])
{
[connection cancel];
[self connectionDidFinishLoading:connection];
return nil;
}
else
{
return request;
}
}
// No more redirects; use the last URL saved
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
[[UIApplication sharedApplication] openself.iTunesURL];< /pre>}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息