# Moya
iOS minimum versions
- SDK: 9.0
# Add SDK
Install Codavel SDK into your project through CocoaPods, a dependency manager for Objective-c and Swift.
- Install CocoaPods, by running the following commands in a terminal:
sudo gem install cocoapods
pod setup
2
- Then, create a ‘Podfile’ in the same directory as your Xcode project. This can be done by running:
pod init
- Afterwards, add the following content to your ‘Podfile’:
target "MyTargetName" do
platform :ios, '9.0'
use_frameworks!
(...)
pod 'BolinaInterceptor', :http=>'https://artifact.codavel.com:8081/artifactory/ios/BolinaInterceptor_0.10.14.zip'
(...)
end
2
3
4
5
6
7
- Install the dependencies in your project using the command:
pod install
- Build your app, with the required dependencies, by opening the generated Xcode workspace (
.xcworkspace
file) instead of the project file:
open <YourProjectName>.xcworkspace
# Start interceptor
Make sure that, before performing any HTTP/HTTPS request (a good place would be the didFinishLaunchingWithOptions
method in your AppDelegate), you import and start the interceptor.
- Import Bolina interceptor:
- Swift
import BolinaInterceptor
- Initialize the Bolina Configuration and set the Bolina Configuration domain name:
- Swift
guard let config = BolinaConfiguration.initBolinaConfiguration() as? BolinaConfiguration else {
// error initialising Bolina's configuration
return
}
config.setDomain("<BOLINA_SERVER_URL>")
2
3
4
5
- [optional] Configure your Origin:
- Swift
config.addBolinaURLReplacement("<your.cdn.com>", url: "<your.origin.com>");
With this configuration, all requests intercepted by Bolina that would originally be sent to <your.cdn.com>
, will be sent to a Bolina Server, that then will fetch the resource from <your.origin.com>
. In case the Bolina transfer fails, the requests will be sent to <your.cdn.com>
, as before. You can add multiple entries to be replaced. Otherwise, without this configuration, Codavel Performance Service servers will perform the same request as your HTTP clients would, to your current CDN or Origin.
- Start the Bolina interceptor:
- Swift
BolinaInterceptor.start("<APP_ID>", withSecret: "<APP_SECRET>", with: config)
WARNING
Check the interceptor lifecycle for more details on how to do it
- Add the Bolina interceptor as a configuration of MoyaProvider with
Alamofire.SessionManager
and use that session manager to perform HTTP/HTTPS requests:
- Swift
let configuration = URLSessionConfiguration.default
if configuration.protocolClasses != nil {
configuration.protocolClasses!.insert(CdvlURLProtocol.self, at: 0)
}
provider = MoyaProvider<YOUR_PROVIDER>(session: Alamofire.Session(configuration: configuration))
2
3
4
5
# Stop interceptor
- Make sure you stop the interceptor whenever you don’t need it:
- Swift
BolinaInterceptor.stop()
WARNING
Check the interceptor lifecycle for more details on how to do it