如何“查找我的朋友”? (FMF)应用程序响应位置? [英] How does "Find My Friends" (FMF) App respond to location?

查看:174
本文介绍了如何“查找我的朋友”? (FMF)应用程序响应位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建一个应用程序,当任何人请求时,它会响应组中的人员位置 - 类似于查找我的朋友(FMF),但是在Android和iOS上,我正在使用Phonegap。我一直在研究FMF App如何返回位置 - 沿着这个 SO Post ,并试图更好地理解这一点。



在某些时候,iOS会因内存压力而终止应用程序。我知道如果您将XCode的功能部分中的背景模式设置为位置,并且如果位置发生重大变化,则应用程序将在后台重新启动。 FMF应用程序正在做什么来确保它能够响应位置请求?



当请求位置时,我发送推送通知(仅通知数据通知在后台处理 - 用户不会看到它),并且应用程序预计会在后台/前台进行响应。但是,如果iOS的应用程序已被iOS终止并且没有重大的位置更改,则该应用程序无法在后台运行并且不会响应。除了以某种方式阻止iOS暂停/终止应用程序,我们能做的最好吗?欣赏任何见解。



我已阅读了关于创建后台服务的帮助,但似乎更适用于Android而不是iOS。



感谢您的任何指导和指引。



Sanjay。

解决方案首先,你应该记得声明应用程序支持的后台任务

支持某些类型的后台执行必须由使用它们的应用预先声明。在Xcode 5及更高版本中,您可以从项目设置的功能选项卡声明您的应用程序支持的背景模式。启用背景模式选项可将UIBackgroundModes键添加到应用的Info.plist文件中。选择一个或多个复选框会将相应的背景模式值添加到该键。

然后跟踪用户位置并缓存最新位置。



处理您的远程通知以上传最新的位置。



当您想获取某人的位置时,服务器使用APNS向客户端推送远程通知,并且客户端处理远程通过应用程序通知:didReceiveRemoteNotification:fetchCompletionHandler:



或者定时在后台上传有限长度任务:

   - (void)applicationDidEnterBackground:(UIApplication *)application 
{
bgTask = [application beginBackgroundTaskWithName :@MyTaskexpirationHandler:^ {
//通过标记哪里清理任何未完成的任务业务你
//停止或直接结束任务。
[application endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
}];

//开始长时间运行的任务并立即返回。
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0),^ {

//完成与该任务相关的工作,最好是块。

[application endBackgroundTask:bgTask ];
bgTask = UIBackgroundTaskInvalid;
});
}

希望能帮到你〜


I am trying to create an App that will respond with locations of people in a group when anyone requests it - similar to what Find My Friends (FMF) does but across Android and iOS and I am using Phonegap. I have been researching how the FMF App returns locations - along the lines of this SO Post and am trying to understand that better.

At some point iOS will terminate the App due to memory pressure. I understand if you set your Background mode in Capabilities section of XCode to location and if there is a significant change in location the App will restart in Background. Is that what the FMF App is doing to ensure it stays up to respond to location request?

When location is requested I send a push notification (data notification only so it is processed in the background - users doesn't see it) and the App is expected to respond if it is in Background/Foreground. However in the case of iOS if the App has been terminated by iOS and there has been no significant location change, the App will not be up and running in Background and won't respond. Is that the best we can do besides somehow preventing iOS from suspending/terminating the App? Appreciate any insights.

I have read about creating background services to help but that seems to apply more to Android than to iOS.

Thank you for any guidance and pointers.

Sanjay.

解决方案

First of all, you shoud Declaring Your App’s Supported Background Tasks.

Support for some types of background execution must be declared in advance by the app that uses them. In Xcode 5 and later, you declare the background modes your app supports from the Capabilities tab of your project settings. Enabling the Background Modes option adds the UIBackgroundModes key to your app’s Info.plist file. Selecting one or more checkboxes adds the corresponding background mode values to that key.

Then Tracking the User’s Location and cached the latest location.

And handle your remote notification to upload the latest location.

When your want to get somebody's location, Server push a remote-notification to the Client with APNS, and Client handle the remote-notification with application:didReceiveRemoteNotification:fetchCompletionHandler:

Or timed to upload location with Finite-Length Tasks in the background:

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    bgTask = [application beginBackgroundTaskWithName:@"MyTask" expirationHandler:^{
        // Clean up any unfinished task business by marking where you
        // stopped or ending the task outright.
        [application endBackgroundTask:bgTask];
        bgTask = UIBackgroundTaskInvalid;
    }];

    // Start the long-running task and return immediately.
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

        // Do the work associated with the task, preferably in chunks.

        [application endBackgroundTask:bgTask];
        bgTask = UIBackgroundTaskInvalid;
    });
}

Hope that help you ~

这篇关于如何“查找我的朋友”? (FMF)应用程序响应位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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