For iOS apps

Tracking status


Tracking status request

[[RPEntry instance] isTrackingActive];
RPEntry.instance.isTrackingActive()

Tracking status by notification

Notification

[[NSNotificationCenter defaultCenter]
     addObserver:self
     selector:@selector(observeTracker)
     name:NSNotification.RPTrackerDidChangeActivityNotification
     object:nil];
NotificationCenter.default.addObserver(
            self,
            selector: #selector(observeTracker),
            name: NSNotification.RPTrackerDidChangeActivityNotification,
            object: nil
        )

Observe

- (void)observeTracker {
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
    	BOOL isActive = [[RPEntry instance].isTrackingActive];
        
        if (isActive) {
            self.stateLabel.text = @"tracking is active";
        } else {
            self.stateLabel.text = @"tracking is not active";
        } 
    });
}
@objc func observeTracker() {
	DispatchQueue.main.async {
  	let isActive = RPEntry.instance.isTrackingActive()
    self.stateLabel.text = "Tracking = \(isActive)"
	}
}

Tracking status by delegate

Interface example

@interface AppDelegate () <RPTrackingStateListenerDelegate> {
    [RPEntry instance].trackingStateDelegate = self;
}
@end
class AppDelegate: UIResponder, UIApplicationDelegate, RPTrackingStateListenerDelegate {
    RPEntry.instance.trackingStateDelegate = self
}

Delegate Method

- (void)trackingStateChanged:(BOOL)state {
    NSLog(@"tracking state changed to %hhu", state);
}
func trackingStateChanged(_ state: Bool) {
    let body = state ? "Tracking Started" : "Tracking Stoped"
    print("tracking state changed to \(body)")
}

Location change and Events

Usage example

@interface AppDelegate () <RPLocationDelegate> {
    [RPEntry instance].locationDelegate = self;
}
class AppDelegate: UIResponder, UIApplicationDelegate, RPLocationDelegate {
    RPEntry.instance.locationDelegate = self
}

Delegate method

- (void)onLocationChanged:(CLLocation * _Nonnull)location {
    // Enter your code here to use location object from SDK
}

- (void)onNewEvents:(NSArray<RPEventPoint *> * _Nonnull)events  {
    // Enter your code here to use event objects SDK
}
func onLocationChanged(_ location: CLLocation) {
    print("location = \(location)")
}

func onNewEvents(_ events: [RPEventPoint]) {
	for item in events {
    	print("event: \(event)")
    }
}

Low power mode

*Usage example

@interface AppDelegate () <RPLowPowerModeDelegate> {
    [RPEntry instance].lowPowerModeDelegate = self;
}
class AppDelegate: UIResponder, UIApplicationDelegate, RPLowPowerModeDelegate {
    RPEntry.instance.lowPowerModeDelegate = self
}

Delegate method

- (void)lowPowerMode:(BOOL)state {
    if (state) {
        // You can create push in this place and fire about this, as example 
        
        UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init];
        content.title = @"Low Power Mode";
        content.body = [NSString stringWithFormat:@"Your trips may be not recorded. Please, follow to Settings=>Battery=>Low Power"];
        UNTimeIntervalNotificationTrigger *trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:1 repeats:NO];
        UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:@"overspeed" content:content trigger:trigger];

        [[UNUserNotificationCenter currentNotificationCenter] addNotificationRequest:request withCompletionHandler:nil]; 
    }
}
func lowPowerMode(_ state: Bool) {
	if (state) {
  	self.showNotification(title: "Low Power Mode", body: "Your trips may be not recorded. Please, follow to Settings=>Battery=>Low Power")
  }
}

Low accuracy mode

*Usage example

@interface AppDelegate () <RPAccuracyAuthorizationDelegate> {
    [RPEntry instance].accuracyAuthorizationDelegate = self;
}
class AppDelegate: UIResponder, UIApplicationDelegate, RPAccuracyAuthorizationDelegate {
    RPEntry.instance.accuracyAuthorizationDelegate = self
}

Delegate method

- (void)wrongAccuracyAuthorization {
    // You can create push in this place and fire about this, as example 
        
    UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init];
    content.title = @"Precise Location is off";
    content.body = [NSString stringWithFormat:@"Your trips may be not recorded. Please, follow to App Settings=>Location=>Precise Location"];
    UNTimeIntervalNotificationTrigger *trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:1 repeats:NO];
    UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:@"overspeed" content:content trigger:trigger];

    [[UNUserNotificationCenter currentNotificationCenter] addNotificationRequest:request withCompletionHandler:nil];

}
func wrongAccuracyAuthorization() {
    let content = UNMutableNotificationContent()
    content.title = "Precise Location is off"
    content.subtitle = "Your trips may be not recorded. Please, follow to App Settings=>Location=>Precise Location"
    content.sound = UNNotificationSound.default
    // show this notification five seconds from now
    let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 5, repeats: false)
    // choose a random identifier
    let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: trigger)
    // add our notification request
    UNUserNotificationCenter.current().add(request)
}