我在發送電子郵件時遇到問題。如果消息只有一個單詞,代碼工作得很好。當我添加多個單詞時,即使用空格或符號時,它會錯誤地顯示「出現連接錯誤,請確保您連接到互聯網,然後再試一次」。字段值包含空格或符號時提交表單錯誤
- (void)sendAction {
NSString *email = [self.emailTxt text];
NSString *message = [self.messageTxt text];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@?email=%@&message=%@", kITSuggestionPage, email, message]];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
NSString *title = (!error)? @"Message Sent" : @"Error";
NSString *message = (!error)? @"Thank you for your Feedback, we hope it will help us to make this product even better." : @"There was an connection error. Please make sure you have internet connection and try again later.";
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:message delegate:nil cancelButtonTitle:@"Close" otherButtonTitles:nil, nil];
[alert show];
NSLog(@"Error: %@", error.localizedDescription);
}];
if (email && (email.length > 0)) {
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setObject:email forKey:kITUserEmailKey];
[userDefaults synchronize];
}
}
太好了!非常感謝! – Steve 2013-04-27 14:36:14