如何让应用程序永远以后台模式运行?

发布于 2024-12-04 18:22:23 字数 513 浏览 0 评论 0原文

我遇到了一个关键问题,让我与您分享。 我有一个 iPhone 应用程序,无论应用程序处于后台模式还是前台模式,每分钟都需要将当前位置发送到服务器。 我完成了 info.plist 参数中的属性设置,例如后台模式 - >位置和位置配置的其他代码通常是

- (CLLocationManager *)loc_mngr {

    if (loc_mngr != nil) {
        return loc_mngr;
    }


    loc_mngr = [[CLLocationManager alloc] init];
    loc_mngr.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
    loc_mngr.delegate = self;
    return loc_mngr;

}

loc_mngr 是 CLLocationManager 的对象。 委托方法实现完成。 它对我有用,但问题是当我的应用程序在后台时如何启用位置服务。 请帮我如何处理? 副词中的感谢

i got one critical problem let me share with you .
i have an iphone app that need to send current location to server whether app is on background mode or foreground mode per minute.
i done setting property in info.plist parameter like background mode-->location and other code for location configuration is usual

- (CLLocationManager *)loc_mngr {

    if (loc_mngr != nil) {
        return loc_mngr;
    }


    loc_mngr = [[CLLocationManager alloc] init];
    loc_mngr.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
    loc_mngr.delegate = self;
    return loc_mngr;

}

loc_mngr is an object of CLLocationManager.
delegate method implementation is done.
it work for me but the problem is how to handel location service enable when my app is on background.
please help me how to deal with it?
thanks in adv.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

铁轨上的流浪者 2024-12-11 18:22:23

看看这个苹果文档,您可以使用以下方法来完成此操作。

CLLocationCoordinate2D coord = CLLocationCoordinate2DMake(0.0, 0.0); 
CLRegion *region = [[CLRegion alloc] initWithCircularRegionWithCenter:coord radius:500 identifier:@"Some Identifier"];

然后,向框架注册区域:

[locationManager startMonitoringForRegion:region]; 

委托协议定义了用于区域的三种方法:

– locationManager:didEnterRegion:
– locationManager:didExitRegion:
– locationManager:monitoringDidFailForRegion:withError:

Have a look at this apple document, you are having following methods to do this thing.

CLLocationCoordinate2D coord = CLLocationCoordinate2DMake(0.0, 0.0); 
CLRegion *region = [[CLRegion alloc] initWithCircularRegionWithCenter:coord radius:500 identifier:@"Some Identifier"];

And then, register the region with the framework:

[locationManager startMonitoringForRegion:region]; 

The delegate protocols define three methods to use for regions:

– locationManager:didEnterRegion:
– locationManager:didExitRegion:
– locationManager:monitoringDidFailForRegion:withError:
只是在用心讲痛 2024-12-11 18:22:23

您将需要创建一个 CLLocationManagerDelegate 来接收对您的应用程序的回调。您需要设置要运行的位置项,并且当您的应用程序转到后台时,您需要让委托“监听”位置更新。这可以通过区域监控 -didEnterRegion 或 -didExitRegion 来实现。或者像标准位置监控中的 -didUpdateToLocation 一样简单。

有关更多信息,请阅读 Apple 位置感知编程指南。祝你好运。

You will need to create a CLLocationManagerDelegate to receive the callbacks to your app. You need to set the location item to run, and when you app goes to the background, you need to have the delegate "listen" for location updates. That can be via region monitoring -didEnterRegion or -didExitRegion. Or as simple as -didUpdateToLocation from standard location monitoring.

For more information, read Apple's Location Awareness Programming Guide. Good luck.

酒儿 2024-12-11 18:22:23

“永远”这个词在概念上是错误的:苹果保留随时终止应用程序的权利。你需要重新考虑逻辑。

一些注意事项:

  • 始终打开本地化(标准本地化)是错误的:它会很快消耗电池

  • 是更好用:

    [locationManager startMonitoringSignificantLocationChanges];

    这种方式功耗要少得多(即使精度较低...)

  • 使用区域:即使您的应用程序被杀死/终止,它们也会被遵守。 (我们在io5中测试过,它有效)

The term "forever" is conceptually wrong: Apple retains the right to kill apps at any moment. You need to reconsider the logic.

Some notes:

  • it is wrong to keep localization (standard localization) always on: it consumes battery very quicky

  • is better to use:

    [locationManager startMonitoringSignificantLocationChanges];

    This way power consumption is much less (even if precison is lower...)

  • use regions: they are obeyed even if your app is was killed/ terminated. (we tested it in io5 and it works)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文