没有 UIWebView 的 iOS 应用程序身份验证
<p><p>有没有办法在<strong>没有</strong>来自 Flask(Python) 后端的 webview 的情况下对用户进行身份验证?</p>
<p>这是我的后台登录代码:</p>
<pre><code>@app.route('/login/', methods=['POST'])
def login():
params = json.loads(request.data)
username = params['username']
password = params['password']
u = User.query.filter_by(username=username).first()
if u:
if utils.check_password_hash(password, u.pw_hash):
login_user(u)
return ('', 200)
else:
return ('', 400)
else:
return ('', 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(@"Received data, parsed into string: %@", 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]