Insert “Download on iTunes” button in app

左心房为你撑大大i 提交于 2019-12-20 04:19:09

问题


My app shows the title of a certain song and I would like to insert a "Download on iTunes" button that open iTunes on my iPhone pointing to my song. I've retrieved the correct iTunes url, using the iTunes Link Maker but I've two questions for you.

  • In which way can I add this button to my UIView? Do I have to insert a standard button? Which method do I have to call?
  • Is it possible to dynamically compose the iTunes url?

I've tried to implement the following method:

- (void) openItunes
{
    NSString *iTunesLink = selectedAlbum.itunesLink;
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:iTunesLink]];
}

with iTunesLink like itms://itunes.apple.com/it/album/.... If I launch this url with Safari, iTunes is automatically opened focusing on the right song. But if I invoke the openItunes method from simulator or iPad Touch nothing happens. Any ideas?

Regards, yassa


回答1:


Finally this worked for me:

- (IBAction)buyAlbum:(id)sender
{
    NSString* url = @"itms://itunes.apple.com/it/album/love-life-lamore-e-la-vita/id298792107?uo=4";

    [[UIApplication sharedApplication] openURL: [NSURL URLWithString: url ]];
}

yassa



来源:https://stackoverflow.com/questions/8647003/insert-download-on-itunes-button-in-app

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!