Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fun init() {
- val awsConfig: AWSConfiguration = AWSConfiguration(this)
- AWSMobileClient.getInstance().initializes(this, awsConfig) {
- onResult {
- Log.d("MainActivity", "${it.userState}")
- }
- onError { e ->
- e.printStackTrace()
- }
- }
- val pinpoint = PinpointManager(PinpointConfiguration(
- this,
- AWSMobileClient.getInstance(),
- awsConfig))
- FirebaseInstanceId.getInstance().instanceId.addOnCompleteListener { task ->
- if (task.isSuccessful()) {
- val token = task?.result?.token
- Log.d("MainActivity", "Registering push notifications token: ${token}")
- token?.let { pinpoint.getNotificationClient().registerDeviceToken(token) }
- } else {
- Log.w("MainActivity", "getInstanceId failed", task.getException())
- }
- }
- fun AWSMobileClient.initializes(context: Context, config: AWSConfiguration, init: Callbacks<UserStateDetails>.() -> Unit) : AWSCredentialsProvider {
- val callbacks = Callbacks<UserStateDetails>()
- callbacks.init()
- this.initialize(context, config, callbacks)
- return this
- }
- class Callbacks<T> : com.amazonaws.mobile.client.Callback<T> {
- var onResultFunc: (T) -> Unit = {}
- var onErrorFunc: (Throwable) -> Unit = {}
- override fun onResult(result: T) {
- onResultFunc(result)
- }
- fun onResult(onResult: (T) -> Unit) {
- this.onResultFunc = onResult
- }
- override fun onError(e: Exception?) {
- onErrorFunc(e ?: Exception())
- }
- fun onError(onError: (Throwable) -> Unit) {
- this.onErrorFunc = onError
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement