Je suis sous delphi berlin. Mon application est en arrière-plan à l'écoute des mises à jour de localisation. Quand il s'agit d'une mise à jour en arrière-plan j'ai besoin d'envoyer les données à un serveur, mais comme je lis sur Internet, je dois le faire dans un autre UIBackgroundTask
sinon l'application entrera à nouveau en arrière-plan avant que les données soient réellement envoyées. Une idée de comment faire cela sous Delphi?comment créer un UIBackgroundTask pour envoyer des données lorsque l'application est en arrière-plan?
0
A
Répondre
1
est ici un code qui devrait vous aider à démarrer:
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;
Lorsque votre application reçoit une mise à jour d'emplacement, vous pouvez faire un appel comme:
TaskID := SharedApplication.beginBackgroundTaskWithExpirationHandler(DoExpiry);
Où DoExpiry est une méthode que vous définissiez gère lorsque le système d'exploitation indique que le temps de votre tâche a expiré. Vérifiez le résultat par rapport à UIBackgroundTaskInvalid.
Lorsque votre tâche est terminée, appelez:
SharedApplication.endBackgroundTask(TaskID);