Mobile SDK
Android
Requirements:
*Android Studio
- minSdkVersion 19 or higher
Import the SDK:
Apps can import the SDK with a Gradle dependency that points to the jitpack repository.
In the first step you need to ensure that jitpack is referenced in the “allprojects” section of your project-level build.gradle
file.
allprojects {
repositories {
// ...
maven { url "https://jitpack.io" }
// ...
}
}
Next you need to open the build.gradle
file at the app level and look for the “dependencies” section.
dependencies {
...
implementation 'com.github.jump-group:avacy-android-sdk:1.0.0'
...
}
Add the line shown in the previous step, which tells Gradle to insert the latest version of the SDK.
If it's not already there, add the Kotlin dependency as well.
dependencies {
...
implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.4.21'
...
}
Once you have done the illustrated steps, save the file and perform a Gradle Sync.
NB: For the most recent versions of Android Studio, when a new project is created, a handler for managing dependencies will be automatically inserted into the settings.gradle file.
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
jcenter() // Warning: this repository is going to shut down soon
maven { url "https://jitpack.io" }
}
}
This snippet replaces the code placed in build.gradle
(project side) and essentially tells the project to resolve dependencies on the settings file rather than the Gradle build file. If you are already working on a project whose dependencies are placed in the allprojects
section, just delete this snippet and re-sync Gradle.
Update the AndroidManifest.xml file:
To perform network operations in your application, include the following permissions inside the AndroidManifest.xml
file
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Initialize the SDK:
Add the following to the onCreate method in the Application class.
Note: BASE_URL
is the URL of the consent page provided by Avacy.
AvacyCMP.init( this, BASE_URL )
Features implemented:
Consent check:
Add the following to check if consent has already been given to the latest version of the privacy policy, otherwise show the consent banner.
Note: The context must be a UI context.
AvacyCMP.check(this) // context: this
Or use the following code to trap any errors that occur during loading.
AvacyCMP.check(context, object : AvacyCMP.OnCMPReady() {
override fun onError(error: String?) {
// gestione dell'errore
}
})
Show Preference Center:
Add the following code to show the Preference Center and change the current consent.
Note: The context must be a UI context.
AvacyCMP.showPreferenceCenter(context)
or, again in case you want to intercept errors:
AvacyCMP.check(context, object : AvacyCMP.OnCMPReady() {
override fun onError(error: String?) {
// gestione dell'errore
}
})
iOS
Requirements:
- iOS 11.0+
- Xcode 12+
- Swift 5.1+
CocoaPods:
CocoaPods is a dependency manager for Cocoa projects. For usage and installation instructions, visit their website. In this case, just type the following commands:
sudo gem install cocoapods
and, in the root of your project, type
pod init
This command will create a text file called Podfile
, in which all the project dependencies must be manually declared. To integrate AvacySdk into your Xcode project using CocoaPods, specify it in the Podfile:
pod 'AvacyCmpSdk', '1.0.11'
Next, run the command
pod update
Initialize the SDK:
Import AvacyCmpSdk
and add the following to your application:
- Add
didFinishLaunchingWithOptions
method in theAppDelegate
file.
Note: BASE_URL
is the URL of the consent page provided by Avacy.
AvacyCMP.configure(url: BASE_URL)
Features implemented:
Consent check:
Add the following to check if consent has already been given to the latest version of the privacy policy, otherwise show the consent banner.
Note: viewController
must be a UIViewController
.
Add a property in the ViewController
let avacy = AvacyCMP()
and call the startCheck
method to the viewDidLoad
function
avacy.startCheck(on viewController: UIViewController, listener: OnCMPReady?)
Where:
UIViewController
is an instance of a UIViewController
. For example, if you are already in a UIViewController
(or a class that extends it), this variable can take the value self.
OnCMPReady
is a listener that implements the OnCMPReady
protocol for catching errors on load. You can also pass the nil value.
Show Preference Center:
Add the following code to show the preference center and change the current consents.
Note: viewController
must be a UIViewController
.
Add a property in the ViewController
let avacy = AvacyCMP()
and then call the showPreferences
method in your custom event:
avacy.showPreferences(on viewController: UIViewController,listener: OnCMPReady?)