菜鸟教程小白 发表于 2022-12-12 08:52:54

没有 UIWebView 的 iOS 应用程序身份验证


                                            <p><p>有没有办法在<strong>没有</strong>来自 Flask(Python) 后端的 webview 的情况下对用户进行身份验证?</p>

<p>这是我的后台登录代码:</p>

<pre><code>@app.route(&#39;/login/&#39;, methods=[&#39;POST&#39;])
def login():
    params = json.loads(request.data)
    username = params[&#39;username&#39;]
    password = params[&#39;password&#39;]
    u = User.query.filter_by(username=username).first()
    if u:
      if utils.check_password_hash(password, u.pw_hash):
            login_user(u)
            return (&#39;&#39;, 200)
      else:
            return (&#39;&#39;, 400)
    else:
      return (&#39;&#39;, 400)
</code></pre></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>是的,您当然可以做到这一点。这是我通常的做法,根据您的需要进行更改(请记住,NSJSONSerialization 仅在 iOS 5+ 中可用):</p>

<pre><code>@property (nonatomic) NSOperationQueue *basicQueue; //add this to your header or as an instance variable

-(void)logMeIn:(NSString *)username password:(NSString *)password {

basicQueue = [ init];

NSDictionary *userCredentialsDict = ;
NSData *encodedDict = ;

NSMutableURLRequest *request = [ initWithURL:];
;
;
;

[NSURLConnection sendAsynchronousRequest:request queue:basicQueue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
    NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*) response;
    NSString *stringFromData = [ initWithData:data encoding:NSUTF8StringEncoding];
    if (httpResponse.statusCode == 200) {
      //do stuff
      NSLog(@&#34;Received data, parsed into string: %@&#34;, stringFromData);
    } else {
      //do error stuff or whatever
    }

}];
</code></pre>

<p>}</p>

<p>如需更多信息,
看看</p>

<ul>
<li> <a href="https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSURLConnection_Class/Reference/Reference.html" rel="noreferrer noopener nofollow">https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSURLConnection_Class/Reference/Reference.html</a> </li>
<li> <a href="https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSMutableURLRequest_Class/Reference/Reference.html" rel="noreferrer noopener nofollow">https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSMutableURLRequest_Class/Reference/Reference.html</a> </li>
<li> <a href="http://developer.apple.com/library/ios/#documentation/Foundation/Reference/NSJSONSerialization_Class/Reference/Reference.html" rel="noreferrer noopener nofollow">http://developer.apple.com/library/ios/#documentation/Foundation/Reference/NSJSONSerialization_Class/Reference/Reference.html</a> </li>
</ul></p>
                                   
                                                <p style="font-size: 20px;">关于没有 UIWebView 的 iOS 应用程序身份验证,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/14986980/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/14986980/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: 没有 UIWebView 的 iOS 应用程序身份验证