Android
[/et_pb_text][et_pb_accordion admin_label=”Steps on Android”][et_pb_accordion_item title=”Configuring your project on Android”]Configuring your app to work with GeoUniq requires only two simple steps, which will take to you only few minutes.
[/et_pb_accordion_item][et_pb_accordion_item title=”1. Importing GeoUniq library”]The first step is to import geouniq-x.y.z.jar, okhttp-x.y.z.jar, and okio-x.y.z.jar in your app project.This step might require slightly different operations depending on the IDE you are using.
Generally, you have to copy each jar file into your app’s lib folder and then add the them to the build path.[/et_pb_accordion_item][et_pb_accordion_item title=”2. Configuring Manifest”]The second step concerns the manifest of your app. Open the AndroidManifest.xml file and simply follow these steps. Copy and paste the code in *Manifest 1* in the <manifest> element. Copy and paste the code in *Manifest 2* in the <application> element. Copy and paste the code in *Manifest 3* in the <application> element. In *Manifest 3*, the <meta-data> tag tells GeoUniq about the identity of your app. Be sure to substitute your-app-key with the appKey you obtained when registered your app. You do not need to keep your appKey secret.
Manifest 1. Declaring permissions.
Manifest 2. Declaring app components.
Manifest 3. Declaring GeoUniq parameters.
[/et_pb_accordion_item][et_pb_accordion_item title=”3. Instantiating GeoUniq class”]If you have correctly performed the two steps above, GeoUniq service will automatically start after the first reboot, with no need to write any line of code. However, we suggest to make GeoUniq start as soon as your app is launched the first time; to do that, you can call the method GeoUniq.getInstance(ApplicationContext context). The best point to to that is in the onCreate method of your main activity,
that is the activity that is launched when your app is opened, as shown in *Code 1*.
@Override protected void onCreate(Bundle savedInstanceState) { startGeoUniq(); } private void startGeoUniq(){ GeoUniq.getInstance(getApplicationContext(), null); }[/et_pb_accordion_item][et_pb_accordion_item title=”TEST: Is everything working well?”]If everything is working well, you will see your app among the set of running application on the device, with an active Service, the GeoUniqService.
Go to *Apps->Running* on the device and looks for your app.
If you can find it, click on it and you will see that GeoUniqService is running.
If you do not see your app among the set of running applications, then take a look at your IDE logs.
You have probably missed something in your manifest or provided some incorrect information.
If so, GeoUniq will have logged the error.
Looks for GeoUniq tag into the log and find out what is not working.[/et_pb_accordion_item][/et_pb_accordion][et_pb_text admin_label=”Text” background_layout=”light” text_orientation=”left”]
iOS
[/et_pb_text][et_pb_accordion admin_label=”Steps on iOS”][et_pb_accordion_item title=”Configuring your project”]Preparing your app to work with GeoUniq requires only few simple steps, which will take to you only few minutes.
[/et_pb_accordion_item][et_pb_accordion_item title=”1. Importing GeoUniq Framework”]The first step consists of importing GeoUniq framework into your app.Drag and Drop GeoUniq.framework file inside your XCode project and include it within the ‘Embedded Binaries’ of the ‘General’ tab of your target application.
Set ‘Build Settings’ – ‘Build Options’ – ‘Embedded Content Contains Swift Code’ to **YES**
The last setting is mandatory for an Objective-C project.[/et_pb_accordion_item][et_pb_accordion_item title=”2. Configuring the Info.plist file”]The second step consists of including some keys inside the Info.plist file of your project.
Info.plist 1 – Declaring GeoUniq parameters
The first key, listed in *Info.plist 1*, is related to your appKey.
Key: GUAppKey | Type: String | Value: yourAppKey
*’GUAppKey’ is the appKey you obtained when you registered your app.
Info.plist 2 – Declaring iOS parameters
The second set of keys, listed in *Info.plist 2*, are related to parameters requested by the iOS system. They are listed below.
Key: NSLocationAlwaysUsageDescription | Type: String | Value: yourMessage
Key: NSLocationWhenInUseUsageDescription | Type: String | Value: yourMessage
Key: NSLocationUsageDescription | Type: String | Value: yourMessage
* ‘NSLocationAlwaysUsageDescription’ is the message prompetd by iOS System when the ‘AlwaysUsage’ authorization is requested.
It will be prompted only if the user clicks *Allow* on the ‘GULocationPermissionNotDetermined’ message.
* ‘NSLocationWhenInUseUsageDescription’ is the message prompetd by iOS System when the ‘WhenInUse’ authorization is requested. It will be prompted only if the user clicks *Allow* on the ‘GULocationPermissionNotDetermined’ message.
* ‘NSLocationUsageDescription’ is the message prompetd by iOS System when the position is requested for iOS Systems previous to version 8. It will be prompted only if the user clicks *Allow* after the ‘GULocationPermissionNotDetermined’ message.[/et_pb_accordion_item][et_pb_accordion_item title=”3. Enabling Capabilities”]The last step is to enable the location capability:
* Select Your Project -> Select your target -> Select **Capabilities** tab -> Switch on **Background Modes** -> Check **Location Updates**; Check **Background fetch**[/et_pb_accordion_item][et_pb_accordion_item title=”4. Enabling Capabilities”]To make GeoUniq automatically start as soon as your app is launched for the first time and keep working undefinitely, simply copy and paste the lines in *Code 2* into your AppDelegate.
Code 2 – Background Fetch (Swift)
//importing the framework import GeoUniq func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { //getting GeoUniq instance to make the service start GeoUniq.sharedInstance() UIApplication.sharedApplication().setMinimumBackgroundFetchInterval(UIApplicationBackgroundFetchIntervalMinimum) return true } func application(application: UIApplication, performFetchWithCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void){ //call GeoUniq backgroundFetch() method GeoUniq.sharedInstance().backgroundFetch() completionHandler(UIBackgroundFetchResult.NewData) }
Code 2 – Background Fetch (Objective C)
#import "GeoUniq/GeoUniq-Swift.h" - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { //getting GeoUniq instance [GeoUniq sharedInstance]; return YES; } - (void) application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler{ //call GeoUniq backgroundFetch() method [[GeoUniq sharedInstance] backgroundFetch]; completionHandler(UIBackgroundFetchResultNewData); }[/et_pb_accordion_item][et_pb_accordion_item title=”Optional: Managing location permission popups”]
Info.plist 3 – Keys to control location permission popups
The following set of keys of the Info.plist file can optionally be used to manage popups messages displayed by GeoUniq when checking the location permission of your project.
Key: GULocationPermissionDenied | Type: String | Value: yourMessage
Key: GULocationPermissionNotDetermined | Type: String | Value: yourMessage
Key: GUGreedinessDeniedPermission | Type: Boolean | Value: yourChoice
* ‘GULocationPermissionNotDetermined’ contains the message that will be displayed to the User (through a popup) in order to explain why your app needs the geographical position. The message is displayed when the permission for using the location service is not yet determined and the tracking functionality has to be started or a single position has been requested. It is displayed before asking the actual permission to the iOS system.
Indeed, The popup gives the User the possibility to accept or deny. If the user accepts, then either the ‘AlwaysUsage’ or the ‘WhenInUseUsage’ permission is requested to the the iOS system depending on wether the tracking functionality has to be started or a single position has been requested.
If the User cliks on “deny”, then the permission is not asked at all.
* ‘GULocationPermissionDenied’ contains the message that is displayed when the permission to use the Location Service is denied. This message is still displayed when either the tracking functionality has to be started or a single position has been requested but, unlike the case of ‘GULocationPermissionNotDetermined’, it provides no option for the User to choose. It is intended to inform the User that He should change the permission in order to allow the app to access the position.
* ‘GUGreedinessDeniedPermission’ specifies the type of approach that GeoUniq has to follow when the permission to use the Location Service is denied. If set to true, then everytime the position should be acessed and the permission is denied, a popup containing the message indicated in ‘GULocationPermissionDenied’ will be prompted to the user. If set to false or not provided, then the message will be prompted just once.
[/et_pb_accordion_item][/et_pb_accordion][/et_pb_column][/et_pb_row][/et_pb_section]