iOS SDK: Advanced Options

Singular iOS SDK
Singular iOS SDK version 9.2.6

iOS 8+

Sample App Review our sample app for an example of a complete SDK integration based on best practices.
Integration Guides
  1. Basic Integration
  2. Tracking Events and Revenue
  3. Implementing Deep Links
  4. Advanced Options


Tracking Uninstalls

Note: Uninstall tracking is only available to Enterprise customers.

To let Singular track your app's uninstalls:

  1. Make sure uninstall tracking is enabled for your app in Singular. See Setting Up iOS Install Tracking for instructions.
  2. In the app, send Singular the device token returned from the Apple Push Notification Service (APNS). To pass the device token to Singular use the registerDeviceTokenForUninstall or registerDeviceToken method. Do this before the Singular StartSession call.

If your app doesn't support push notifications yet, see Apple's guide to implementing APNS.


  • If you are already retrieving a device token from an existing push notification implementation, you can use that value.
  • The APNS token is usually binary data in the native form. Pass the token as received from APNS. If the app alters the token data type pass it as a hex-encoded string, like the following example: b0adf7c9730763f88e1a048e28c68a9f806ed032fb522debff5bfba010a9b052
registerDeviceTokenForUninstall Method (Objective-C)
Description Pass the device token returned from APNS.
Signature + (void)registerDeviceTokenForUninstall:(NSData*)deviceToken;
Usage Example
NSString* apns = @"b0adf7c9730763f88e1a048e28c68a9f806ed032fb522debff5bfba010a9b052";
NSData* data = [apns dataUsingEncoding:NSUTF8StringEncoding];
[Singular registerDeviceTokenForUninstall:data];

Using the Singular SDK JavaScript Interface

Singular provides a JavaScript interface that you can use in order to call Singular from within javaScript code in your app.

For example, if you set up the JavaScript interface, you can send events to Singular from JavaScript code as follows:

Singular.event('test', JSON.stringify({"a1":"bar",
"a2":"boo", "a3":"baz"}));

The interface supports the following SDK methods:

  • setCustomUserID
  • unsetCustomUserID
  • event
  • revenue

Enabling the JavaScript Interface

Note: Starting in iOS 8.0+ Apple recommends using WKWebView to add web content to your app. Do not use UIWebView or WebView. See Apple's WKWebView documentation for more information.

To enable the JavaScript interface when using WKWebView , you need to add some code to the webView method of the WKNavigationDelegate protocol (this protocol helps you implement custom behaviors triggered when a web view handles a navigation request).


extension ViewController: WKNavigationDelegate { 
 func webView(_: WKWebView, decidePolicyFor: WKNavigationAction, 
decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) { // Singular handler let js = "typeof(Singular)" webView.evaluateJavaScript(js) { (result, error) -> Void in if let resultString = result as? String { if resultString.isEqual("undefined") { do { let contents = try String(contentsOfFile:
Bundle.main.path(forResource: "Singular", ofType: "js")!) self.webView.evaluateJavaScript(contents,
completionHandler: nil) } catch { } } else { print(decidePolicyFor.request) Singular.processJSRequestWK(self.webView,
withURL:decidePolicyFor.request) } } } // rest of your code goes here }

If you are using the older UIWebView (deprecated in iOS 8.0), update the method webView:shouldStartLoadWithRequest:navigationType: in your UIWebViewDelegate file as follows:


- (BOOL)webView:(UIWebView *)webView 
shouldStartLoadWithRequest:(NSURLRequest *)request
navigationType:(UIWebViewNavigationType)navigationType{ if([[webView stringByEvaluatingJavaScriptFromString:@"typeof(Singular)"] isEqualToString:@"undefined"]) { // Inject Singular.js into the HTML [webView stringByEvaluatingJavaScriptFromString:[NSString
stringWithContentsOfFile:[[NSBundle mainBundle]
pathForResource:@"Singular" ofType:@"js"] usedEncoding:nil error:nil]]; } else { // process request in Singular.js [Singular processJSRequest:webView withURL:request]; } // The rest of your code goes here return true; }

GDPR Compliance

The Singular SDK provides several methods to help you comply with GDPR policies and let Singular know about user consent or non-consent for tracking.

trackingOptIn Method
Description Notify Singular of user consent for tracking (opt-in).
Usage Example Objective-C:
[Singular trackingOptIn];


trackingUnder13 Method
Description Notifying Singular that a user is a minor (under 13).
Usage Example


[Singular trackingUnder13];


stopAllTracking Method
Description Stopping all tracking activities for this user on this app
Important: Calling this method effectively disables the SDK, even between app restarts (the state is persistent). The only way to turn it off is by calling the resumeAllTracking method
Usage Example


[Singular stopAllTracking];


resumeAllTracking Method
Description Resuming tracking activities for this user on this app
Usage Example


[Singular resumeAllTracking];


isAllTrackingStopped Method
Description Checking the status of tracking for this user on this app
Usage Example


[Singular isAllTrackingStopped]; // returns true/false


Singular.isAllTrackingStopped() // returns true/false
Was this article helpful?
0 out of 0 found this helpful