I write some app that sends local notification with delay and when the notification received i want to decide what to do based on device movement. if device is in move - set the same notification with new delay and stay in background. if device not in move - pop specific view controller.
i do succeed with the "no drive" mode but when the device is in move - i don't really know hot to handle this situation.
here is my code for now, hope for some help thanks!
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
NSLog(@"Notification recieved from background...");
//check if device is in move
CLLocationManager *locationManager = [[CLLocationManager alloc]init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyKilometer;
locationManager.distanceFilter = 50;
[locationManager startMonitoringSignificantLocationChanges];
if (locationManager.location.speed > 10) {
NSLog(@"Device is in drive....");
notification.fireDate = [NSDate dateWithTimeIntervalSinceNow:10];//TODO - Debug Set Real Time Before publish
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
NSLog(@"New Notification sent to device");
self.window.rootViewController = nil;
[self.window makeKeyAndVisible];
}
else{
NSLog(@"Device is not in drive....");
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];
IGUViewFillDetailsController *vc = (IGUViewFillDetailsController *)[mainStoryboard instantiateViewControllerWithIdentifier:@"IGUViewFillDetailsController"];
vc.dic = notification.userInfo;
UINavigationController *navVC = [[UINavigationController alloc] initWithRootViewController: vc];
self.window.rootViewController = vc;
//[self.window addSubview:vc.view];
[self.window makeKeyAndVisible];
}
}