我在德尔福·柏林的名下。我的应用程序在后台监听位置更新。当他们在后台更新位置时,我需要将数据发送到服务器,但当我在互联网上阅读时,我需要在UIBackgroundTask中执行此操作,否则应用程序将在实际发送数据之前再次进入后台。你知道如何在delphi下做到这一点吗?
发布于 2017-07-18 09:32:02
下面是一些可以让你入门的代码:
uses
Macapi.ObjectiveC, iOSapi.Foundation, iOSapi.CocoaTypes, iOSapi.UIKit;
const
UIKitFwk: string = '/System/Library/Frameworks/UIKit.framework/UIKit';
type
TBackgroundTaskHandler = procedure of object;
// Fills in methods missing in Delphi
UIApplication = interface(UIResponder)
['{8237272B-1EA5-4D77-AC35-58FB22569953}']
function beginBackgroundTaskWithExpirationHandler(handler: TBackgroundTaskHandler): UIBackgroundTaskIdentifier; cdecl;
procedure endBackgroundTask(identifier: UIBackgroundTaskIdentifier); cdecl;
end;
TUIApplication = class(TOCGenericImport<UIApplicationClass, UIApplication>) end;
function SharedApplication: UIApplication;
begin
Result := TUIApplication.Wrap(TUIApplication.OCClass.sharedApplication);
end;
function UIBackgroundTaskInvalid: UIBackgroundTaskIdentifier;
begin
Result := CocoaIntegerConst(UIKitFwk, 'UIBackgroundTaskInvalid');
end;当你的应用程序收到位置更新时,你可以进行如下调用:
TaskID := SharedApplication.beginBackgroundTaskWithExpirationHandler(DoExpiry);其中,DoExpiry是您定义的方法,用于在操作系统指示您的任务时间已过期时进行处理。对照UIBackgroundTaskInvalid检查结果。
当您的任务完成后,调用:
SharedApplication.endBackgroundTask(TaskID);https://stackoverflow.com/questions/45154421
复制相似问题