Got this code so far for my send button:
到目前为止我的发送按钮有这个代码:
NSString* urlString = [NSString stringWithFormat:@"http://server.com/ios/add.php?user=iPhone+App&message=%@", messageBox.text stringByAddingPercentEscapesUsingEncoding : NSUFT8StringEncoding];
NSURL *add = [NSURL URLWithString:urlString];
However I do get the error "Expected ':'
但是我确实收到错误“预期”:'
5 个解决方案
#1
19
You need to separate the two string construction calls
您需要分开两个字符串构造调用
NSString* urlString = [[NSString stringWithFormat:@"http://server.com/ios/add.php?user=iPhone+App&message=%@", messageBox.text] stringByAddingPercentEscapesUsingEncoding : NSUTF8StringEncoding];
NSURL *add = [NSURL URLWithString:urlString];
#2
7
The proper way is not to escape the entire URL. You should only escape individual parameter values.
正确的方法是不要逃避整个URL。您应该只转义单个参数值。
NSString* urlString = [NSString stringWithFormat:@"http://server.com/ios/add.php?user=iPhone+App&message=%@", [messageBox.text stringByAddingPercentEscapesUsingEncoding : NSUFT8StringEncoding]];
Better yet, for readability and easier debugging, do this:
更好的是,为了便于阅读和调试,请执行以下操作:
NSString *escapedText = [messageBox.text stringByAddingPercentEscapesUsingEncoding:NSUFT8StringEncoding];
NSString* urlString = [NSString stringWithFormat:@"http://server.com/ios/add.php?user=iPhone+App&message=%@", escapedText];
#3
1
Try:
尝试:
NSString* urlString = [[NSString stringWithFormat:@"http://server.com/ios/add.php?user=iPhone+App&message=%@", messageBox.text] stringByAddingPercentEscapesUsingEncoding : NSUFT8StringEncoding];
#4
0
Separate the NSString method to see it clearly:
分离NSString方法以清楚地看到它:
NSString* urlString = [[NSString stringWithFormat:@"http://server.com/ios/add.php?user=iPhone+App&message=%@", messageBox.text] stringByAddingPercentEscapesUsingEncoding : NSUFT8StringEncoding];
#5
-1
NSURL will automatically url encode the string when you call NSURL urlWithString this code is not needed.
当您调用NSURL urlWithString时,NSURL将自动对字符串进行url编码,不需要此代码。
#1
19
You need to separate the two string construction calls
您需要分开两个字符串构造调用
NSString* urlString = [[NSString stringWithFormat:@"http://server.com/ios/add.php?user=iPhone+App&message=%@", messageBox.text] stringByAddingPercentEscapesUsingEncoding : NSUTF8StringEncoding];
NSURL *add = [NSURL URLWithString:urlString];
#2
7
The proper way is not to escape the entire URL. You should only escape individual parameter values.
正确的方法是不要逃避整个URL。您应该只转义单个参数值。
NSString* urlString = [NSString stringWithFormat:@"http://server.com/ios/add.php?user=iPhone+App&message=%@", [messageBox.text stringByAddingPercentEscapesUsingEncoding : NSUFT8StringEncoding]];
Better yet, for readability and easier debugging, do this:
更好的是,为了便于阅读和调试,请执行以下操作:
NSString *escapedText = [messageBox.text stringByAddingPercentEscapesUsingEncoding:NSUFT8StringEncoding];
NSString* urlString = [NSString stringWithFormat:@"http://server.com/ios/add.php?user=iPhone+App&message=%@", escapedText];
#3
1
Try:
尝试:
NSString* urlString = [[NSString stringWithFormat:@"http://server.com/ios/add.php?user=iPhone+App&message=%@", messageBox.text] stringByAddingPercentEscapesUsingEncoding : NSUFT8StringEncoding];
#4
0
Separate the NSString method to see it clearly:
分离NSString方法以清楚地看到它:
NSString* urlString = [[NSString stringWithFormat:@"http://server.com/ios/add.php?user=iPhone+App&message=%@", messageBox.text] stringByAddingPercentEscapesUsingEncoding : NSUFT8StringEncoding];
#5
-1
NSURL will automatically url encode the string when you call NSURL urlWithString this code is not needed.
当您调用NSURL urlWithString时,NSURL将自动对字符串进行url编码,不需要此代码。