Thanks for your helpful reply.
I'm using objective-c (though I don't have much experience with it, and am learning as I go).
I've tried using the completion-handler variant, like so:
SMAppService* myservice = [SMAppService daemonServiceWithPlistName:@"myservice.plist"];
[myservice unregisterWithCompletionHandler:^(NSError * error){
if (error != NULL) {
NSLog(@"Could not unregister myservice: %@", error.localizedDescription);
return;
}
NSLog(@"Successfully unregistered myservice, now trying to register it again");
NSError* err;
bool success = [myservice registerAndReturnError:&err];
if (success) {
NSLog(@"Successfully registered myservice");
} else {
NSLog(@"Could not register myservice: %@", err.localizedDescription);
}
}];
This successfully unregisters the service, but fails to register it again. Instead I get the error:
Could not register myservice: The operation couldn't be completed. Operation not permitted.
And sure enough, the service does not start in this case.
However, if I add [NSThread sleepForTimeInterval:2.000]; before calling registerAndReturnError, then registering succeeds.
Maybe I'm using the completion handler incorrectly?
Topic:
App & System Services
SubTopic:
Processes & Concurrency
Tags: