在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
http://stackoverflow.com/questions/32348081/delphi-firemonkey-ios-background-processing I finally got it to work under delphi 10 Seattle (you need this version, i have tried XE7 and doesn't work, I haven't tried xe8). Here are the steps: Project > Options > Version Info. Check UIBackgroundModes you need (I used Fetch) 1。设置setMinimumBackgroundFetchInterval时间间隔 2.实现performFetchWithCompletionHandler方法 unit uBackgroundiOS; interface uses fmx.platform.iOS,iOSapi.CocoaTypes, Macapi.ObjCRuntime, Macapi.ObjectiveC, iOSapi.UIKit; const UIBackgroundFetchResultNewData:NSUInteger = 0; UIBackgroundFetchResultNoData:NSUInteger = 1; UIBackgroundFetchResultFailed:NSUInteger = 2; UIApplicationBackgroundFetchIntervalMinimum:NSTimeInterval = 0; UIApplicationBackgroundFetchIntervalNever:NSTimeInterval = -1; type // copied from fmx.platform.iOS as it's on private declaration id = Pointer; SEL = Pointer; PUIApplication = Pointer; IMP = function( self : id; cmd : SEL; Param1 : NSUInteger ) : id; cdecl; function imp_implementationWithBlock( block :id ) : IMP; cdecl; external libobjc name _PU + 'imp_implementationWithBlock'; function imp_removeBlock( anImp : IMP ) : integer; cdecl; external libobjc name _PU + 'imp_removeBlock'; procedure performFetchWithCompletionHandler(self : id; _cmd : SEL; application: PUIApplication; handler : id ); procedure initializeBackgroundFetch; function objc_msgSend(theReceiver: Pointer; theSelector: Pointer): Pointer; cdecl; varargs; external libobjc name _PU + 'objc_msgSend'; //to test if procedure is called in background var fecth_string_test: string; implementation procedure performFetchWithCompletionHandler(self : id; _cmd : SEL; application: PUIApplication; handler : id ); var ahandlerimp: IMP; begin //Code to perform fetch HERE!!!! fecth_string_test := 'entered background code!!'; surl:='www.cnblog.com/abc/123.html'; ahandlerimp := imp_implementationWithBlock( handler ); //Create c function for block ahandlerimp(self,_cmd, UIBackgroundFetchResultNewData); //Call c function, _cmd is ignored 接收到的新数据 imp_removeBlock(ahandlerimp); //Remove the c function created two lines up
也可以在didFinishLaunchingWithOptions事件里设置UIApplicationBackgroundFetchIntervalMinimum时间 执行完了要调用completionHandler告知系统。 [[UIApplication sharedApplication] setMinimumBackgroundFetchInterval:UIApplicationBackgroundFetchIntervalMinimum]; performFetchWithCompletionHandler是回调函数,可以在里边写个通知!
performFetchWithCompletionHandler DeclarationSwift Objective-C
Parameters
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论