2013-10-05 137 views
1

我想要獲得電影標題的亞馬遜搜索,但是在使用該網址時遇到問題。電影名稱會插入到帶有'%@'的鏈接中,但多餘的'%'會導致問題。任何幫助,將不勝感激。ios網址問題

錯誤:

More '%' conversions than data arguments 
Format specifies type 'int' but the argument has type 'NSString *' 

這裏是我的代碼:

- (void)jumpToAmazon:(id)sender { 
    // create the string that points to the correct Amazon page for the game name 
    NSString *amazonPageString = [NSString stringWithFormat:@"http://www.amazon.com/s/ref=nb_sb_noss_1?url=search-alias%3Dmovies-tv&field-keywords=%@&sprefix=friend%2Cmovies-tv&rh=i%3Amovies-tv%2Ck%3A%@", self.movie.name, self.movie.name]; 
    if (![[UIApplication sharedApplication] openURL:[NSURL URLWithString:amazonPageString]]) 
    { 
     // there was an error trying to open the URL. for the moment we'll simply ignore it. 
    } 
} 

回答

2

加倍字面百分比如下:

[NSString stringWithFormat: 
@"http://www.amazon.com/s/ref=nb_sb_noss_1?url=search-alias%%3Dmovies-tv&field-keywords=%@&sprefix=friend%%2Cmovies-tv&rh=i%%3Amovies-tv%%2Ck%%3A%@", 
self.movie.name, self.movie.name]; 
2

使用%%當你想要一個實際的百分號出現的字符串中。

1

在URL中url=search-alias%3Dmovies-tv當場你需要添加另一個%標誌,以使它看起來像url=search-alias%%3Dmovies-tvfriend%2Cmovies-tv&rh=i%3Amovies-tv%2Ck%3也是如此,您需要將其更改爲friend%%2Cmovies-tv&rh=i%%3Amovies-tv%%2Ck%%3以便打印百分號。