我们正在尝试将Xamarin
构建的应用程序部署到Apple
appstore,因此我们需要将应用程序迁移到Unified Api
以获得64位支持。升级到最新版本的Xamarin.iOS
(版本:8.8.2.4)并将应用程序迁移到Unified Api
后,我们现在收到以下编译错误:
Cannot access protected member 'Foundation.NSDictionary.NSDictionary(System.IntPtr)' via a qualifier of type 'Foundation.NSDictionary'.
此行发生错误:
NSDictionary prefSpecification = new NSDictionary(preferences.ValueAt(i));
此方法调用:
public static void RegisterDefaultsFromSettingsBundle()
{
string settingsBundle = NSBundle.MainBundle.PathForResource("Settings", @"bundle");
if(settingsBundle == null) {
System.Console.WriteLine(@"Could not find Settings.bundle");
return;
}
NSString keyString = new NSString(@"Key");
NSString defaultString = new NSString(@"DefaultValue");
NSDictionary settings = NSDictionary.FromFile(Path.Combine(settingsBundle,@"Root.plist"));
NSArray preferences = (NSArray) settings.ValueForKey(new NSString(@"PreferenceSpecifiers"));
NSMutableDictionary defaultsToRegister = new NSMutableDictionary();
for (uint i=0; i<preferences.Count; i++) {
NSDictionary prefSpecification = new NSDictionary(preferences.ValueAt(i));
NSString key = (NSString) prefSpecification.ValueForKey(keyString);
if(key != null) {
NSObject def = prefSpecification.ValueForKey(defaultString);
if (def != null) {
defaultsToRegister.SetValueForKey(def, key);
}
}
}
NSUserDefaults.StandardUserDefaults.RegisterDefaults(defaultsToRegister);
}
任何人都可以解释为什么会发生这种情况以及我如何解决这个问题?
答案 0 :(得分:2)
根据Apple docs, PreferenceSpecifiers 是一个字典数组,所以不要这样做:
NSDictionary prefSpecification = new NSDictionary(preferences.ValueAt(i));
你应该可以这样做:
NSDictionary prefSpecification = (NSDictionary)preferences.ValueAt(i);
<强> Udated 强>
如果您正在使用新的统一API,则必须将所需的类(在本例中为NSDictionary)子类化,以便访问this Xamarin docs中所述的NSDictionary(IntPtr)构造函数。
希望有所帮助