- (void)applicationDidEnterBackground:(UIApplication *)application
{
NSLog(@"Entered1");
if([[UIDevice currentDevice] respondsToSelector:@selector(isMultitaskingSupported)]){
if ([[UIDevice currentDevice] isMultitaskingSupported]) {
UIApplication *application = [UIApplication sharedApplication];
__block UIBackgroundTaskIdentifier background_task;
background_task = [application beginBackgroundTaskWithExpirationHandler:^{
[application endBackgroundTask:background_task];
background_task = UIBackgroundTaskInvalid;
}];
dispatch_async(dispatch_get_global_queue
(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSLog(@"Running background");
//Calling method from ViewController
[application endBackgroundTask:background_task];
background_task = UIBackgroundTaskInvalid;
});
}
}
我想从中调用类ViewController.m
,AppDelegate.m
以便在后台和应用程序最小化时计算屏幕上的手指位置和大小。因此,它必须确定访问屏幕上不同窗口和应用程序的所有值。到目前为止,ViewController 能够在单个窗口中找到这些值。请建议实现相同的逻辑。我们可以只从 AppDelegate 调用这些方法吗?如果可以的话怎么做?
代码中声明的方法ViewContoller.m
如下,
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"Filename =%@", inputText);
UITouch *theTouch = [touches anyObject];
startPoint = [theTouch locationInView:self.view];
CGFloat x = startPoint.x;
CGFloat y = startPoint.y;
xCoord.text = [NSString stringWithFormat:@ "x = %f", x];
yCoord.text = [NSString stringWithFormat:@ "y = %f", y];
//Calculating finger size in millimeters-
locate = [[theTouch valueForKey:@"pathMajorRadius"] floatValue];
value.text = [NSString stringWithFormat:@"pressure = %.2f", locate];
}
- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *theTouch = [touches anyObject];
CGPoint touchLocation = [theTouch locationInView:self.view];
CGFloat x = touchLocation.x;
CGFloat y = touchLocation.y;
xCoord.text = [NSString stringWithFormat:@ "x = %f", x];
yCoord.text = [NSString stringWithFormat:@ "y = %f", y];
locate = [[theTouch valueForKey:@"pathMajorRadius"] floatValue];
value.text = [NSString stringWithFormat:@"pressure = %.2f", locate];
}
- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *theTouch = [touches anyObject];
CGPoint endPoint = [theTouch locationInView:self.view];
xCoord.text = [NSString stringWithFormat:@ "x:%f, y:%f", startPoint.x, startPoint.y];
yCoord.text = [NSString stringWithFormat:@ "x:%f, y:%f", endPoint.x, endPoint.y];
locate = [[theTouch valueForKey:@"pathMajorRadius"] floatValue];
value.text = [NSString stringWithFormat:@"pressure = %.2f", locate];
dist_x = (endPoint.x - startPoint.x);
dist_y = (endPoint.y - startPoint.y);
EucDistance = sqrtf((dist_x * dist_x) + (dist_y * dist_y));
NSLog(@"Distance =%f", EucDistance);
}