2011-05-04 37 views
0

我需要打开链接那种“http://www.web.com/?text=link =)http://google.ru是goooooood”打开Safari使用NSURL网站链接进去可变

[email protected]"http://www.web.com/?text=link+=)+http://google.ru+is+goooooood"; 
twitter=[NSURL URLWithString:message]; 
[[UIApplication sharedApplication] openURL:twitter]; 

但它不没有工作。 safari打开链接:“http://www.web.com/?text=link =)”。 但我需要所有文字。 任何想法?

回答

0

你应该URL编码的参数(在你的patameters特殊字符),可以使用下面的函数来URL编码

- (NSString *)stringByURLEncode:(NSString *)param { 

    NSMutableString *tempStr = [NSMutableString stringWithString:param]; 
    [tempStr replaceOccurrencesOfString:@" " withString:@"+" options:NSCaseInsensitiveSearch range:NSMakeRange(0, [tempStr length])]; 


    return [[NSString stringWithFormat:@"%@",tempStr] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 

} 

您的消息变量应该是这个样子 -

message=[NSString stringWithFormat:@"http://www.web.com/?text=%@",[self stringByURLEncode:@"link+=)+http://google.ru+is+goooooood"]];