Integration of PEIG API for iOS platform is implemented by using framework in targeted application. Framework, named as PeigApiLib.framework, is part of the package. This framework is archived as ZIP file. Must be extracted on OSX system, because contains symlinks (symlinks doesn't work on Windows system).
It is recommended to use Xcode 6.4 for using PeigApiLib framework.
Framework PeigApiLib.framework must be included into Xcode project, in project settings, choose Build Phases, section Link Binary With Libraries, see below image.
Framework contains next important classes (public headers):
In the source code, use the following import
#import<PeigApiLib/LibServiceDelegate.h> #import<PeigApiLib/ApiResult.h>
Class LibServiceDelegate has two methods:
-(void) onSuccess:(ApiResult*) result; -(void) onFailed:(NSString*) error;
First, import class:
#import<PeigApiLib/PeigApiLib.h>
Thereafter call method:
[[PeigApiLib sharedInstance] aducidAuthenticate:url withDelegate:delegate withDataSourceCompletionHandler:^(ApiResult* result) { } withDataSourceErrorHandler:^(NSString *error) { }];
where:
LoginViewController implements LibServiceDelegate and methods:
-(void) onSuccess:(ApiResult *) result { ... } -(void) onFailed:(NSString *) error { ... }
See DemoBank application, class LoginViewController and other, eg. CHService. To the evaluate ApiResult - see PEIG API documentation.
Your code should evaluate these possible outcomes:
if [result isOK]
Session is authenticated.
else if [result peigNotInstalled]
PEIG is not installed, code
[[PeigApiLib sharedInstance] openAppStoreDetail]
opens ITUNES detail page.
else
other exception / redirect / state.
Custom application errors, authentication failed!
result.exception
contains ADUCID exception, there are possible states:
[result notAcceptedByUser]
user rejected
[result isFactorAbsent]
user doesn’t have personal factor (and server requires it)
result.data
contains error message / reason
[result doRedirect], result.redirect
contains page that could be opened using browser / contains additional content to download / display to the user.
See ApiResult class for all details.
PeigApiLib works with URI scheme. It is important to forward URi request from PEIG to PeigApiLib. Please, see class THAppDelegate in DemoBank application.
- (BOOL)application:(UIApplication*)application handleOpenURL:(NSURL*)url { [[PeigApiLibsharedInstance]handleOpenURL:url]; returnYES; }
Method handleOpenURL is defined in protocol class UIApplicationDelegate.
In case ApiResult is “OK” and mobile application is authenticated, use this session to contact your application server by using PeigApiLib library.
You can use GET or POST operations. See PeigApiLib class.
- (void) getAducidOperation:(NSString*)url withParameters:(id)params withDelegate:(id<LibServiceDelegate>)delegate withDataSourceCompletionHandler:(void (^) (ApiResult*))successDataHandler withDataSourceErrorHandler:(void (^)(NSString*))failureDataHandler; - (void) postAducidOperation:(NSString*)url withParameters:(id)params withDelegate:(id<LibServiceDelegate>)delegate withDataSourceCompletionHandler:(void (^) (ApiResult*))successDataHandler withDataSourceErrorHandler:(void (^)(NSString*))failureDataHandler;
url - target page or method URL, e.g. https://demobank.aducid.com/demobank/payment
params - reference to object with parameters, e.g. NSDictionary object in DemoBank application, class CHService
delegate - reference to delegate for callback when data is loaded
Please, have a look at class PaymentViewController in DemoBank application. There is the example how to use POST request.
Check your setup, test if you get error response from the server.
PEIG sends response back to mobile application via URI scheme. Please, define URI scheme for your mobile application in info.plist file. For DemoBank application is defined as aducid-demobank. See image below: