Dear all,
I'm quite new to Xcode.
I'm trying to set up my first project - I'd like to create a macOS and iPad app.
So I'm following the steps in Xcode, but receiving errors.
I'm attaching the steps I'm following with the details of what Xcode is giving me as error.
C
o
Could you please give me indications on how to solve the issue?
Thanks,
Andrea
Managed Settings
RSS for tagSet restrictions for certain settings, such as locking accounts in place, preventing password modification, filtering web traffic, and shielding apps.
Posts under Managed Settings tag
105 Posts
Sort by:
Post
Replies
Boosts
Views
Activity
I have implemented a shielding mechanism via Family Controls to prevent unauthenticated users from deleting specific shortcuts within the Shortcuts app. While this successfully secures the app, it has an unintended consequence: the Shortcuts app no longer appears in Spotlight Search and becomes inaccessible for users subject to this shielding. I understand that this is the default behavior when implementing app shielding or time limits on specific apps. Is there a way to retain the app's visibility in Spotlight Search despite it being shielded?
we have corp own devices (ipad's) that need to disable the ability of users to turn off the location services as well as airplane mode and GPS, how this can be done?
Thanks in advance
I am developing a project with the Screen Time API, and I cannot understand why the methods inside DeviceActivityMonitor extension are not being called. Some points to note:
I do start by requesting authorization from the User (this is working as expected when opening the app)
Both the DeviceActivityMonitor Extension and the main app are under the same App Group
I have added Family Controls capability to both targets and have the developer account to use it.
I start by calling center.startMonitoring()
I have overridden the original methods.
Yet, when startMonitoring is called, there is no action that is supposed to be taken that is being taken, and as far as I can tell, the methods aren't even being called.
Here are some relevant snippets of code:
// EXT
class DeviceActivityMonitorExtension: DeviceActivityMonitor {
override func intervalDidStart(for activity: DeviceActivityName) {
super.intervalDidStart(for: activity)
let store = ManagedSettingsStore(named: .daily)
}
override func intervalDidEnd(for activity: DeviceActivityName) {
super.intervalDidEnd(for: activity)
let store = ManagedSettingsStore(named: .daily)
store.clearAllSettings()
}
override func eventDidReachThreshold(_ event: DeviceActivityEvent.Name, activity: DeviceActivityName) {
super.eventDidReachThreshold(event, activity: activity)
let store = ManagedSettingsStore(named: .daily)
let model = BeeFreeModel.shared
let applications = model.selectionToDiscourage.applicationTokens
let categories = model.selectionToDiscourage.categoryTokens
let webDomains = model.selectionToDiscourage.webDomainTokens
store.shield.applications = applications.isEmpty ?
nil : applications
store.shield.applicationCategories = categories.isEmpty ?
nil : ShieldSettings.ActivityCategoryPolicy.specific(categories)
store.shield.webDomains = webDomains.isEmpty ?
nil : webDomains
}
}
// APP
extension DeviceActivityName {
static let daily = Self("daily")
}
extension DeviceActivityEvent.Name {
static let discouraged = Self("discouraged")
}
let schedule = DeviceActivitySchedule(
intervalStart: DateComponents(hour: 0, minute: 0, second: 0),
intervalEnd: DateComponents(hour: 23, minute: 59, second: 59),
repeats: true
)
class BeeFreeSchedule {
static public func setSchedule() {
print("Setting schedule...")
print("Hour is: ", Calendar.current.dateComponents([.hour, .minute], from: Date()).hour!)
let events: [DeviceActivityEvent.Name: DeviceActivityEvent] = [
.discouraged: DeviceActivityEvent(
applications: BeeFreeModel.shared.selectionToDiscourage.applicationTokens,
categories: BeeFreeModel.shared.selectionToDiscourage.categoryTokens,
webDomains: BeeFreeModel.shared.selectionToDiscourage.webDomainTokens,
threshold: BeeFreeModel.shared.thresholdToDiscourage
)
]
let center = DeviceActivityCenter()
do {
print("Try to start monitoring...")
// Call startMonitoring with the activity name, schedule, and events
try center.startMonitoring(.daily, during: schedule, events: events)
} catch {
print("Error monitoring schedule: ", error)
}
}
}
// APP
class BeeFreeModel: ObservableObject {
// Import ManagedSettings to get access to the application shield restriction
let store = ManagedSettingsStore()
//@EnvironmentObject var store: ManagedSettingsStore
@Published var selectionToDiscourage: FamilyActivitySelection
@Published var thresholdToDiscourage: DateComponents
@Published var setOfApps: [String]
init() {
selectionToDiscourage = FamilyActivitySelection()
thresholdToDiscourage = DateComponents()
var setOfAppIdentifiers: Set<String?> = Set<String?>()
setOfApps = [String]()
if selectionToDiscourage.applicationTokens.isEmpty {}
else {
for application in BeeFreeModel.shared.selectionToDiscourage.applications {
setOfAppIdentifiers.insert(application.localizedDisplayName)
setOfApps = setOfAppIdentifiers.compactMap { $0 }.sorted()
}
}
}
class var shared: BeeFreeModel {
return _BeeFreeModel
}
func setSelection() {
let applications = BeeFreeModel.shared.selectionToDiscourage
}
func changeThreshold(threshold: DateComponents) {
thresholdToDiscourage = threshold
}
}
// APP
/// ...
Button("Select Apps to Discourage") {
isDiscouragedPresented = true
}
.familyActivityPicker(isPresented: $isDiscouragedPresented, selection: $model.selectionToDiscourage)
}
.onChange(of: model.selectionToDiscourage) {
BeeFreeModel.shared.setSelection()
}
// ...
// ...
Button("Save Time") {
saveTime()
let new_threshold = DateComponents(hour: savedTime?.hours,
minute: savedTime?.minutes,
second: savedTime?.seconds)
model.changeThreshold(threshold: new_threshold)
}
}
.onChange(of: model.thresholdToDiscourage) {
BeeFreeSchedule.setSchedule()
// ...
I believe I am using the latest stable version of Xcode (recently deleted and reinstalled). I'm really new to mobile development to Swift so any help is greatly appreciated.
Thank you! :)
Sometimes the app switcher doesn't show the correct shield configuration if there is like 7 or more apps in the app switcher.
if I clear all apps from app switcher cache and leave 4 apps, the correct shield configuration will show every time instantly when I change the shield configuration from my parent app and go back to the app switcher; but if there is like 7 or more apps in the app switcher, I can see some of the app's shield configurations don't update instantly and I have to scroll past the app in the app switcher and go back to for it to update to the correct shield if it does at all.
This is misleading to users and in the case of my app detrimental to one of its core functionalities
override func configuration(shielding application: Application) -> ShieldConfiguration {
let sharedUserDefaults = UserDefaults(suiteName: SharedUserDefaults.suiteName.rawValue)!
let isPaidOn = sharedUserDefaults.bool(forKey: SharedUserDefaults.paidSwitchKey.rawValue)
if isPaidOn == true {
return ShieldConfig.paid
} else {
return ShieldConfig.free
}
}
Starting with iOS 17.4, the DeviceActivityEvent initializer includes a new parameter named includesPastActivity.
The default value for this parameter is set to false, whereas device activity events have behaved as though this parameter were set to true up until now.
This breaking change is a MAJOR ISSUE for developers who used device activity events in their apps before iOS 17.4 because their apps might not work the way they intended after the update. They'll have to release new app versions that specifically set includesPastActivityto true.
In my opinion, the default value for includesPastActivity should be true to avoid disrupting events scheduled on older versions of iOS.
I have filed an enhancement report (FB13573556) about this. I really hope this is changed before the official iOS 17.4 release.
I am able to correctly select and store the tokens of apps and categories my users will block, but I am unable to pre-populate Picker whenever the app is rebooted with previously selected and stored tokens. Below is the selection variable I am passing to the picker...
var selectionsToBlock = FamilyActivitySelection() {
willSet {
saveSelection(selection: newValue)
blockersSelected = true
}
}
Is there any way I can provide my existing blockers (shown below) so that the user can easily edit their list of restricted apps from the Picker?
func savedBlockers() -> FamilyActivitySelection? {
let defaults = UserDefaults.standard
guard let data = defaults.data(forKey: userDefaultsKey) else {
return nil
}
return try? decoder.decode(
FamilyActivitySelection.self,
from: data
)
}
If I want to run Apple Search Ads (ASA) in two different countries, with one country managed by an agency and the other managed by myself, can I set up two separate ASA accounts for the same app?
I use App Groups to share UserDefaults data between my host app and DeviceActivityMonitor extension.
On iOS 17, it appears that reading @AppStorage variables are causing my DeviceActivityMonitor extension callback functions to crash. Weirdly, writing values is okay.
I see this in the extension logs:
Couldn't read values in CFPrefsPlistSource<0x10fe251d0> (Domain: GROUP_NAME, User: kCFPreferencesAnyUser, ByHost: Yes, Container: (null), Contents Need Refresh: Yes): Using kCFPreferencesAnyUser with a container is only allowed for System Containers, detaching from cfprefsd
However, through searching this log message on the internet and the fact that it also appears in my host app logs without crashing, this seems to be a warning - possibly indicating an issue but also a possible red herring.
But the fact remains that when I don't read UserDefaults values or variables decorated with @AppStorage in the DeviceActivityMonitor extension, everything works fine.
Are UserDefaults, and specifically @AppStorage decorators supported in the DeviceActivityMonitor extension?
I have posted this already in Feedback Assistant back in September with detailed steps to reproduce and have not heard back. Posting a brief overview here in hopes that Apple acknowledges and addresses this issue that is still present in recent Sonoma betas. This is preventing our organization from updating to Sonoma, however the Apple maximum update deferral timeline of 90 days is running out at Christmas.
The Switch User option is missing from the Lock Screen on macOS Sonoma if only one person has ever signed in for an enterprise device with an MDM pushed (and verified) configuration profile which allows user switching and network users to sign in to the device. It only shows users who are not hidden and have a home folder. This locks out all users without a hard reboot if nobody else exists on the device, or the user can do something that is very unintuitive if there are 2 or more users who have signed in. They can click any other user than the one who was logged in when the lockscreen process started, and that will let them erase the username of the user they clicked and log in themselves.
What is missing is "Other..." or "Switch User", which were on the Lock Screen for pervious versions of macOS. The login screen works just fine, it's the lock screen that's now ignoring configuration profiles or just doesn't have the same settings as the loginwindow process.
We have an app that uses the Screen Time APIs to block certain apps set by the user on a schedule:
We use ManagedSettings to shield selected apps
We use DeviceActivityMonitor to shield the apps automatically on a schedule set by the user. The shielding starts during the intervalDidStart callback function and ends during the intervalDidEnd callback function
We are getting reports from the majority of our iOS 17 users that the app blocking schedules no longer work on iOS 17. We have tested this on our own iOS 17 devices and reproduced the behavior. But the feature still works consistently on iOS 16 devices.
The app is still built using Xcode 14 instead of Xcode 15 due to another issue - the DeviceActivityReport is blank for all iOS 16 users when built in Xcode 15 (link to issue on the developer forums: https://developer.apple.com/forums/thread/735915). When testing with Xcode 15 builds, the bug appears to improve - however it still occurs intermittently.
Are there any other mechanisms to run tasks on repeating schedules? For this specific feature, we don't need to eventDidReachThreshold callbacks, which is the main purpose of DeviceActivityMonitor. So we really don't need any Device Activity integration at all, just setting and disabling ManagedSettings shields at certain times. Would love if anyone could suggest and alternative to DeviceActivityMonitor.
Any way that I try requesting authorization for family controls is incredibly inconsistent.
The line of code that hangs is **let center = AuthorizationCenter.shared **
I've looked at other posts and I saw someone recommended declaring let center = AuthorizationCenter.shared outside the main thread and somehow get the status on the main thread. I've tried that approach with no success. I've scoured GitHub to see how other people approach the request but it's all pretty similar.
The following code sometimes works great for a few minutes and then I rebuild and run and it hangs on AuthorizationCenter.shared.requestAuthorization(for: FamilyControlsMember.individual). Would love any suggestions!!!
.onAppear {
Task {
do {
print("try requestAuthorization")
try await AuthorizationCenter.shared.requestAuthorization(for: FamilyControlsMember.individual)
print("requestAuthorization success")
switch AuthorizationCenter.shared.authorizationStatus {
case .notDetermined:
print("not determined")
case .denied:
print("denied")
case .approved:
print("approved")
@unknown default:
break
}
} catch {
print("Error requestAuthorization: ", error)
}
}
}
I have gained the PassKit access, but don't know how to configure com. Apple. Developer. PassKit. Pass the presentation - suppression the permissions.
Who can tell us the detailed process, which Capabilities should be configured in the App ID?
DL;DR: Sometimes the API fails to unblock the app and leaves an hourglass shield on the restricted apps, which is not set by us. Even worse, if we remove authorization of our app from Settings, the restricted apps remain locked until we restart the phone or re-run our app from Xcode.
Our app monitors the usage of selected apps from the current time until the reset time at 4:00 a.m.
When the given threshold is reached, the selected apps are shielded.
After the user taps the close button on the shield view, we attempt to remove the shield, set up a new threshold monitoring and close the app.
The issue is that: sometimes the shield removal fails, and after the app closes itself, it remains shielded, and displays an hourglass shield view that was never in our shield configuration.
Additionally, regardless of what we do-removing the shielding from our apps or removing the authorization of our app from Settings, the restricted apps remain shielded until we restart the phone or re-run our app from Xcode.
Code I use for un-shielding:
warningUsageStore.clearAllSettings()
Code I use for scheduling the threshold:
var warningMinute = userDefaults.integer(forKey: .warningMinute)
if warningMinute <= 0 { warningMinute = 5 }
let selection = familyActivitySelection()
let now = Date.now
let start = Calendar.current.dateComponents([.hour, .minute, .second], from: now)
var end = AppConfig.resetEndTime
// use twenty minutes later as the end time if the before reset time is too near e.g. warning start at 3:55 but reset time is 4:00
if let endDate = Calendar.current.nextDate(after: now, matching: end, matchingPolicy: .nextTime), endDate.timeIntervalSince(now) <= 15*60 {
end = Calendar.current.dateComponents([.hour, .minute, .second], from: now.addingTimeInterval(20*60))
}
// add inidividual event according to the hash value to dintinguish between apps.
var events = [DeviceActivityEvent.Name : DeviceActivityEvent]()
for application in selection.applications where application.token != nil {
events[.init(application.hashValue.description)] = .init(applications: [application.token!], threshold: .init(minute: warningMinute))
}
for category in selection.categories where category.token != nil {
events[.init(category.hashValue.description)] = .init(categories: [category.token!], threshold: .init(minute: warningMinute))
}
for webDomain in selection.webDomains where webDomain.token != nil {
events[.init(webDomain.hashValue.description)] = .init(webDomains: [webDomain.token!], threshold: .init(minute: warningMinute))
}
try deviceActivityCenter.startMonitoring(.usageWarning, during: .init(intervalStart: start, intervalEnd: end, repeats: false), events: events)
The issue happens on my iPhone11 iOS17.1.2
Any insight would be much appreciated. Thank you!
Hello,
I wasn't able to figure out how to handle multiple days with DeviceActivitySchedule.
For instance, let's say the user wants to block certain apps from 9:00 AM to 12:00 AM, every day except Saturday and Sunday, how my schedule should look like?
I've tried different things...
This schedule works for each day of the week, but that's not my goal:
let schedule = DeviceActivitySchedule(
intervalStart: DateComponents(hour: 9, minute: 00),
intervalEnd: DateComponents(hour: 12, minute: 00),
repeats: true)
And if I specify the weekDay inside the DateComponents, like this:
// Gregorian calendar
// 2 -> Monday
// 6 -> Friday
let schedule = DeviceActivitySchedule(
intervalStart: DateComponents(..., weekday: 2),
intervalEnd: DateComponents(..., weekday: 6),
repeats: true)
the schedule will block the apps from Monday at 9:00 AM to Friday at 12:00 AM, which is also not my goal.
The only workaround that came to my mind was to create a different schedule for each day of the week:
enum WeekDays: String, CaseIterable {
case sun, mon, tue, wed, thu, fri, sat
var sortOrder: Int {
switch self {
case .sun: return 1
case .mon: return 2
case .tue: return 3
case .wed: return 4
case .thu: return 5
case .fri: return 6
case .sat: return 7
}
}
}
func startMonitoring(weekDays: [WeekDays]) {
for weekDay in weekDays {
let day = weekDay.sortOrder
let schedule = DeviceActivitySchedule(
intervalStart: DateComponents(
hour: 9,
minute: 00,
weekday: day),
intervalEnd: DateComponents(
hour: 12,
minute: 00,
weekday: day),
repeats: true)
let activityName = DeviceActivityName(weekDay.rawValue)
do {
try center.startMonitoring(activityName,
during: schedule)
} catch {
print("DEBUG: Error: \(error.localizedDescription)")
}
}
}
This way I kinda get what I want, for example:
I can specify 3 days of the week, let's say Monday, Tuesday and Wednesday, the time interval, let's keep 9:00 AM - 12:00 AM, and this function will block apps on Monday, Tuesday and Wednesday at that time interval, fine.
However...
What if I also want another schedule that blocks at a different time interval but same day?
For example, I want to block certain apps Monday and Tuesday from 2:00 PM - 6:00 PM.
Following the example above the activityName would be overwritten, so the user ( for Monday and Tuesday ) would now have only the schedules that starts from 2:00 PM.
Basically, I want the user to be able to select multiple days for a schedule and to let them create as many schedules as they want.
Does anybody know the correct way to handle multiple days schedules?
Hello,
I'm currently experiencing an issue with the DeviceActivityMonitor extension in my code, specifically with the eventDidReachThreshold callback. I'm hoping to get some insights into why this problem occurs and how to resolve it.
Problem:
Issue 1: The eventDidReachThreshold callback is not triggering as expected. It appears that the callback is not being invoked when the threshold is reached.
Issue 2: After a few seconds, the eventDidReachThreshold callback starts to trigger multiple times. This unexpected behavior is causing problems in my code, as it results in incorrect actions being taken.
Issue 3: There are instances where the eventDidReachThreshold callback provides an incorrect event name.
iOS version: iOS16.7.2 and iOS17.1.1
Here is my code to start the monitoring:
func startMonitoring() {
var startTime : DateComponents = DateComponents(hour: 0, minute: 0)
let endTime : DateComponents = DateComponents(hour: 23, minute: 59)
/// Creates the schedule for the activity, specifying the start and end times, and setting it to repeat.
let schedule = DeviceActivitySchedule(intervalStart: startTime, intervalEnd: endTime, repeats: true, warningTime: nil)
/// Defines the event that should trigger the encouragement.
let event = DeviceActivityEvent(applications: socialActivitySelection.applicationTokens, categories: socialActivitySelection.categoryTokens, webDomains: socialActivitySelection.webDomainTokens, threshold: DateComponents(minute: 2))
let events: [DeviceActivityEvent.Name: DeviceActivityEvent] = [.socialScreenTimeEvent : event]
do {
activityCenter.stopMonitoring([.socialScreenTime])
/// Tries to start monitoring the activity using the specified schedule and events.
try activityCenter.startMonitoring(.socialScreenTime, during: schedule, events: events)
} catch {
/// Prints an error message if the activity could not be started.
print("Could not start monitoring: \(error)")
}
}
In addition, I should mention that, with each iteration through the eventDidReachThreshold callback, I increment the threshold by 2 minutes and restart the monitoring.
If there are any known workarounds or potential solutions, please share them.
Thank you.
My app sends screen time awareness notifications based on DeviceActivityMonitor thresholds.
Often, users receive two notifications in a row for the same screen time threshold. This means that the app extension is triggering the same eventDidReachThreshold callback function twice for the same threshold. I've made sure that there is only one activity schedule being monitored. This happens often, but not every time (over 50% of the time).
Anybody else experience this issue, and any way to mitigate it?
Hello Apple Developer Community,
We're experiencing a critical issue with the Screen Time frameworks, and it's affecting one of our users severely. I'm hoping someone here can provide guidance or a potential solution.
Details:
Our app offers a feature using the ManagedSettings shield that lets users block all apps based on a set schedule.
After the scheduled block ends, the apps are expected to become accessible again.
In one case, a user reported that the apps did not unblock after the schedule ended.
Upon trying to manually end the session from within our app, the app only displays a blank white screen.
The user attempted to disable Screen Time access for our app via the iOS settings, but the apps remained blocked.
Even after completely disabling Screen Time from the settings or restarting the phone, the apps stayed blocked.
Interestingly, I attempted to replicate the issue on my end by toggling Screen Time settings and restarting, but everything worked as expected and I could not reproduce the problem.
This issue, though seemingly isolated, has rendered a user's phone virtually unusable, and highlights a potential high-impact bug within the Screen Time framework. It feels necessary for there to be a "master off-switch" or a fail-safe mechanism in these scenarios.
Any insights, solutions, or workarounds would be deeply appreciated. It's crucial for us to support our user and resolve this promptly.
Thank you in advance!
Hi !
We are super exited to switch to Xcode 15 when it will be released, but we have a major issue :
Apps built with Xcode 15 beta fail to show DeviceActivityReport base view on iOS 16.
The following message shows in the console :
] [default] LaunchServices: store (null) or url (null) was nil: Error Domain=NSOSStatusErrorDomain Code=-54 "process may not map database" UserInfo={NSDebugDescription=process may not map database, _LSLine=66, _LSFunction=_LSServer_GetServerStoreForConnectionWithCompletionHandler}
2023-07-31 14:54:12.568332+0200 Opal[57940:4651501] [default] Attempt to map database failed: permission was denied. This attempt will not be retried.
2023-07-31 14:54:12.568420+0200 Opal[57940:4651501] [db] Failed to initialize client context with error Error Domain=NSOSStatusErrorDomain Code=-54 "process may not map database" UserInfo={NSDebugDescription=process may not map database, _LSLine=66, _LSFunction=_LSServer_GetServerStoreForConnectionWithCompletionHandler}
We Opened a bug report at the end of june but got no answer from Apple (FB12416769). It's 100% reproductible with a very simple sample project
If you guys could report the issue as well, it would be nice !
Hi there,
In rare cases (about 0.2% of the time?), I'm seeing calls to startMonitoring on an instance of DeviceActivityCenter throw an error with localizedDescription "couldn’t communicate with a helper application."
I am certain I am passing valid parameters to the startMonitoring call because sometimes a naive retry after a few seconds succeeds. Similarly, I am certain that FamilyControls permissions have been granted by the user.
Was hoping to get more color from the systems team on what some causes of this error are and if it is avoidable by the programmer.