HTTP Request Customization in iOS
For the iOS platform, you will be required to conform to URLRequestInterceptingDelegate
which provides you with a callback that receives URLRequest
right before they are fired. In this example, we will utilize AppDelegate
to intercept our requests:
import FaceSDK
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
FaceSDK.service.requestInterceptingDelegate = self
return true
}
}
extension AppDelegate: URLRequestInterceptingDelegate {
func interceptorPrepare(_ request: URLRequest) -> URLRequest? {
var request = request
request.addValue("Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJmYWNlLXNkayI6IkhhdmUgYSBncmVhdCBkYXkhIn0.IPoW0D0LnMv_pL4U22MuIhDNGIdK34TaHhqhKBAaBEs", forHTTPHeaderField: "Authorization")
return request
}
}
#import "AppDelegate.h"
#import <FaceSDK/FaceSDK.h>
@interface AppDelegate () <RFSURLRequestInterceptingDelegate>
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
RFSFaceSDK.service.requestInterceptingDelegate = self;
return YES;
}
- (NSURLRequest * _Nullable)interceptorPrepareRequest:(NSURLRequest * _Nonnull)request {
NSMutableURLRequest *interceptedRequest = [request mutableCopy];
[interceptedRequest addValue:@"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJmYWNlLXNkayI6IkhhdmUgYSBncmVhdCBkYXkhIn0.IPoW0D0LnMv_pL4U22MuIhDNGIdK34TaHhqhKBAaBEs" forHTTPHeaderField:@"Authorization"];
return interceptedRequest;
}
@end