Search code examples
iphoneobjective-cios4itunes

how to open itunes link in iphone app?


I am trying to open itunes link on UIControlEventTouchDown button press event. My code is as follows.

    NSString *urlString =@"http://itunes.apple.com/in/album/carnatic-vocal-sanjay-subrahmanyan/id106924807?ign-mpt=uo%3D4";


    NSString *str_ur=[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

    NSURL *url=[NSURL URLWithString:str_ur];

    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
    [webview_buy loadRequest:requestObj];

    webview_buy.delegate=self;

    [self.view addSubview:webview_buy];

This will go to itunes in the device and open the itunes store. But i get an alert message that says

Your Request could not be Completed.

Please give idea with code.


Solution

  • First copy the url from iTunes which you want to open in app.

    Then use below code:

    [[UIApplication sharedApplication] 
         openURL:[NSURL URLWithString:@"http://itunes.apple.com/in/album/carnatic-vocal-sanjay-subrahmanyan/id106924807?ign-mpt=uo%3D4"]];
    

    here, URLWithString value will be your app url which you want to open.

    Let me know in case of any difficulty.