ios - Class return wait for UIWebView -
i developing app fetch data school website tableview, that, app needs logged in.
i have been trying hours make proper login system sending data post login form, reason, wont work (i have done before site, aint because dont know how to)
so have hidden uiwebview loginform , populate user adds 2 uitextfields..
but instead of adding hidden uiwebview every viewcontroller (whenever need login again data, in case of session on site expires) make class that..
i thinking like:
class.h
+(bool)loginwithusername(nsstring*)username : password(nsstring*)password;
class.m
+(bool)loginwithusername(nsstring*)username : password(nsstring*)password { //create webview //populate form on site // press submitbutton //wait - (void)webviewdidfinishload:(uiwebview *)webview finish, analyzes if user logged in, , if return true }
but how done??
much better create method completion block
typedef block, not necessary helpful
typedef void(^completionhandler)(bool success);
in method save completion handler local ivar completionhandler _handler;
+(bool)loginwithusername(nsstring*)username : password(nsstring*)password complete:(completionhandler)handler;
in webviewdidfinishload
check login success end cal block
if (handler) { handler(yes); // or no if login failed }
and in anther controller can call
[loginclass loginwithusername:@"user" password:@"pass" complete:^(bool success){ if (success) { // logged in } }];
Comments
Post a Comment