gpt4 book ai didi

iOS分享扩展-发送大视频

转载 作者:行者123 更新时间:2023-11-29 11:35:35 30 4
gpt4 key购买 nike

所以我正在尝试发送一个大视频文件(超过 100 mb),每当我使用 dataWithContentsOfURL 访问视频文件时,扩展都会终止。这适用于较小的文件。

我该如何解决?

if ([itemProvider hasItemConformingToTypeIdentifier:(NSString *)kUTTypeMovie]){
[itemProvider loadItemForTypeIdentifier:(NSString *)kUTTypeMovie options:nil completionHandler:urlHandler];
}




NSItemProviderCompletionHandler urlHandler = ^(NSURL *item, NSError *error) {

if ([itemProvider hasItemConformingToTypeIdentifier:(NSString *)kUTTypeVideo] | [itemProvider hasItemConformingToTypeIdentifier:(NSString *)kUTTypeMovie])
{
NSData *fileData = [NSData dataWithContentsOfURL:item]

// ----> fileData WORKS for small files.
// ----> for large files, extension QUITS - without any trace - and control does not proceed after this. This may be due to memory pressure?

[_shareExtensionActionsManager sendTextMessage:contentText attachmentData:fileData attachmentName:@"video-1" toChatEntity:_selectedItem completion:^(BOOL success)
{
[self.extensionContext completeRequestReturningItems:nil completionHandler:^(BOOL expired) {
exit(0);
}];
}];
}
};

最佳答案

来自app extension docs :

Users tend to return to the host app immediately after they finish their task in your app extension. If the task involves a potentially lengthy upload or download, you need to ensure that it can finish after your extension gets terminated.

After your app extension calls completeRequestReturningItems:completionHandler: to tell the host app that its request is complete, the system can terminate your extension at any time.

您将需要使用 NSURLSession 创建启动后台任务的 URL session 。

如果后台任务完成时您的扩展没有运行,系统将在后台启动包含您的应用程序并在您的 AppDelegate 中调用 application:handleEventsForBackgroundURLSession:completionHandler:

您还需要设置一个 shared container您的扩展程序和包含的应用程序都可以访问。为此,您需要使用 NSURLSessionConfiguration 的 sharedContainerIdentifier 属性来指定容器的标识符,以便稍后访问它。

这是文档中的示例,显示了如何实现此目的:

NSURLSession *mySession = [self configureMySession];
NSURL *url = [NSURL URLWithString:@"http://www.example.com/LargeFile.zip"];
NSURLSessionTask *myTask = [mySession downloadTaskWithURL:url];
[myTask resume];

- (NSURLSession *) configureMySession {
if (!mySession) {
NSURLSessionConfiguration* config = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:@“com.mycompany.myapp.backgroundsession”];
// To access the shared container you set up, use the sharedContainerIdentifier property on your configuration object.
config.sharedContainerIdentifier = @“com.mycompany.myappgroupidentifier”;
mySession = [NSURLSession sessionWithConfiguration:config delegate:self delegateQueue:nil];
}
return mySession;
}

这是一个 related resource这可能会有所帮助。

关于iOS分享扩展-发送大视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49564095/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com