AFNetworking在多语言应用程序中崩溃

时间:2017-05-17 11:04:46

标签: ios afnetworking multilingual

  

路线[SOURCE_NAME] = 2152,%20Mohali%20Stadium%20Rd,%20Phase%2010%20Sector%2064%20Sahibzada%20Ajit%20Singh%20Nagar,%20Punjab%20160062,%20भारत

这个参数在印地语运行时导致崩溃,同时使用西班牙语和英语正常工作。请建议我。崩溃描述如下: -

  

***因未捕获的异常'NSInternalInconsistencyException'而终止应用程序,原因:'参数无效   满足:URLString'

     

2 个答案:

答案 0 :(得分:1)

添加以下代码行以避免网址中的无效参数。

NSString *str = ...; // Your URL
NSCharacterSet *set = [NSCharacterSet URLHostAllowedCharacterSet]; 
NSString *result = [str stringByAddingPercentEncodingWithAllowedCharacters:set];

在ios 9.0之前不推荐使用的代码:

NSString *str = ...; // Your URL
NSString *urlAsString = [str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

答案 1 :(得分:1)

检查

目标 - C

NSString *string = @"भारत";
NSString *encoded = [string stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLFragmentAllowedCharacterSet]];

Swift 3.0

let string = "भारत"
let urlString = string.addingPercentEncoding( withAllowedCharacters: . urlUserAllowed)
  

输出::%E0%A4%AD%E0%A4%BE%E0%A4%B0%E0%A4%A4