Your PARENT app can't be authorized (at this moment of time and will never be in my opinion) so the applicationTokens set will never be exposed to you from apple security reasons. You can tell this is a security issue because even when using an authorized CHILD app this data is not empty but it is encrypted.
Post
Replies
Boosts
Views
Activity
Hi MohamediOS!
You get an empty set of applications tokens because the parent app is not authorized and you can't get it authorized at all.
I think that apple did this from security issues and you can see this even on an authorized child that the applications tokens set is not empty but it's encrypted. So i believe you can't get this list on a Non authorized app at this moment maybe apple will be nice and make an api change that we can retrieve this information on a connected users threw the family sharing or something.
did it tell you this? : "Provisioning profile "" doesn't support the Family Controls capability even though you enabled this option on Xcode and on your apple developer account?
i'm currently at the same situation and trying to figure out why is that.
From what i saw you can't get the neither the application identifiers nor the application tokens of the applications on the parent device' probably because security and information privacy issues. Let's remember that you also can't get authorization on parent app.
I may have a possible solution for this but i haven't tried it yet to see if it works:
Sending selection model from the picker via server to the child app and use it on the picker. Probably it won't work because of encryption and security issues but it worth the try.
Let me know if it helped
i think this is not possible as long that we cant get Authorization for the parent app at all
first of all i assume you are talking about shielding apps.
when i tried to trigger the threshold callbacks i noticed that the threshold i defined was reached not by one app i selected but as a sum of the usage of all the apps i selected. maybe start from there?
if you defined an DeviceActivityEvent with a threshold of X and passed several applications, it means that if the total usage for all the apps combined is X than the callback will fire
if you want each app to have different threshold consider creating DeviceActivityEvent for each app separately
tell me if it was helpful for you
."But even if I try only setting the restricted apps to nil or the empty set the apps remain shielded until I run the same code from the main app." - you need to remember that app and an app extension doesn't share data so it's likely that the store instance you are using isn't the same.
what you need to do is to manage the selected apps list you want to shield or block using user defaults or core data or some other persistence storage that will be shared between your app and app extension. and block or unblock according to the data you are managing between them.
try to keep the blocking or unblocking on the app or on the app extension so only one of the will use the store. i chose to do this on the extension using the events that correspond with start and stop monitoring
what your code actually says is: after 30 seconds of total usage of the application that you selected (applications.applicationTokens) the "eventDidReachThreshold" of the DeviceActivityMonitor extension will be called. handle your event ".encouraged" inside the "eventDidReachThreshold" and do there what ever you like.
i think for you case if you want to limit some apps for a period of time just make a scheduled event that start from the current time you tapped an OK button (or some other action) to current time + limitation time of tour choice. and on your DeviceActivityMonitor extension you should handle the blocking and unblocking on the intervalDidStart and intervalDidEnd
the your code should look something like this:
do {
let schedule = DeviceActivitySchedule(intervalStart: start, intervalEnd: end, repeats: false, warningTime: nil)
try center.startMonitoring(.block, during: schedule)
} catch {
print("error: " + error.localizedDescription)
}
app usage thresholds of the apps i selected from the picker
if you set the family correctly the app that the child have should be presented on the picker on the parent
i have a parent with iOS 15.0.2 and a child with iOS 15.1 and it seems to work (sort of)
i have to mentioned that the facebook app is an app i downloaded after using the screen time api on my app and this require a confirmation from the parent app
i did not managed to block or shield an app from the parent on the child because an authorization error i'm keep getting
i don't know why the icon of the app is missing on the child app
child:
parent:
currently the answer is NO yo cant access usage history of apps or app categories, try and monitor the usage yourself
played with this some more and answered my own questions:
the token is unavailable/nil
i managed to shield an app with the same extension used for blocking
no my app extension does not require some additional configuration
AuthorizationCenter.shared.requestAuthorization can only used on a device with Child iCloud account. It can not be used on Parent's device. Purpose of this request is to Authorize A parent iCloud account on child device so that a parent can supposedly manage the child ScreenTime
quoting an answer i got for this question from: AsifmDev
i have created an extension and changed the identifier to com.apple.deviceactivity.monitor-extension i subclassed DeviceActivityMonitor in my class and designated it as the principal class of my app extension but non of the methods doesn't get called when trying to monitor an activity
what method will trigger the extension? is it center.startMonitoring(activity, during: schedule) in that case why non of my extension DeviceActivityMonitor methods doesn't gets called?
why calling requestAuthorization on parent device always fails?
can anyone upload some sample code that actually do something?
can you please specify how you built the Device Activity Monitor Extension?
xcode beta 2 doesn't have this kind of extension