My Mac app has a launch agent (within the app bundle) that works great without the app running. There are some occasions where I need to display an alert and ask the user to launch the app to handle the issue. I thought about using UNUserNotificationCenter but I'm not able to make it work from the agent.
I'm asking for authorization as follows:
[center requestAuthorizationWithOptions:(UNAuthorizationOptionAlert | UNAuthorizationOptionSound | UNAuthorizationOptionBadge)
completionHandler:^(BOOL granted, NSError * _Nullable error) {
NSLog(@"authorization request completion. Granted: %@, error: %@ (%@)",granted?@"YES":@"NO",error, [error localizedDescription]);
}];
And I'm trying to post the notification as follows:
content.title = @"Your App Name";
content.body = @"Click the button to open the app";
content.sound = [UNNotificationSound defaultSound];
UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:[[NSUUID UUID] UUIDString]
content:content
trigger:nil];
[center addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) {
if (error) {
NSLog(@"Error showing notification: %@ %@", error, [error localizedDescription]);
}
}];
When running I'm getting asked to authorize, I authorize and all seems OK in system settings but I'm not able send any notifications. addNotificationRequest results in UNErrorCodeNotificationsNotAllowed error.
I tried this with the authorization request inside the main app, or inside the agent, with the same results.
When trying to post the notification from within the app, it does work, but that's not what I need.
Is posting notifications from within the launch agent not possible at all, or is there anything here that I'm missing.
TIA
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
I'm working on adding a finder sync extension to an app. The app is not sandboxed.
In essence, the app is operating on files located in folders that the user chooses, the app stores the status information in an extended attribute for each file.
The extension needs to monitor these folders and and assign a badge according to the state indicated in the extended attribute.
Everything is working fine, I can get the app and extension to communicate which folders to watch, I can manipulate the files with the app, setting the extended attributes and the extension is getting requestBadgeIdentifierForURL called.
However, attempting to read the the extended attribute using getxattr() is blocked by the sandbox.
I tried creating an app group and to store the folder urls as security scoped bookmarks in the group but this fails when trying to resolve the bookmark.
In retrospect this makes sense since the security scoped bookmark is supposed to be used for accessing the same url by the same app in the same sandbox which is not the case when dealing with an un-sandboxed app and a sandboxed Finder Find Extension.
I read somewhere (here: https://developer.apple.com/forums/thread/66259?page=2) from someone, quoting DTS on a similar issue that he can either communicate to the main app process to get the information or use document scoped
security scoped bookmarks but I'm having trouble finding information about document scoped bookmarks and I'm not sure if it makes sense either.
Thanks in advance
Eyal