1. Home
  2. Docs
  3. Details
  4. Technical Specification
  5. iOS Mobile Sample Code

iOS Mobile Sample Code

iOS code to enable renaming a device with the 0$S prefix. Please note, this automation will
require permissions

@IBAction func changeNamePressed(_ sender: Any) {
		let alert = UIAlertController(title: "Alert", message: "Go to About > Name and Type \"0$S\" in front of your current device name to enable the 0 $S Global Opt - Out Mechanism ", preferredStyle: .alert)
			let cancelAction = UIAlertAction(title: "Cancel", style: .destructive)
			let okAction = UIAlertAction(title: "Ok", style: .default, handler: {
				action in
				self.openSettings()
			})
			alert.addAction(cancelAction) alert.addAction(okAction) self.present(alert, animated: true)
		}
		func openSettings() {
			if let url = URL(string: UIApplication.openSettingsURLString) {
				if UIApplication.shared.canOpenURL(url) {
					UIApplication.shared.open(url, options: [: ], completionHandler: nil)
				}
			}
		}

iOS sample code an app can use to read the name of the device on which it is installed and
determine if it includes the “0$S” prefix and trigger an opt-out or not.

if UIDevice.current.name.hasPrefix("0$S") {
	print("Universal Opt Out Enabled")
} else {
	print("Universal Opt Out Disabled")
}

How can we help?