Handle Automation Result

❗️

Testing Automation

Make sure debug mode is enabled when testing Automations.
Call Qonversion.setDebugMode() before calling Qonversion.launch().
Do not forget to remove this line for the production build.

Automations Delegate

To handle Automations result call setDelegate and implement the following functions.

Set Automations delegate

You can skip this step if you don't need to handle the Qonversion Automations result.

Qonversion.Automations.setDelegate(self)
[QONAutomations setDelegate:self];
Automations.setDelegate(object : AutomationsDelegate {
     // Override functions here
})
Automations.setDelegate(new AutomationsDelegate() {
   // Override functions here
  });
// This method is not relevant for Flutter

Implement Qonversion.AutomationsDelegate functions

1. Controller for navigation

This function returns the controller for the navigation in iOS and context for screen intent in Android. This is an optional function.

func controllerForNavigation() -> UIViewController {
    // return controller for automations flow presentation
}
- (UIViewController * _Nonnull)controllerForNavigation {
    // return controller for automations flow presentation
}
override fun contextForScreenIntent(): Context {
   // Provide the context for screen intent
}
@NotNull
@Override
public Context contextForScreenIntent() {
    // Provide the context for screen intent
}
// This method is not relevant for Flutter

2. Automations states

All of these functions are optional.
First, you can handle the function that notifies you that Automations' screen is shown. You can do additional logic or just track an event here:

func automationsDidShowScreen(_ screenID: String) {
    // do some logic or track event
}
- (void)automationsDidShowScreen:(NSString * _Nonnull)screenID {
    // do some logic or track event
}
override fun automationsDidShowScreen(screenId: String) {
        // do some logic or track event
}
@Override
public void automationsDidShowScreen(@NotNull String screenId) {
  // do some logic or track event
}
StreamSubscription<String> _shownScreensStream;
_shownScreensStream = Automations.shownScreensStream.listen((event) {
  // do any logic you need
});

Then, you can handle Automations start, fail, or finish executing an action with the following functions:
Same as in the previous step, you can do additional logic or just track events here:

2.1. Start:
func automationsDidStartExecuting(actionResult: Qonversion.ActionResult) {
    // do some logic or track event
}
- (void)automationsDidStartExecutingActionResult:(QONActionResult * _Nonnull)actionResult {
    // do some logic or track event
}
override fun automationsDidStartExecuting(actionResult: QActionResult) {
       // Do some logic or track event
 }
@Override
public void automationsDidStartExecuting(@NotNull QActionResult actionResult) {
       // Ddo some logic or track event
}
StreamSubscription<ActionResult> _startedActionsStream;
_startedActionsStream = Automations.startedActionsStream.listen((event) {
  // do any logic you need or track event
});
2.2. Fail
func automationsDidFailExecuting(actionResult: Qonversion.ActionResult) {
    // do some logic or track event
}
- (void)automationsDidFailExecutingActionResult:(QONActionResult * _Nonnull)actionResult {
    // do some logic or track event
}
override fun automationsDidFailExecuting(actionResult: QActionResult) {
     // Do some logic or track event
}
@Override
public void automationsDidFailExecuting(@NotNull QActionResult actionResult) {
        // Do some logic or track event
}
StreamSubscription<ActionResult> _failedActionsStream;
_failedActionsStream = Automations.failedActionsStream.listen((event) {
  // do any logic you need or track event
});
2.3. Finish

You can use this function to get information if a user makes a purchase within the Automations flow. In this case, you need to check user's permissions ('checkPermissions') to unlock access to your app's premium content.

func automationsDidFinishExecuting(actionResult: Qonversion.ActionResult) {
    if actionResult.type == .purchase {
        Qonversion.checkPermissions { (resul, error) in
            // handle new permissions here
        }
    }
}
- (void)automationsDidFinishExecutingActionResult:(QONActionResult * _Nonnull)actionResult {
    if (actionResult.type == QONActionResultTypePurchase) {
        [Qonversion checkPermissions:^(NSDictionary<NSString *,QNPermission *> * _Nonnull result, NSError * _Nullable error) {
            // handle new permissions here
        }];
    }
}
override fun automationsDidFinishExecuting(actionResult: QActionResult) {
   if (actionResult.type == QActionResultType.Purchase) {
     Qonversion.checkPermissions(object :QonversionPermissionsCallback{
        // Handle new permissions here
     })
     }
 }
@Override
public void automationsDidFinishExecuting(@NotNull QActionResult actionResult) {
  if (actionResult.getType() == QActionResultType.Purchase) {
    Qonversion.checkPermissions(new QonversionPermissionsCallback() {
      // Handle new permissions here
    });
}
StreamSubscription<ActionResult> _finishedActionsStream;
_finishedActionsStream = Automations.finishedActionsStream.listen((event) {
  if (event.type == ActionResultType.purchase) {
    // do any logic you need
  }
});
2.4. Automations finished

This function is called when Automations flow is finished and the Automations screen is closed.

func automationsFinished() {
    // do any logic you needed
}
- (void)automationsFinished {
    // do any logic you needed
}
override fun automationsFinished() {
    // Do any logic you needed
 }
@Override
 public void automationsFinished() {
        // Do any logic you needed
 }
StreamSubscription<Null> _finishedAutomationsStream;
_finishedAutomationsStream =
    Automations.finishedAutomationsStream.listen((event) {
      // do any logic you need or track event
});

3. Automation events

This function allows identifying the event type that triggered the Automation.
Override this method and return false if you want to handle the event by yourself. Otherwise, Qonversion handles the event and shows the Automation screen (if it's configured). This is an optional function.
In case you want to handle push results on your side and show different screens to users that received push notifications triggered by different events, you need to handle the Automation event, check the event type, and show the screen required.

func shouldHandle(_ event: QONAutomationsEvent, payload: [String : Any]) -> Bool {
    // check event.type here
    // return false if you want to handle event yourself
  
    // for example
    if event.type == .subscriptionCanceled {
        return false
    } else {
        return true
    }
}
- (BOOL)shouldHandleEvent:(QONAutomationsEvent *)event payload:(NSDictionary<NSString *,id> *)payload {
    // check event.type here
    // return false if you want to handle event yourself
  
    // for example
    if (event.type == QONAutomationsEventTypeSubscriptionCanceled) {
        return false;
    } else {
        return true;
    }
}
override fun shouldHandleEvent(
    event: AutomationsEvent,
    payload: MutableMap<String, String>
): Boolean {
    // check event.type here
    // return false if you want to handle the event on your side
  
    // for example
    if (event.type == AutomationsEventType.SubscriptionCanceled) {
        return false
    } else {
        return true
    }
}
@Override
public Boolean shouldHandleEvent(@NotNull AutomationsEvent event, @NotNull Map<String, String> payload) {
    // check event.type here
    // return false if you want to handle the event on your side
  
    // for example
    if (event.getType() == AutomationsEventType.SubscriptionCanceled) {
        return false;
    } else {
        return true;
    }
}
// Will be available soon

Did this page help you?