Ios5 从MonoTouch访问iCloud NsubiquiousKeyValueStoreDidChangeExternallyNotification详细信息

Ios5 从MonoTouch访问iCloud NsubiquiousKeyValueStoreDidChangeExternallyNotification详细信息,ios5,xamarin.ios,icloud,Ios5,Xamarin.ios,Icloud,在MonoTouch下,我想访问NSUbiquitousKeyValueStoreDidChangeExternallyNotification(iOS5/iCloud key-value inbound update)通知数据: NSUbiquitousKeyValueStoreChangeReasonKey->NSNumber NSUbiquitousKeyValueStoreChangedKeysKey->NSString的NSArray 有一个示例@,但是上面访问的代码被注释掉了,并

在MonoTouch下,我想访问NSUbiquitousKeyValueStoreDidChangeExternallyNotification(iOS5/iCloud key-value inbound update)通知数据:

  • NSUbiquitousKeyValueStoreChangeReasonKey->NSNumber
  • NSUbiquitousKeyValueStoreChangedKeysKey->NSString的NSArray
有一个示例@,但是上面访问的代码被注释掉了,并且有缺陷(它如何尝试将reason转换为integer是错误的)。我离这里很近:

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"));
});
我想出了如何将原因作为整数。但是如何将nsstring的NSArray转换为
一个简单的字符串[]??对不起,我以前从未使用过核心Objective-C类型的包装器

Hope this help~使用从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...
});
NSNotificationCenter.DefaultCenter.AddObserver(
NSUbiquitousKeyValueStore.DidChangeExternallyNotification
,代表(NSN)
{
Console.WriteLine(“收到云通知”);
NSDictionary userInfo=n.userInfo;
NSNumber原因=(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();
对于(uint i=0;i
谢谢@CraigD。如果对其他人有帮助,以下是您发送的枚举值:public enum NSUbiquitousKeyValueStoreChangeReason{ServerChange=0,InitialSyncChange=1,QuotaViolationChange=2}