다음 코드를 사용하여 내 앱에서 Twitter를 열었습니다. 작동하는 동안 NSString에 공백을 포함 할 수 없습니다.iOS 앱에서 트위터를 열지 못합니다.
NSString *string1 = [NSString stringWithFormat:@"twitter://post?message=hello+world"];
NSString *string2 = [NSString stringWithFormat:@"http://twitter.com/intent/tweet?text=hello%20world"];
NSURL *twitterURL = [NSURL URLWithString:string1];
NSURL *mobileURL = [NSURL URLWithString:string2];
if ([[UIApplication sharedApplication] canOpenURL:twitterURL])
[[UIApplication sharedApplication] openURL:twitterURL];
else
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:mobileURL]];
코드의 두 부분이 의도 한 상황에서 작동하지만 어떻게 NSURL에 공백을 포함시킬 수 있습니까? 두 번째 코드는 "hello world"대신 "hello2orld"를 인쇄합니다. 또한 + 구분 기호를 사용하지 않으려 고 시도했습니다.
을'+'또는'% 20'이 있습니다 공백을 인코딩하는 두 가지 방법. – rmaddy
이 문자열을 시도해야합니다. stringByAddingPercentEscapesUsingEncoding –