Copied To Clipboard

Xamarin


Integration

Import the NotifyVisitors SDK in your project

  1. Download the SDK from the link given below.
  2. Download SDK

  3. Extract the file and add the extracted library project to your project Solution. Double click on Reference and goto PROJECTS tab and select notifyvisitors and click on OK button.Now Notifyvisitors should be shown in Reference folder as following image.

Configure Info.plist

Goto info.plist click on Source tab

Add the following keys with their required values

  • Add NSAppTransportSecurity as a Dictionary. Then add a Subkey NSAllowsArbitraryLoadsas Boolean and set its value to YES.
  • Add URL types as an Array. Under Item 0, add two new items : URL Identifier (string) and URL schemes (Array). Add your company identifier for the URL Identifier and “YourAppScheme” for Item 0 of URL schemes.
  • Add NSLocationAlwaysUsageDescription as a String. Configure the message you want to show in alert box for asking user permission for geofencing.
  • Go To Application Tab inside Background Modes section select the checkbox “Enable Background Modes” and then select 3 checkboxes (i.e. Location updates,Background fetch,Remote notifications).Background Modes section should be look like following image.

Include Namespace

Include namespace in each .cs file in which sdk function is to be accessed.

  • iOS

            using Notifyvisitors;   
            

Initialise the SDK

To initialize the sdk, call the following function in didFinishLaunchingWithOptions method of your project.

  • iOS

            notifyvisitors.SetupWithBrandId (BRANDID, "SECRETEKEY");
            

Sample Code

Set its value to “debug” or “live” based on preprocessor if condition so that sdk knows the app is running in debugging mode or downloaded from AppStore (i.e. live mode)

  • iOS

            notifyvisitors.SetupWithBrandId (1176, "F8665C849AB6DBE429E1851384050610");    
            

Deep Linking

Call the following method in your AppDelegate openURL method that will check the deep linking and open your app from URL Scheme.

  • iOS

        
        notifyvisitors.Application (application, url, sourceApplication, annotation, BRANDID, "SECRETEKEY");   
        

Example:

  • iOS

        public override bool OpenUrl (UIApplication application, NSUrl url, string sourceApplication, NSObject annotation)   {
            notifyvisitors.Application (application, url, sourceApplication, annotation, 1176, "F8665C849AB6DBE429E1851384050610");
            throw new System.NotImplementedException ();  
            }
          
        

InApp Notifications

InApp Notifications include both Banners and Surveys. These are displayed based on iOS ViewControllers.

Every event occurs in the context of a ViewController. Every ViewController can be associated with some contextual data, which can be used as targeting rules for In-App Notifications.

Call the below show() Method in viewDidLoad method of every ViewController. show() Method should be called only once per ViewController.

  • iOS

        var userTokens = new NSMutableDictionary ();
        var customRules = new NSMutableDictionary ();
        notifyvisitors.Show (userTokens, customRules);
           
        

Default values are passed as nil.

Dynamic Tokens (NSMutableDictionary)Dynamic tokens are used to show personalised content in Notification messages real time.

Custom Rules (NSMutableDictionary)This data can be used in configuring targeting rules for the Notifications.

If you are using UIScrollView call the following method in your ScrollViewDidScroll delegate method.

  • iOS

        var YourScrollView = new UIScrollView ();
        this.YourScrollView.Scrolled += (sender, args) => {  
        notifyvisitors.ScrollViewDidScroll (YourScrollView);      };
        

Push Notifications

  1. Add the following method in didFinishLaunchingWithOptions method of application.
  • iOS

        notifyvisitors.RegisterForPushNotificationWithBrandId (BRANDID, "SECRETEKEY");
        
        

Add the following inside FinishedLaunching function to handle push notification and geofencing when your app is either in background state or terminated.

  • iOS

        if (launchOptions != null) { 
        notifyvisitors.HandlePushWhenAppTerminated (application, launchOptions);
        }
        
  1. Add the following methods inside your AppDelegate file to handle the registering and receiving events of push notification.
  • iOS

        public override void DidRegisterUserNotificationSettings (UIApplication application, UIUserNotificationSettings notificationSettings)   {
        application.RegisterForRemoteNotifications (); 
                    }
         public override void RegisteredForRemoteNotifications (UIApplication application, NSData deviceToken)   {
         notifyvisitors.DidRegisteredNotification (application, deviceToken);   
                }
        public override void FailedToRegisterForRemoteNotifications (UIApplication application, NSError error)  {
        new UIAlertView ("Error registering push notifications", error.LocalizedDescription, null, "OK", null).Show ();  
                    }
        public override void DidReceiveRemoteNotification (UIApplication application, NSDictionary userInfo, System.Action completionHandler) {
         notifyvisitors.DidReceiveNotifyvisitorsPushNotification (application, Window, userInfo);
                }
           
        

Notification Center

You can show a list of push notifications received in an In-app Notification Center. Expiry of the notifications can be set from the panel.

To launch In-app notification center you can call the following method.

  • iOS

         notifyvisitors.NotifyVisitorsNotificationCentre ();
        

Geofencing

  1. To handle the geofencing notifications in background state and Inactive state of application, add the following codes in applicationDidEnterBackground and applicationDidBecomeActive methods respectively.
  • iOS

        public override void DidEnterBackground (UIApplication application)  {
        notifyvisitors.NotifyVisitorsGeofencingApplicationDidEnterBackground ();
        }
        public override void OnActivated (UIApplication application)   {
        notifyvisitors.NotifyVisitorsGeofencingapplicationDidBecomeActive ();
        }
        
        
  1. Add the following Code to receive local notification when geofencing events trigger.
  • iOS

        public override void ReceivedLocalNotification (UIApplication application, UILocalNotification notification) { notifyvisitors.NotifyVisitorsGeofencingReceivedNotificationWithApplication (application, Window, notification); 
        }
         
        

Track Users

User API enables you to track a users' activity as they move from device to device and attach attributes to their profiles. Attributes enrich user profiles, like email, username, mobile, gender etc.

This method should be called when the user is identified (mostly on login).

  • iOS

        var jsonDataMutableDictionary = new NSMutableDictionary ();
        notifyvisitors.UserIdentifier ("userID", jsonDataMutableDictionary);
        
        

USER_ID(NSString)Setting the Unique ID is a critical piece to tie a user across devices and installs/uninstalls as well across all platforms (i.e. iOS, Android, Windows, The Web). Unique ID can be something like an email ID, a username (unique), or any Backend generated ID.

USER_ATTRIBUTES (NSMutableDictionary) You can set the user attributes like name, email, mobile number. These can then be used to send personalised content in notifications. But these attributes can not be used in segmenting the users.

Default Attribute Names -

  • name
  • email
  • mobile

You can also pass your custom attributes like username, birthday, first name, last name.

IMPORTANT :

Attribute Names should contain only alpha-numerics, white spaces or ‘_’ ;
No other special characters are allowed.
Recommended names - ‘first_name’, ‘last_name’

Sample Code

  • iOS

        var jsonDataMutableDictionary = new NSMutableDictionary ();
        notifyvisitors.UserIdentifier ("userID", jsonDataMutableDictionary);
        

Track Events

Event API enables you to record any actions your users perform, along with any properties that describe the action. These are then used for analytics, user segmentation or to trigger engagements or other actions.

  • iOS

        notifyvisitors.TrackEvents ("eventName",AttributesDictionary Attributes, ”Ltv”, scope);
        
        

EVENT_NAME (string)Name of the event like sale, register. Event names should contain only alpha-numerics, white spaces or ‘_’ ; No other special characters are allowed.

EVENT_ATTRIBUTES (NSMutableDictionary)Attributes associated with the event. Attribute values should be passed in the form of Javascript strings, booleans and numbers respectively. Similarly date attribute values are expected in the form of Javascript date objects.

IMPORTANT :

Attribute Names should contain only alpha-numerics, white spaces or ‘_’ ; No other special characters are allowed. Recommended names - ‘category’, ‘price_usd’

LIFETIME_VALUE (integer)The score you would like to reward the user on performing this event like 10, 100.

SCOPE (integer) The scope of the event, whether it should be tracked every time it is called, or per session, or once in a lifetime. This parameter is used to minimise the duplication of data in analytics. It is an integer whose values are :

  1. Track every time the api is called
  2. Track once per session
  3. Track once in a lifetime

Sample Code

  • iOS
var AttributesDictionary = new NSMutableDictionary ();
            AttributesDictionary.Add ((NSString)"price", (NSString)"2000");
            AttributesDictionary.Add ((NSString)"Category", (NSString)"fancy");

            notifyvisitors.TrackEvents ("YourEventName",AttributesDictionary, ”7”, 2);