从MonoTouch访问iCloud NSUbiquitousKeyValueStoreDidChangeExternallyNotification详细信息(Accessing iCloud NSUbiquitousKeyValueStoreDidChangeExternallyNotification details from MonoTouch)

在MonoTouch下,我想访问NSUbiquitousKeyValueStoreDidChangeExternallyNotification(iOS5 / iCloud键值入站更新)通知数据:

NSUbiquitousKeyValueStoreChangeReasonKey - > NSNumber NSUbiquitousKeyValueStoreChangedKeysKey - > NSString的NSArray

有一个示例@ http://docs.xamarin.com/@api/deki/files/321/=iCloud.zip ,但上面访问的代码已被注释掉并且有错误(它如何尝试将原因转换为整数是错的)。 我在这附近:

NSNotificationCenter.DefaultCenter.AddObserver(new NSString("NSUbiquitousKeyValueStoreDidChangeExternallyNotification"), delegate(NSNotification n) { NSDictionary userInfo = n.UserInfo; NSNumber reason = (NSNumber)userInfo.ObjectForKey( new NSString("NSUbiquitousKeyValueStoreChangeReasonKey")); int ireason = reason.IntValue; NSArray changedKeys = (NSArray)userInfo.ObjectForKey( new NSString("NSUbiquitousKeyValueStoreChangedKeysKey")); });

我想出了如何将理由作为整数。 但是如何将NSStrings的NSArray转换为简单的字符串[]? 我以前从未使用过核心的Objective-C类包装器,抱歉。

Under MonoTouch, I'd like to access NSUbiquitousKeyValueStoreDidChangeExternallyNotification (iOS5/iCloud key-value inbound update) notification data:

NSUbiquitousKeyValueStoreChangeReasonKey -> NSNumber NSUbiquitousKeyValueStoreChangedKeysKey -> NSArray of NSString

There is a sample @ http://docs.xamarin.com/@api/deki/files/321/=iCloud.zip, but the code to access above is commented out and is buggy (how it tries to convert reason to integer is wrong). I am close here:

NSNotificationCenter.DefaultCenter.AddObserver(new NSString("NSUbiquitousKeyValueStoreDidChangeExternallyNotification"), delegate(NSNotification n) { NSDictionary userInfo = n.UserInfo; NSNumber reason = (NSNumber)userInfo.ObjectForKey( new NSString("NSUbiquitousKeyValueStoreChangeReasonKey")); int ireason = reason.IntValue; NSArray changedKeys = (NSArray)userInfo.ObjectForKey( new NSString("NSUbiquitousKeyValueStoreChangedKeysKey")); });

I figured out how to get reason as integer. But how do I convert the NSArray of NSStrings to a simple string[]?? I've never had to work with the core Objective-C type wrappers before, sorry.

最满意答案

希望这有助于〜使用从NSArray.ValueAt()方法返回的IntPtr来新建一个NSString并访问您所追求的值。

NSNotificationCenter.DefaultCenter.AddObserver ( NSUbiquitousKeyValueStore.DidChangeExternallyNotification , delegate (NSNotification n) { Console.WriteLine("Cloud notification received"); NSDictionary userInfo = n.UserInfo; NSNumber reason = (NSNumber)userInfo.ObjectForKey(NSUbiquitousKeyValueStore.ChangeReasonKey); int ireason = reason.IntValue; Console.WriteLine("reason.IntValue: " + ireason); NSArray changedKeys = (NSArray)userInfo.ObjectForKey (NSUbiquitousKeyValueStore.ChangedKeysKey); var changedKeysList = new System.Collections.Generic.List<string> (); for (uint i = 0; i < changedKeys.Count; i++) { var key = new NSString (changedKeys.ValueAt(i)); Console.WriteLine("changedKey IntPtr: " + changedKeys.ValueAt(i)); Console.WriteLine("changedKey (value): " + key); changedKeysList.Add (key); } // now do something with the list... });

Hope this helps ~ uses the IntPtr returned from the NSArray.ValueAt() method to new up an NSString and access the values you're after.

NSNotificationCenter.DefaultCenter.AddObserver ( NSUbiquitousKeyValueStore.DidChangeExternallyNotification , delegate (NSNotification n) { Console.WriteLine("Cloud notification received"); NSDictionary userInfo = n.UserInfo; NSNumber reason = (NSNumber)userInfo.ObjectForKey(NSUbiquitousKeyValueStore.ChangeReasonKey); int ireason = reason.IntValue; Console.WriteLine("reason.IntValue: " + ireason); NSArray changedKeys = (NSArray)userInfo.ObjectForKey (NSUbiquitousKeyValueStore.ChangedKeysKey); var changedKeysList = new System.Collections.Generic.List<string> (); for (uint i = 0; i < changedKeys.Count; i++) { var key = new NSString (changedKeys.ValueAt(i)); Console.WriteLine("changedKey IntPtr: " + changedKeys.ValueAt(i)); Console.WriteLine("changedKey (value): " + key); changedKeysList.Add (key); } // now do something with the list... });从MonoTouch访问iCloud NSUbiquitousKeyValueStoreDidChangeExternallyNotification详细信息(Accessing iCloud NSUbiquitousKeyValueStoreDidChangeExternallyNotification details from MonoTouch)

在MonoTouch下,我想访问NSUbiquitousKeyValueStoreDidChangeExternallyNotification(iOS5 / iCloud键值入站更新)通知数据:

NSUbiquitousKeyValueStoreChangeReasonKey - > NSNumber NSUbiquitousKeyValueStoreChangedKeysKey - > NSString的NSArray

有一个示例@ http://docs.xamarin.com/@api/deki/files/321/=iCloud.zip ,但上面访问的代码已被注释掉并且有错误(它如何尝试将原因转换为整数是错的)。 我在这附近:

NSNotificationCenter.DefaultCenter.AddObserver(new NSString("NSUbiquitousKeyValueStoreDidChangeExternallyNotification"), delegate(NSNotification n) { NSDictionary userInfo = n.UserInfo; NSNumber reason = (NSNumber)userInfo.ObjectForKey( new NSString("NSUbiquitousKeyValueStoreChangeReasonKey")); int ireason = reason.IntValue; NSArray changedKeys = (NSArray)userInfo.ObjectForKey( new NSString("NSUbiquitousKeyValueStoreChangedKeysKey")); });

我想出了如何将理由作为整数。 但是如何将NSStrings的NSArray转换为简单的字符串[]? 我以前从未使用过核心的Objective-C类包装器,抱歉。

Under MonoTouch, I'd like to access NSUbiquitousKeyValueStoreDidChangeExternallyNotification (iOS5/iCloud key-value inbound update) notification data:

NSUbiquitousKeyValueStoreChangeReasonKey -> NSNumber NSUbiquitousKeyValueStoreChangedKeysKey -> NSArray of NSString

There is a sample @ http://docs.xamarin.com/@api/deki/files/321/=iCloud.zip, but the code to access above is commented out and is buggy (how it tries to convert reason to integer is wrong). I am close here:

NSNotificationCenter.DefaultCenter.AddObserver(new NSString("NSUbiquitousKeyValueStoreDidChangeExternallyNotification"), delegate(NSNotification n) { NSDictionary userInfo = n.UserInfo; NSNumber reason = (NSNumber)userInfo.ObjectForKey( new NSString("NSUbiquitousKeyValueStoreChangeReasonKey")); int ireason = reason.IntValue; NSArray changedKeys = (NSArray)userInfo.ObjectForKey( new NSString("NSUbiquitousKeyValueStoreChangedKeysKey")); });

I figured out how to get reason as integer. But how do I convert the NSArray of NSStrings to a simple string[]?? I've never had to work with the core Objective-C type wrappers before, sorry.

最满意答案

希望这有助于〜使用从NSArray.ValueAt()方法返回的IntPtr来新建一个NSString并访问您所追求的值。

NSNotificationCenter.DefaultCenter.AddObserver ( NSUbiquitousKeyValueStore.DidChangeExternallyNotification , delegate (NSNotification n) { Console.WriteLine("Cloud notification received"); NSDictionary userInfo = n.UserInfo; NSNumber reason = (NSNumber)userInfo.ObjectForKey(NSUbiquitousKeyValueStore.ChangeReasonKey); int ireason = reason.IntValue; Console.WriteLine("reason.IntValue: " + ireason); NSArray changedKeys = (NSArray)userInfo.ObjectForKey (NSUbiquitousKeyValueStore.ChangedKeysKey); var changedKeysList = new System.Collections.Generic.List<string> (); for (uint i = 0; i < changedKeys.Count; i++) { var key = new NSString (changedKeys.ValueAt(i)); Console.WriteLine("changedKey IntPtr: " + changedKeys.ValueAt(i)); Console.WriteLine("changedKey (value): " + key); changedKeysList.Add (key); } // now do something with the list... });

Hope this helps ~ uses the IntPtr returned from the NSArray.ValueAt() method to new up an NSString and access the values you're after.

NSNotificationCenter.DefaultCenter.AddObserver ( NSUbiquitousKeyValueStore.DidChangeExternallyNotification , delegate (NSNotification n) { Console.WriteLine("Cloud notification received"); NSDictionary userInfo = n.UserInfo; NSNumber reason = (NSNumber)userInfo.ObjectForKey(NSUbiquitousKeyValueStore.ChangeReasonKey); int ireason = reason.IntValue; Console.WriteLine("reason.IntValue: " + ireason); NSArray changedKeys = (NSArray)userInfo.ObjectForKey (NSUbiquitousKeyValueStore.ChangedKeysKey); var changedKeysList = new System.Collections.Generic.List<string> (); for (uint i = 0; i < changedKeys.Count; i++) { var key = new NSString (changedKeys.ValueAt(i)); Console.WriteLine("changedKey IntPtr: " + changedKeys.ValueAt(i)); Console.WriteLine("changedKey (value): " + key); changedKeysList.Add (key); } // now do something with the list... });