Locations & Geofences

In this section you will find a series of more advanced functionalities that require a more complex development. We recommend that a developer be in charge of this configuration.

Activate geolocated notifications

The indigitall SDK can manage the user's location. This allows you to use the location filters on the send push campaign screen ( Campaigns> Push> New push campaign > Filters> Geographical Filters)

18291829

Once we have enabled this functionality, the end user will have to give their consent to the location permission and enable the location services of their smartphone, so that the application can obtain the exact location of the user.

Android

Add the location permissions by including this line in the AndroidManifest.xml file inside the Properties folder of the android project:

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

You have to add the RequestLocationPermission parameter when the SDK is initialized in the case of using Xamarin. Forms and mark with the requestPermissionLocation flag, in the case of using Xamarin Classics you only have to add the requestPermissionLocation flag. This is done using the following code excerpt:

//Xamarin.Forms
//When you want to initialize indigitall in global iOS project::Xamarin.Forms.Forms.Init(this, bundle);
  DependencyService.Register<Com.Indigitall.Xamarin.Android.Indigitall>();
  Com.Indigitall.Xamarin.Android.Utils.PermissionUtils.RequestLocationPermission(this);
  // otra forma de pdefinir el setdefault: this.ComponentName.ClassName

  var app = new App();
  LoadApplication(app);

...

  public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Permission[] grantResults)
    {
        base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
        Com.Indigitall.Xamarin.Android.Utils.PermissionUtils.OnRequestPermissionResult(this, requestCode, permissions, grantResults);

    }

  ------------
//Initialize the project
 var indigitall = DependencyService.Get<IIndigitall>();
  if (indigitall != null)
  {
      indigitall.Init("YOUR_APPKEY", "YOUR_SENDERID", true);
  }
  ------------

//Xamarin Classics
  Com.Indigitall.Xamarin.Android.Indigitall indigitall = new Com.Indigitall.Xamarin.Android.Indigitall();
  indigitall.Init("YOUR_APPKEY", "YOUR_SENDERID", true);

iOS

Add the following keys to the application's Info.plist file.

//Xamarin.Forms
//When you want to initialize indigitall in global iOS project::Xamarin.Forms.Forms.Init(this, bundle);</span>
  DependencyService.Register&lt;Com.Indigitall.Xamarin.Android.Indigitall&gt;();
  Com.Indigitall.Xamarin.Android.Utils.PermissionUtils.RequestLocationPermission(<span class="hljs-keyword">this</span>);
  <span class="hljs-comment">// otra forma de pdefinir el setdefault: this.ComponentName.ClassName</span>

  var app = <span class="hljs-keyword">new</span> App();
  LoadApplication(app);

...

  <span class="hljs-function"><span class="hljs-keyword">public</span> override <span class="hljs-keyword">void</span> <span class="hljs-title">OnRequestPermissionsResult</span><span class="hljs-params">(<span class="hljs-keyword">int</span> requestCode, string[] permissions, [GeneratedEnum] Permission[] grantResults)</span>
    </span>{
        base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
        Com.Indigitall.Xamarin.Android.Utils.PermissionUtils.OnRequestPermissionResult(<span class="hljs-keyword">this</span>, requestCode, permissions, grantResults);

    }

  ------------
<span class="hljs-comment">//Initialize the project</span>
 var indigitall = DependencyService.Get&lt;IIndigitall&gt;();
  <span class="hljs-keyword">if</span> (indigitall != <span class="hljs-keyword">null</span>)
  {
      indigitall.Init(<span class="hljs-string">"YOUR_APPKEY"</span>, <span class="hljs-string">"YOUR_SENDERID"</span>, <span class="hljs-keyword">true</span>);
  }
  ------------

<span class="hljs-comment">//Xamarin Classics</span>
  Com.Indigitall.Xamarin.Android.Indigitall indigitall = <span class="hljs-keyword">new</span> Com.Indigitall.Xamarin.Android.Indigitall();
  indigitall.Init(<span class="hljs-string">"YOUR_APPKEY"</span>, <span class="hljs-string">"YOUR_SENDERID"</span>, <span class="hljs-keyword">true</span>);</code>

Keys NSLocationAlwaysUsageDescription, NSLocationWhenInUseUsageDescription y _NSLocationAlwaysAndWhenInUseUsageDescription_can be customized by editing the content of the label < string >.
Add the following code in the AppDelegate inside the FinishedLaunching method

DependencyService.Register<Com.Indigitall.Xamarin.iOS.Indigitall>();

  if (UIDevice.CurrentDevice.CheckSystemVersion(10, 0))
  {
      // iOS 10 or later
      var authOptions = UNAuthorizationOptions.Alert | UNAuthorizationOptions.Badge | UNAuthorizationOptions.Sound;
      UNUserNotificationCenter.Current.RequestAuthorization(authOptions, (granted, error) =>
      {
          if (granted)
          {
              InvokeOnMainThread(() =>
              {
                  UIApplication.SharedApplication.RegisterForRemoteNotifications();
              });
          }
      });

      // For iOS 10 display notification (sent via APNS)
      UNUserNotificationCenter.Current.Delegate = new Com.Indigitall.Xamarin.iOS.UserNotificationCenterDelegate();

  }
  else
  {
      // iOS 9 or before
      var allNotificationTypes = UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound;
      var settings = UIUserNotificationSettings.GetSettingsForTypes(allNotificationTypes, null);
      UIApplication.SharedApplication.RegisterUserNotificationSettings(settings);
  }