iOS位置更新(即使应用未运行)(例如找到我的iPhone) [英] iOS Location update even app is not running (like find my iphone)

查看:91
本文介绍了iOS位置更新(即使应用未运行)(例如找到我的iPhone)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编写位置跟踪应用程序,例如 找到我的iphone ,该应用程序可以在前台,后台甚至终止(不运行)中运行。位置将定期发送到我的服务器。我已经在Google中搜索并阅读了许多关于此主题的文档,教程注释和代码。然后我找到了本教程。但是在本教程中,位置被发送到前景和后台的 .txt文件中。不终止 ...我的意思是,当应用被杀死时,它不会在后台重新启动以发送位置 .txt文件。。因此,我添加并更新了一些代码,以在未运行时发送位置。.但是,我没有这样做...我的意思是,当我在多任务处理中杀死(关闭)应用程序时(双点击主页按钮),它不会发送到位置...

I want to write location tracking app like "find my iphone" that runs in foreground,background and even terminating ( not running). Location will be sent to my server periodically time. I have searched in google and read many many documents,tutorials comments, codes about this topic. Then I have found this tutorial. But in this tutorial, location is sent to ".txt" file in foreground and background not terminating... I mean, when the app is killed, it is not relaunched in the background to send location ".txt" file .. So I have added and updated some codes to send location when it is not running.. However, I didn't do it... I mean, when I kill(close) the app in multitasking (double tapping home button), it is not sending to location...

您能帮我,如何解决此问题?

Can you help me, how can I fix this problem?

预先感谢

- (void)locationManager:(CLLocationManager *)manager
    didUpdateToLocation:(CLLocation *)newLocation
           fromLocation:(CLLocation *)oldLocation
{
    [self log:[NSString stringWithFormat:@"Background location %.06f %.06f %@" , newLocation.coordinate.latitude, newLocation.coordinate.longitude, newLocation.timestamp]];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    id locationValue = [launchOptions objectForKey:UIApplicationLaunchOptionsLocationKey];
    if (locationValue)
    {
        // create a new manager and start checking for sig changes

        [self log:@"didFinishLaunchingWithOptions location key"];
        m_locManager = [[CLLocationManager alloc] init];

        [self log:@"didFinishLaunchingWithOptions created manager"];
        m_locManager.delegate = self;

        [self log:@"didFinishLaunchingWithOptions set delegate"];
        [m_locManager startMonitoringSignificantLocationChanges];

        [self log:@"didFinishLaunchingWithOptions monitoring sig changes"];

        return YES;
    }

    [self log:@"didFinishLaunchingWithOptions"];    
    return YES;
}


- (void)applicationWillResignActive:(UIApplication *)application {
    [self log:@"applicationWillResignActive"];
    NSUserDefaults * userDefaults = [NSUserDefaults standardUserDefaults];
    [userDefaults setBool:viewController.m_significantSwitch.on forKey:@"significant"];
    [userDefaults synchronize];
}                


- (void)applicationDidEnterBackground:(UIApplication *)application {
    [self log:@"applicationDidEnterBackground"];
    [m_locManager startMonitoringSignificantLocationChanges];
}


- (void)applicationWillEnterForeground:(UIApplication *)application {

    [self log:@"applicationWillEnterForeground"];
    [m_locManager stopMonitoringSignificantLocationChanges];

}


- (void)applicationDidBecomeActive:(UIApplication *)application {
    [self log:@"applicationDidBecomeActive"];

    if (![window.subviews count])
    {
        // Add the view controller's view to the window and display.
        [window addSubview:viewController.view];
        [window makeKeyAndVisible];

        NSUserDefaults * userDefaults = [NSUserDefaults standardUserDefaults];
        viewController.m_significantSwitch.on = [userDefaults boolForKey:@"significant"];
        if (viewController.m_significantSwitch.on)
            [viewController actionSignificant:nil];
    }
}


- (void)applicationWillTerminate:(UIApplication *)application {
    [self log:@"applicationWillTerminate"];
    [m_locManager startMonitoringSignificantLocationChanges];

}


推荐答案

我的朋友,您走错了路。实际上,在iOS中杀死应用程序后,没有任何方法可以执行任务。您可以在Apple文档中此处 a>。

My friend , you are on wrong way. Actually there is no any way to do a task after killing of app in iOS. You can read about this here in Apple documentation.

查找我的iPhone-这是一个Apple App,他们正在使用专用API来实现这一目标。这些类型的功能不适用于通用开发人员编程。

Find My iPhone - It is an Apple App and they are using private api's to make this possible. And these type of features not available for general purpose developer programming.

因此,请不要走这条路,所有这些都是徒劳的。

So please don't go on this path.All will go in vain.

希望这对您有帮助!

这篇关于iOS位置更新(即使应用未运行)(例如找到我的iPhone)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆