English 中文(简体)
在多个设备上使用 iCloud 的 ExC_BAD_ACACES
原标题:EXC_BAD_ACCESS using iCloud on multiple devices

我用 iCloud 创建一个应用程序。 但我有些问题。 它使用 NSFileWrapper 在 iClod 上创建目录, 然后在 NSFileWrapper 目录中创建 NSData( 容器) 文件。 I m 使用此代码将 NSFileWrapper 转换为 NSMubableArray :

NSFileWrapper *MyWrapper=[[[MyDocument data] fileWrappers] objectForKey:@"myFile.doh"];
    NSData *MyData=[NSData dataWithData:[MyWrapper regularFileContents]];
    NSMutableArray *MyList=[NSPropertyListSerialization propertyListFromData:MyData mutabilityOption:NSPropertyListMutableContainers format:nil errorDescription:nil];

它只对创建了这个容器的设备正确工作。 在其它设备上, 这个代码的结果是 BAD_ACCESS( 在代码的第二行, 我开始用数据做一些事情 ) 。 在调试时, 函数“ 常规功能” 返回正确的对象, 并使用正确的数据大小, 但是当我试图读取这个数据时, 会发生 BAD_ ACESS( 代码= 10) 。

我使用ARC,所以它不是一个内存管理错误。

问题可能在于某些项目/代码符号设置?有什么想法吗?

谢谢!

问题回答

我同样也遇到了这个问题,经过许多实验后,我发现,尽管外包装已经下载了内装物,但内部内容实际上还没有下载,这导致对常规文件内容的号召失败。

我一直在 MyWrapper 上拨打 开始下载UbiotousTroupAturL , 一旦完成错误完成, 错误就会消失。 这里使用的方法可以检查文件的下载状态( 假设您知道 MyWrapper 的 URL), 如果还没有下载, 并开始下载 。

-(BOOL)downloadFileIfNotAvailable:(NSURL*)fileURL
{
    NSNumber *isInCloud = nil;

    if ([fileURL getResourceValue:&isInCloud forKey:NSURLIsUbiquitousItemKey error:nil])
    {
        if ([isInCloud boolValue]) {
            NSNumber *isDownloaded = nil;
            if ([fileURL getResourceValue:&isDownloaded forKey:NSURLUbiquitousItemIsDownloadedKey error:nil])
            {
                if ([isDownloaded boolValue])
                {
                    return YES;
                }

                NSError *error = nil;
                [[NSFileManager defaultManager] startDownloadingUbiquitousItemAtURL:fileURL error:&error];

                if (error)
                {
                    NSLog(@"Download Failed :: %@", error);
                }

                return NO;
            }
        }
    }

    return YES;
}




相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签