使用 App Configuration 的好處是使用者不用重新輸入資料,可以透過MDM派送相關的設定值給APP.
Apple 官方文章:
https://developer.apple.com/library/content/samplecode/sc2279/Introduction/Intro.html
Managed App Configuration
Last Revision: |
Version 1.0, 2013-10-01
“ManagedAppConfig” demonstrates how to implement managed app configuration and feedback support in an iOS app. |
Build Requirements: |
Xcode 5.0 or later; iOS SDK 7 or later.
|
Runtime Requirements: |
iOS 7 or later.
|
“ManagedAppConfig” demonstrates how to implement managed app configuration and feedback support in an iOS application. This functionality allows a Mobile Device Management (MDM) server to push down a dictionary into the managed app’s NSUserDefaults for the purposes of remotely configuring settings. Also, feedback (such as critical errors) can be written by the app into NSUserDefaults which can then be queried by an MDM server. This is a powerful mechanism enterprise and educational institutions can use to remotely configure managed applications from a centralized MDM server.
Apple 官方的 sample code:
– (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];
}