ondrive api for ios:无法保存下载的文件(应用程序崩溃)
我需要一点帮助来理解我做错了什么 我正在尝试在iphone(或模拟器)中下载一个最初在MS oneDrive中使用oneDrive API for IOS的文件。我已正确验证,因为我能够列出文件和目录 下载具有给定文件ID的文件的代码如下:ondrive api for ios:无法保存下载的文件(应用程序崩溃),ios,objective-c,nsdata,onedrive,Ios,Objective C,Nsdata,Onedrive,我需要一点帮助来理解我做错了什么 我正在尝试在iphone(或模拟器)中下载一个最初在MS oneDrive中使用oneDrive API for IOS的文件。我已正确验证,因为我能够列出文件和目录 下载具有给定文件ID的文件的代码如下: - (void) loadFolderContent { [self.liveClient getWithPath:@"file.3f40e27093d2e59e.3F40E27093D2E59E!306"
- (void) loadFolderContent
{
[self.liveClient getWithPath:@"file.3f40e27093d2e59e.3F40E27093D2E59E!306"
delegate:self
userState:@"load-file-content"];
}
- (void) liveOperationSucceeded:(LiveOperation *)operation
{
if ([operation.userState isEqual:@"load-file-content"])
{
LiveDownloadOperation *downloadOp = (LiveDownloadOperation *)operation;
[downloadOp.data writeToFile:@"example.pdf" atomically:YES];
}
}
文件路径file.3f40e27093d2e59e.3f40e27093d2e59e!306是文件的fileID,所以应该是ok
它在这条线上崩溃:
[downloadOp.data writeToFile:@"example.pdf" atomically:YES]
downloadOp.data存在并且不是零,但我仍然得到错误:
-[LiveOperation data]: unrecognized selector sent to instance 0xacde910
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[LiveOperation data]: unrecognized selector sent to instance 0xacde910'
*** First throw call stack:
(
0 CoreFoundation 0x028881e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x026078e5 objc_exception_throw + 44
2 CoreFoundation 0x02925243 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x0287850b ___forwarding___ + 1019
4 CoreFoundation 0x028780ee _CF_forwarding_prep_0 + 14
5 DemoApp 0x000410f3 -[CFFlipsideViewController liveOperationSucceeded:] + 515
6 DemoApp 0x00050ed7 -[LiveOperationCore operationCompleted] + 335
7 DemoApp 0x00051060 -[LiveOperationCore connectionDidFinishLoading:] + 35
8 Foundation 0x023d0e49 ___NSURLConnectionDidFinishLoading_block_invoke + 40
9 Foundation 0x023677e1 __65-[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:]_block_invoke + 62
10 Foundation 0x021eff5e -[NSURLConnectionInternalConnection invokeForDelegate:] + 119
11 Foundation 0x021efec6 -[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:] + 208
12 Foundation 0x021efdd8 -[NSURLConnectionInternal _withActiveConnectionAndDelegate:] + 76
13 Foundation 0x021f0188 _NSURLConnectionDidFinishLoading + 43
14 CFNetwork 0x02d1869f ___ZN27URLConnectionClient_Classic26_delegate_didFinishLoadingEU13block_pointerFvvE_block_invoke + 111
15 CFNetwork 0x02d163de ___ZN27URLConnectionClient_Classic18_withDelegateAsyncEPKcU13block_pointerFvP16_CFURLConnectionPK33CFURLConnectionClientCurrent_VMaxE_block_invoke_2 + 104
16 CoreFoundation 0x02829c69 CFArrayApplyFunction + 57
17 CFNetwork 0x02c7f441 _ZN19RunloopBlockContext7performEv + 155
18 CFNetwork 0x02d613f4 _ZThn16_N19RunloopBlockContext24multiplexerClientPerformEv + 20
19 CFNetwork 0x02c7f257 _ZN17MultiplexerSource7performEv + 299
20 CFNetwork 0x02c7f06c _ZN17MultiplexerSource8_performEPv + 76
21 CoreFoundation 0x0281177f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
22 CoreFoundation 0x0281110b __CFRunLoopDoSources0 + 235
23 CoreFoundation 0x0282e1ae __CFRunLoopRun + 910
24 CoreFoundation 0x0282d9d3 CFRunLoopRunSpecific + 467
25 CoreFoundation 0x0282d7eb CFRunLoopRunInMode + 123
26 GraphicsServices 0x039785ee GSEventRunModal + 192
27 GraphicsServices 0x0397842b GSEventRun + 104
28 UIKit 0x012c7f9b UIApplicationMain + 1225
)
我非常感谢您为解决此问题提供的帮助
谢谢,
dom我不知道这个API,所以我只能做一些一般性的观察。它抱怨
downloadOp.data
,说LiveOperation
类没有data
方法。我看到您将其转换为livedownloadmoperation
,但运行时并不认为该对象是这样的。因此,假设data
属于子类,这就是报告的错误。n记录操作的值
并查看结果。谢谢,这有助于确定问题所在。第三行:[self.liveClient downloadFromPath:@“file.3f40e27093d2e59e.3f40e27093d2e59e!306/content”是正确的,而不是[self.liveClient getWithPath:@“file.3f40e27093d2e59e.3f40e27093d2e59e!306”。将在解决方案说明中详细说明,但感谢您帮助我更仔细地思考(并查看文档…)