Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/103.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在WKWebview中打开URL_Ios_Objective C_Wkwebview_Urlencode - Fatal编程技术网

Ios 在WKWebview中打开URL

Ios 在WKWebview中打开URL,ios,objective-c,wkwebview,urlencode,Ios,Objective C,Wkwebview,Urlencode,我正试图在WKWebview中打开以下URL 当我运行这段代码时,它在url中给出了nil值,这可能是因为您的url无效并且包含无效字符。您应该确保url的编码正确。您必须使用字符串,方法是将PercentEncoding与AllowedCharacters一起添加以使其成为有效的url NSString *urlString = @"https://chart.googleapis.com/chart?chs=200x200&chld=M|0&cht=qr&chl=o

我正试图在WKWebview中打开以下URL


当我运行这段代码时,它在url中给出了nil值,这可能是因为您的url无效并且包含无效字符。您应该确保url的编码正确。

您必须使用字符串,方法是将PercentEncoding与AllowedCharacters一起添加以使其成为有效的url

NSString *urlString = @"https://chart.googleapis.com/chart?chs=200x200&chld=M|0&cht=qr&chl=otpauth://totp/mynameisanthony@gmail.com?secret=B6S2LGJTQHIDKIMU&issuer=someapp+Auth";
NSString *encodedURLString = [urlString stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
NSURL *url = [NSURL URLWithString:encodedURLString];

现在您可以使用此url。

我已经解决了我的问题

        strQRImage = [strQRImage stringByReplacingOccurrencesOfString:@"+" withString:@" "];
        strQRImage = [strQRImage stringByRemovingPercentEncoding];
        NSURL* url = [NSURL URLWithString:[strQRImage stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]]];

谢谢,先生。Arora@SomePerson如果您的问题已得到解决,您可以向上投票并接受答案。我已向上投票,但请参阅此消息中的“感谢您的反馈!记录声誉低于15的人所投的票,但不要更改公开显示的帖子分数”。如果您想增加您答案的向上投票,请询问
        strQRImage = [strQRImage stringByReplacingOccurrencesOfString:@"+" withString:@" "];
        strQRImage = [strQRImage stringByRemovingPercentEncoding];
        NSURL* url = [NSURL URLWithString:[strQRImage stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]]];