For iOS apps

Tracking status


Tracking status request

[RPTracker instance].isActive
RPTracker.instance().isActive

Tracking status by notification

Notification

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

Observe

- (void)observeTracker {
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        self.startButton.enabled = ![RPTracker instance].isActive;
        self.stopButton.enabled = [RPTracker instance].isActive;
        
        if ([RPTracker instance].isActive) {
            self.tokenLabel.text = @"tracking is active";
        } else {
            self.tokenLabel.text = @"tracking is not active";
        }
    });
}
@objc func observeTracker() {
	DispatchQueue.main.async {
  	let isActive = RPTracker.instance()?.isActive ?? false
    self.stateLabel.text = "Tracking = \(isActive)"
	}
}

Tracking status by delegate

Interface example

@interface AppDelegate () <RPSpeedLimitDelegate, RPTrackingStateListenerDelegate> {
    
}

@end
class AppDelegate: UIResponder, UIApplicationDelegate, RPSpeedLimitDelegate, RPTrackingStateListenerDelegate {
            RPEntry.instance().trackingStateDelegate = self
            RPEntry.instance().speedLimitDelegate = self
}

Delegate Method

- (void)trackingStateChanged:(Boolean)state {
    NSLog(@"tracking state changed to %hhu", state);
}
func trackingStateChanged(_ state: Bool) {
        var body = "Tracking Stoped"
        if state {
            body = "Tracking Started"
        }
        NSLog("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 *)location {
    // Enter your code here to use location objectfrom SDK
}

- (void)onNewEvents:(NSMutableArray *)events {
    for (RPEventPoint *temp in events) {
        NSString *tempString = self.loggerView.text;
        tempString = [NSString stringWithFormat:@"%@\n%@", tempString, temp.type];
        dispatch_async(dispatch_get_main_queue(), ^{
            [self.loggerView setText:tempString];
        });
    }
}
func onLocationChanged(_ location: CLLocation!) {
    NSLog("location = %@", location)
}

func onNewEvents(_ events: NSMutableArray!) {
	for item in events {
  	if let theItem = item as? RPEventPoint {
    	NSLog("event id = %@ type = %@", theItem.theId, theItem.type)
    }
	}
}

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:(Boolean)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)
}