TapPay Push Token Example Code for iOS Plateform.
- Make sure issuer app has been installed
- Setup the URL scheme in the Info.plist of example project
- Issuer App will launch your App with tspPushToken and cancelUrl
- Parse TspPushToken and cancelUrl from intent data
- Send Push Token API to Tappay server
- You will get a suceess response with cardKey and cardToken
- You may get more card information by Card Metadata API if you want
// AppDelegate
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
// Parsing the url by any method which could return parameters
NSArray *queryItems = [GlobalFunction queryParameter:url];
// Post the push token and cancel url to observer
[[NSNotificationCenter defaultCenter] postNotificationName:@"TSP_Push_Token" object:queryItems];
return true;
}
// SceneDelegate
- (void)scene:(UIScene *)scene openURLContexts:(NSSet<UIOpenURLContext *> *)URLContexts {
NSURL * url = [[[URLContexts allObjects] firstObject] URL];
// Parsing the url by any method which could return parameters
NSURL * url = [[[URLContexts allObjects] firstObject] URL];
NSArray *queryItems = [GlobalFunction queryParameter:url];
// Post the push token and cancel url to observer
[[NSNotificationCenter defaultCenter] postNotificationName:@"TSP_Push_Token" object:queryItems];
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(tokenGet:) name:@"TSP_Push_Token" object:nil];
}
- (void)tokenGet:(NSNotification *)notification {
NSString *pushToken = [notification object];
if (pushToken.length > 0) {
[self pushTokenizeWithToken:pushToken successCallback:^(NSDictionary *result) {
// Do something here if request succeed
} failureCallback:^(NSDictionary *result, NSError *error) {
// Do something here if request failed
}];
}
}
- (void)pushTokenizeWithToken:(NSString *)token
successCallback:(void (^)(NSDictionary *result))successCallback
failureCallback:(void (^)(NSDictionary *result, NSError *error))failureCallback{
...
NSDictionary *parametersDict = @{@"partner_key":yourPartnerKey,
@"tsp_push_token":token};
...
}
// AppDelegate
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
// Parsing the url by any method which could return parameters
let queryItems = URLComponents(string: url.absoluteString)?.queryItems
// Post the push token and cancel url to observer
NotificationCenter.default.post(name:NSNotification.Name.init("TSP_Push_Token"), object: queryItems, userInfo: nil)
return true
}
// SceneDelegate
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
if let url = URLContexts.first?.url {
// Parsing the url by any method which could return parameters
let queryItems = URLComponents(string: url.absoluteString)?.queryItems
// Post the push token and cancel url to observer
NotificationCenter.default.post(name:NSNotification.Name.init("TSP_Push_Token"), object: queryItems, userInfo: nil)
}
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
NotificationCenter.default.addObserver(self, selector: #selector(tokenGet(notification:)), name: NSNotification.Name.init("TSP_Push_Token"), object: nil)
}
@objc func tokenGet(notification : NSNotification) {
let pushToken = notification.object as! String
if pushToken.count > 0 {
pushTokenizeWithToken(token: pushToken) { result in
// Do something here if request succeed
} fail: { result,error in
// Do something here if request failed
}
}
}
private func pushTokenizeWithToken(token: String ,success: @escaping (_ result: Dictionary<String, Any>) -> Void ,fail: @escaping (_ result:Dictionary<String, Any>, _ error:Error) -> Void) {
...
let parametersDict = ["partner_key":yourPartnerKey,"tsp_push_token":token]
...
}