Got it to work thanks to your tips and suggestions.
Created a unit to interact with SMAppService:
unit ServiceManagementAppService;
{$mode objfpc}{$H+}
{$modeswitch objectivec1}
{$linkframework ServiceManagement}
interface
uses Classes, SysUtils, CocoaAll;
const
SMAppServiceStatusNotRegistered =0;
SMAppServiceStatusEnabled =1;
SMAppServiceStatusRequiresApproval =2;
SMAppServiceStatusNotFound =3;
SmAppServiceStatusResult :
Array [0..3] of string =
('Not registered',
'Enabled',
'Requires Approval',
'Not found' );
type
SMAppServiceStatus = NSInteger;
type
SMAppService = objcclass external (NSObject)
public
function registerAndReturnError(error: NSErrorPtr): objcbool; message 'registerAndReturnError:';
function unregisterAndReturnError(error: NSErrorPtr): objcbool; message 'unregisterAndReturnError:';
function status:SMAppServiceStatus; message 'status';
end;
implementation
end.
And in my main application for some random testing:
procedure TForm1.Button1Click(Sender: TObject);
var
appService: SMAppService;
StatusReturn : SMAppServiceStatus;
Registered:boolean;
begin
try
// Create a service
appService := SMAppService.new;
// Get current status
StatusReturn := appService.status;
ShowMessage('Status: '+IntToStr(Integer(StatusReturn))+LineEnding+ SmAppServiceStatusResult[StatusReturn]);
// Resgister service
Registered := appService.registerAndReturnError(nil);
ShowMessage('Registering result: '+BoolToStr(Registered,'Success','Failed'));
// Get current status
StatusReturn := appService.status;
ShowMessage('Status: '+IntToStr(Integer(StatusReturn))+LineEnding+ SmAppServiceStatusResult[StatusReturn]);
// Resgister service
Registered := appService.unregisterAndReturnError(nil);
ShowMessage('Unregistering result: '+BoolToStr(Registered,'Success','Failed'));
// Get current status
StatusReturn := appService.status;
ShowMessage('Status: '+IntToStr(Integer(StatusReturn))+LineEnding+ SmAppServiceStatusResult[StatusReturn]);
except
Showmessage('fail');
end;
end;
Note:
while testing it seemed I needed to sign the app bundle of my application
I haven't tested this yet in the App Store (I know that I need to make the user make this choice)
I hope this is useful to someone and feel free to correct me if I goofed up somehow. 😊
Thanks again!
Topic:
App & System Services
SubTopic:
Processes & Concurrency
Tags: