MDM推送設定值到 iOS device
透過 mdm 派送 settings 到 iOS app 的方法是透過 ApplicationConfiguration 指令來派送,ApplicationConfiguration指令要能正確執行的前提是:
- 被派送 settings 的 app 必需是被管控制。
(透過 InstallApplication command 去安裝)
出錯之後,MDM 告訴我們的Error Message:
<key>Settings</key> <array> <dict> <key>ErrorChain</key> <array> <dict> <key>ErrorCode</key> <integer>12038</integer> <key>ErrorDomain</key> <string>MCMDMErrorDomain</string> <key>LocalizedDescription</key> <string>App「app id」不受管理。</string> <key>USEnglishDescription</key> <string>The app “app id” is not managed.</string> </dict> </array>
Managed app configuration changes that are pushed down from an MDM server appear in NSUSerDefaults
so you can add an observer to be alerted of any changes to NSUserDefaults
. The Managed app configuration dictionary pushed down from the MDM server is stored in the key named: com.apple.configuration.managed
Your application can also send a dictionary containing the feedback to the MDM server. The dictionary that is sent back to the MDM server as feedback must be stored in this key com.apple.feedback.managed
In order to test all of this you would need a device that is managed by an MDM server and the application must be installed by the MDM server that supports ApplicationConfiguration setting and ManagedApplicationFeedback commands.
The sample application’s readme.txt file recommends seeing the WWDC 2013 Session 301 “Extending Your Apps for Enterprise and Education Use” for a demo of this application.
to read the config (swift 3):
if let managedConf = UserDefaults.standard.object(forKey: "com.apple.configuration.managed") as? [String:Any?] {
if let serverURL = managedConf["serverURL"] as? String{
return serverURL
}
}
if let serverURL = Bundle.main.object(forInfoDictionaryKey: "serverURL") as? String {
return serverURL
}
return "https://apple.com/"
as you can see – the app needs to manually enable reading from MDM bundle configuration.
P,S: only managed apps can get those configs.
資料來源:
範例:
// The Managed app configuration dictionary pushed down from an MDM server are stored in this key. static NSString * const kConfigurationKey = @"com.apple.configuration.managed"; // This sample application allows for a server url and cloud document switch to be configured via MDM // Application developers should document feedback dictionary keys, including data types and valid value ranges. static NSString * const kConfigurationServerURLKey = @"serverURL"; static NSString * const kConfigurationDisableCloudDocumentSyncKey = @"disableCloudDocumentSync"; // The dictionary that is sent back to the MDM server as feedback must be stored in this key. static NSString * const kFeedbackKey = @"com.apple.feedback.managed"; // This sample application tracks a success and failure count for the loading of a UIWebView. // Application developers should document feedback dictionary keys including data types to expect for feedback queries static NSString * const kFeedbackSuccessCountKey = @"successCount"; static NSString * const kFeedbackFailureCountKey = @"failureCount"; - (void)readDefaultsValues { NSDictionary *serverConfig = [[NSUserDefaults standardUserDefaults] dictionaryForKey:kConfigurationKey]; NSString *serverURLString = serverConfig[kConfigurationServerURLKey]; // Data coming from MDM server should be validated before use. // If validation fails, be sure to set a sensible default value as a fallback, even if it is nil. if (serverURLString && [serverURLString isKindOfClass:[NSString class]]) { self.serverURLUILabel.text = serverURLString; } else { self.serverURLUILabel.text = @"http://foo.bar"; } NSNumber *disableCloudDocumentSync = serverConfig[kConfigurationDisableCloudDocumentSyncKey]; if (disableCloudDocumentSync && [disableCloudDocumentSync isKindOfClass:[NSNumber class]]) { self.cloudDocumentSyncEnabledSwitch.on = ![disableCloudDocumentSync boolValue]; } else { self.cloudDocumentSyncEnabledSwitch.on = YES; } // Fetch the success and failure count values from NSUserDefaults to display. // Data validation for feedback values is a good idea, in case the application wrote out an unexpected value. NSDictionary *feedback = [[NSUserDefaults standardUserDefaults] dictionaryForKey:kFeedbackKey]; NSNumber *successCount = feedback[kFeedbackSuccessCountKey]; if (successCount && [successCount isKindOfClass:[NSNumber class]]) { self.successCount = [successCount unsignedIntegerValue]; } else { self.successCount = 0; } self.successUILabel.text = [NSString stringWithFormat:@"%lu", (unsigned long)self.successCount]; NSNumber *failureCount = feedback[kFeedbackFailureCountKey]; if (failureCount && [failureCount isKindOfClass:[NSNumber class]]) { self.failureCount = [failureCount unsignedIntegerValue]; } else { self.failureCount = 0; } self.failureUILabel.text = [NSString stringWithFormat:@"%lu", (unsigned long)self.failureCount]; }