2

我现在有3天的大问题。我正在尝试在 iOS 上使用 iCloud 键值存储,但值永远不会与 iCloud 同步而不会出现明显错误。当我说它不同步时,它真的从不同步。我可以让应用程序运行 15 分钟,关闭它并再次启动它,值仍然不存在。

我在 Apple 会员中心的 App-ID 上启用了 iCloud。我在我的项目的 xCode 功能中启用了 iCloud。一切运行良好,没有错误,但是当我试图获得我的价值时,它根本不存在。

这是我用来与 iCloud 通信的代码(请记住,我需要将它与 Unity3D 一起使用):

extern "C" void UnitySendMessage(const char *, const char *, const char *);

@interface iCloudPlugin : NSObject
{
    NSUbiquitousKeyValueStore *keyStore;
}
@end

@implementation iCloudPlugin

- (id) initClass
{

    if([NSUbiquitousKeyValueStore defaultStore] == nil){
        NSLog(@"iCloud not enabled");
    }else{
        keyStore = [NSUbiquitousKeyValueStore defaultStore];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyValueStoreDidChange:) name:NSUbiquitousKeyValueStoreDidChangeExternallyNotification object:keyStore];
    }
    return self;
}

- (void) synchronize
{
    NSLog(@"Syncing iCloud");
    if([keyStore synchronize])
    {
        NSLog(@"Successfully synced");
    }
}

- (void) addValue:(const char*)key value:(const char*)value
{
    NSLog([NSString stringWithFormat:@"%s",key]);
    NSLog([NSString stringWithFormat:@"%s",value]);
    [keyStore setString:[NSString stringWithFormat:@"%s",key] forKey:[NSString stringWithFormat:@"%s",value ]];
    [self synchronize];
}

-(void) keyValueStoreDidChange: (NSNotification *) notification
{
    NSLog([NSString stringWithFormat:@"Key/Value Changed"]);
}

- (const char*) getValue:(const char*)key
{
    NSString *storedString = [keyStore stringForKey:[NSString stringWithFormat:@"%s",key]];
    return [storedString UTF8String];
}

- (BOOL) hasKey:(const char*)key
{

    NSString *storedString = [keyStore stringForKey:[NSString stringWithFormat:@"%s",key]];
    if(storedString == nil){
        return NO;
    }else{
        return YES;
    }
}

- (void) removeKey:(const char*)key
{
    [keyStore removeObjectForKey:[NSString stringWithFormat:@"%s",key]];
    [self synchronize];
}




@end

extern "C" {
    void *_InitICloud();
    void _Synchronize(void *instance);
    void _AddValue(void *instance, const char *key, const char *value);
    const char *_GetValue(void *instance, const char *key);
    BOOL _HasKey(void *instance, const char *key);
    void _RemoveKey(void *instance, const char *key);
}

void *_InitICloud()
{
    id instance = [[iCloudPlugin alloc] initClass];
    return (void *)instance;
}

void _Synchronize(void *instance)
{
    iCloudPlugin *iCloudInstance = (iCloudPlugin *) instance;
    [iCloudInstance synchronize];
}

void _AddValue(void *instance, const char *key, const char *value){
    iCloudPlugin *iCloudInstance = (iCloudPlugin *) instance;
    [iCloudInstance addValue:key value:value];
}

const char *_GetValue(void *instance, const char *key)
{
    iCloudPlugin *iCloudInstance = (iCloudPlugin *) instance;
    return [iCloudInstance getValue:key];
}

BOOL _HasKey(void *instance, const char *key)
{
    iCloudPlugin *iCloudInstance = (iCloudPlugin *) instance;
    return [iCloudInstance hasKey:key];
}

void _RemoveKey(void *instance, const char *key)
{
    iCloudPlugin *iCloudInstance = (iCloudPlugin *) instance;
    [iCloudInstance removeKey:key];
}

所以每次我启动我的应用程序时,我都会检查一个名为“myKey”的具有“test”值的键。

如果它不存在我创建它,如果它存在我显示它。

如果没有挂起,hasKey 函数总是返回 NO。

我试图在我的应用程序的不同位置调用它或通过多次同步它,但当我重新启动应用程序时我从来没有我的价值。

我查看了 iPhone 5(运行 iOS 8.1)日志,没有关于 iCloud 的日志。我已经阅读了另一个主题,您可以通过与 iCloud 同步来访问隐藏的 iCloud 日志,然后导航到 ~/Library/Logs/CrashReporter/MobileDevice/iPhone de *******/DiagnosticLogs。

在这些日志中,我有时会发现:

Nov  4 16:57:29 iPhone-de-******* librariand[139] <Debug>: cancelled, closing fd 4
Nov  4 16:57:29 iPhone-de-******* librariand[139] <Debug>: client process 140 does not have a valid com.apple.developer.ubiquity-container-identifiers entitlement
Nov  4 16:57:29 iPhone-de-******* librariand[139] <Debug>: not tracking pid 140 since it does not require us to enable push
Nov  4 16:57:29 iPhone-de-******* librariand[139] <Debug>: application identifier for process 140 = bird
Nov  4 16:57:29 iPhone-de-******* librariand[139] <Debug>: received request 12 from client 140 (bird): <dictionary: 0x175749a0> { count = 1, contents =
                "Request Type" => <uint64: 0x17683ed0>: 12
        }
Nov  4 16:57:29 iPhone-de-******* librariand[139] <Debug>: container com.apple.shoebox has 0 bytes evictable
Nov  4 16:57:29 iPhone-de-******* librariand[139] <Debug>: client connection error: Connection invalid

问题是我在 iCloud 权利中找不到任何 com.apple.developer.ubiquity-container-identifiers。所以我创建了它并给它我们的 AppID 值,但它也不起作用(+ 它在 xCode 中显示一个错误,因为它无法识别它)。

我试图从手机中删除所有配置文件,它不会改变任何东西。我试图在 iCloud 中禁用蜂窝数据,它没有改变任何东西(我也尝试再次启用它,猜猜看,没有改变任何东西)。

我现在真的被困住了,几乎所有我能找到的与这个错误相关的东西都用谷歌搜索了。

谢谢您的帮助。

4

0 回答 0