{
	"id": "d2a17581-0e6e-4d6c-b12d-fc2b30056351",
	"created_at": "2026-04-06T00:13:46.502935Z",
	"updated_at": "2026-04-10T13:12:50.096755Z",
	"deleted_at": null,
	"sha1_hash": "207831f7ef9fd3c8fa19720b2fa9fa3d536b3624",
	"title": "NSBackgroundActivityScheduler | Apple Developer Documentation",
	"llm_title": "",
	"authors": "",
	"file_creation_date": "0001-01-01T00:00:00Z",
	"file_modification_date": "0001-01-01T00:00:00Z",
	"file_size": 78988,
	"plain_text": "NSBackgroundActivityScheduler | Apple Developer\r\nDocumentation\r\nArchived: 2026-04-05 19:20:06 UTC\r\nOverview\r\nUse an NSBackgroundActivityScheduler object to schedule an arbitrary maintenance or background task. It’s\r\nsimilar to an Timer object, in that it lets you schedule a repeating or non-repeating task. However, NSBackground\r\nActivityScheduler gives the system flexibility to determine the most efficient time to execute based on energy\r\nusage, thermal conditions, and CPU use.\r\nFor example, use an NSBackgroundActivityScheduler object to schedule:\r\nAutomatic saves\r\nBackups\r\nData maintenance\r\nPeriodic content fetches\r\nInstallation of updates\r\nActivities occurring in intervals of 10 minutes or more\r\nAny other deferrable task\r\nFor information about performing non-deferrable tasks efficiently, see Specify Nondeferrable Background\r\nActivities in Energy Efficiency Guide for Mac Apps.\r\nCreate a Scheduler\r\nTo initialize a scheduler, call init(identifier:) for NSBackgroundActivityScheduler , and pass it a unique\r\nidentifier string in reverse DNS notation ( nil and zero-length strings are not allowed) that remains constant\r\nacross launches of your application.\r\nSwift\r\nObjective-C\r\nlet activity = NSBackgroundActivityScheduler(identifier: \"com.example.MyApp.updatecheck\")\r\nConfigure Scheduler Properties\r\nhttps://developer.apple.com/documentation/foundation/nsbackgroundactivityscheduler\r\nPage 1 of 4\n\nConfigure the scheduler with any of the following scheduling properties:\r\nrepeats —If set to true , the activity is rescheduled at the specified interval after finishing.\r\ninterval —For repeating schedulers, the average interval between invocations of the activity. For\r\nnonrepeating schedulers, interval is the suggested interval of time between scheduling the activity and\r\nthe invocation of the activity.\r\ntolerance —The amount of time before or after the nominal fire date when the activity should be\r\ninvoked. The nominal fire date is calculated by using the interval combined with the previous fire date or\r\nthe time when the activity is started. These two properties create a window in time, during which the\r\nactivity may be scheduled. The system will more aggressively schedule the activity as it nears the end of\r\nthe grace period after the nominal fire date. The default value is half the interval.\r\nqualityOfService —The default value is NSQualityOfServiceBackground . If you upgrade the quality of\r\nservice above this level, the system schedules the activity more aggressively. The default value is the\r\nrecommended value for most activities. For information on quality of service, see Prioritize Work at the\r\nTask Level in Energy Efficiency Guide for Mac Apps.\r\nThe next three code examples demonstrate different scheduling scenarios.\r\nScheduling an activity to fire in the next 10 minutes\r\nScheduling an activity to fire between 15 and 45 minutes from now\r\nScheduling an activity to fire once each hour\r\nSchedule Activity with scheduleWithBlock:\r\nWhen you’re ready to schedule the activity, call scheduleWithBlock: and provide a block of code to execute\r\nwhen the scheduler runs, as shown in the following example. The block will be called on a serial background\r\nqueue appropriate for the level of quality of service specified. The system automatically uses the begin\r\nActivity(options:reason:) method (of ProcessInfo ) while invoking the block, choosing appropriate options\r\nbased on the specified quality of service.\r\nWhen your block is called, it’s passed a completion handler as an argument. Configure the block to invoke this\r\nhandler, passing it a result of type NSBackgroundActivityScheduler.Result to indicate whether the activity\r\nfinished ( NSBackgroundActivityScheduler.Result.finished ) or should be deferred ( NSBackgroundActivity\r\nScheduler.Result.deferred ) and rescheduled for a later time. Failure to invoke the completion handler results in\r\nthe activity not being rescheduled. For work that will be deferred and rescheduled, the block may optionally adjust\r\nscheduler properties, such as interval or tolerance , before calling the completion handler.\r\nScheduling background activity\r\nSwift\r\nObjective-C\r\nhttps://developer.apple.com/documentation/foundation/nsbackgroundactivityscheduler\r\nPage 2 of 4\n\nactivity.scheduleWithBlock() { (completion: NSBackgroundActivityCompletionHandler) in\r\n // Perform the activity\r\n self.completion(NSBackgroundActivityResult.Finished)\r\n}\r\nDetect Whether to Defer Activity\r\nIt’s conceivable that while a lengthy activity is running, conditions may change, resulting in the activity now\r\nrequiring deferral. For example, perhaps the user has unplugged the Mac and it’s now running on battery power.\r\nYour activity can call shouldDefer to determine whether this has occurred. A value of true indicates that the\r\nblock should finish what it’s currently doing and invoke its completion handler with a value of NSBackground\r\nActivityScheduler.Result.deferred . See the following example.\r\nDetecting deferred background activity\r\nSwift\r\nObjective-C\r\nif activity.shouldDefer {\r\n // Wrap up processing and prepare to defer activity\r\n self.completion(NSBackgroundActivityResult.Deferred)\r\n} else {\r\n // Continue processing\r\n self.completion(NSBackgroundActivityResult.Finished)\r\n}\r\nStop Activity\r\nCall invalidate() to stop scheduling an activity, as shown in the following example.\r\nStopping background activity\r\nSwift\r\nObjective-C\r\nTopics\r\nBackground Scheduler Attributes\r\nvar identifier: String\r\nA unique reverse DNS notation string, such as com.example.MyApp.updatecheck , that identifies the activity.\r\nvar repeats: Bool\r\nA Boolean value indicating whether the activity should be rescheduled after it completes.\r\nhttps://developer.apple.com/documentation/foundation/nsbackgroundactivityscheduler\r\nPage 3 of 4\n\nvar shouldDefer: Bool\r\nA Boolean value indicating whether your app should stop performing background activity and resume at a more\r\noptimal time.\r\nConstants\r\nenum Result\r\nThese constants indicate whether background activity has been completed successfully or whether additional\r\nprocessing should be deferred until a more optimal time.\r\nSource: https://developer.apple.com/documentation/foundation/nsbackgroundactivityscheduler\r\nhttps://developer.apple.com/documentation/foundation/nsbackgroundactivityscheduler\r\nPage 4 of 4",
	"extraction_quality": 1,
	"language": "EN",
	"sources": [
		"MITRE"
	],
	"origins": [
		"web"
	],
	"references": [
		"https://developer.apple.com/documentation/foundation/nsbackgroundactivityscheduler"
	],
	"report_names": [
		"nsbackgroundactivityscheduler"
	],
	"threat_actors": [],
	"ts_created_at": 1775434426,
	"ts_updated_at": 1775826770,
	"ts_creation_date": 0,
	"ts_modification_date": 0,
	"files": {
		"pdf": "https://archive.orkl.eu/207831f7ef9fd3c8fa19720b2fa9fa3d536b3624.pdf",
		"text": "https://archive.orkl.eu/207831f7ef9fd3c8fa19720b2fa9fa3d536b3624.txt",
		"img": "https://archive.orkl.eu/207831f7ef9fd3c8fa19720b2fa9fa3d536b3624.jpg"
	}
}