java上传音频的方法_将音频文件从文档目录上传到 iCloud

我正在尝试使用以下代码将文档目录中的 session1.mp3 等音频文件上传到 iCloud

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

NSString *documentsDirectory = [paths objectAtIndex:0];

NSString *path = [documentsDirectory stringByAppendingPathComponent:@"session1.mp3"];

NSURL* sourceURL = [[NSURL alloc] initFileURLWithPath:path];

NSFileManager *fileManager = [NSFileManager defaultManager];

if ([fileManager fileExistsAtPath:path]) {

NSLog(@"File found!");

}

else

{

NSLog(@"File not found!");

}

NSURL *ubiq = [[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil];

if (ubiq)

{

NSLog(@"iCloud access at %@", ubiq);

NSError* error = nil;

NSURL *destinationURL = [[ubiq URLByAppendingPathComponent:@"Documents"] URLByAppendingPathComponent:@"session1.mp3"];

[[NSFileManager defaultManager] setUbiquitous:YES

itemAtURL:sourceURL

destinationURL:destinationURL

error:&error];

if(error != nil)

{

NSLog(@"Error while uploading the file: %@", error);

}

else

{

NSLog(@"File ulpoaded successfully");

}

}

else

{

NSLog(@"No iCloud access");

}

我尝试上传的文件存在(打印出“找到文件”),但将其上传到 iCloud 会产生以下错误

上传文件时出错:错误 Domain=NSCocoaErrorDomain Code=513“无法完成操作.(Cocoa error 513.)”UserInfo=0x1f03d9f0 {NSURL=file://localhost/var/mobile/Applications/20D82CDA-021E-4067-B9AB-C0197A6FA834/dox.app/session1.mp3,NSUnderlyingError=0x1f03d990“操作无法完成.操作不允许”}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值