0

我正在使用 Swift 4 和 Objective-C 开发一个应用程序,它将一组 m4a 音频文件(在本地和通过 http 尝试)加载到粘贴板。

基本上,这在将文本加载到粘贴板时有效 let pasteBoard = UIPasteboard.general pasteBoard.string = "Paste me!"

此外,这在将图像加载到粘贴板时有效

let image = UIImage(named: "person.png")
UIPasteboard.general.image = image;

但是在处理 mp4 文件时,我尝试了不同的方法选项 1. 从 url 加载数据(objective-c)

NSData *data = [NSData dataWithContentsOfURL:[NSURL 
URLWithString:@"http://www.example.com/assets/vasir.m4a"]];
UIPasteboard *pasteBoard = [UIPasteboard generalPasteboard];
[pasteBoard setData:data forPasteboardType:@"public.mpeg4"];

最后一行我在 https://developer.apple.com/library/content/documentation/Miscellaneous/Reference/UTIRef/Articles/System-DeclaredUniformTypeIdentifiers.html中尝试了 public.mpeg4-audio public.audio

在这种情况下,我收到一个错误:

Audiokeyboard[2475:996008] NSURLConnection finished with error - code -1022
Audiokeyboard[2475:995924] Could not save pasteboard named com.apple.UIKit.pboard.general. Error: Error Domain=PBErrorDomain Code=0 "Cannot load representation of type public.mpeg4" UserInfo={NSLocalizedDescription=Cannot load representation of type public.mpeg4, NSUnderlyingError=0x1d0640ff0 {Error Domain=PBErrorDomain Code=15 "No loader block available for type public.mpeg4." UserInfo={NSLocalizedDescription=No loader block available for type public.mpeg4.}}}

我搜索了很多关于“没有可用于类型 public.mpeg4 的加载程序块”。并没有找到任何结果。

选项 2. 斯威夫特

do {
  let url = URL(string : "https://www.example.com/home/vasir.m4a")
  let data1 = try Data(contentsOf: url!)
  let pb = UIPasteboard.general
  pb.setData(data1, forPasteboardType: "public.mpeg-4")
} catch {
  print(error.localizedDescription)
}

在这种情况下,没有收到错误(甚至在 catch 中也没有),当我调试代码时,我看到 data1 var 正在从文件中获取信息。setData 语句做了一些事情,这出现在控制台中

swiftCustomKeyboard[2515:1011974] [BoringSSL] Function boringssl_session_errorlog: line 2881 [boringssl_session_read] SSL_ERROR_ZERO_RETURN(6): operation failed because the connection was cleanly shut down with a close_notify alert
swiftCustomKeyboard[2515:1011974] [BoringSSL] Function boringssl_session_errorlog: line 2881 [boringssl_session_read] SSL_ERROR_ZERO_RETURN(6): operation failed because the connection was cleanly shut down with a close_notify alert
(lldb) 

所以,是的,我被困在这里。我通常不使用swift或objective-c,所以也许只是我缺乏练习。

知道该怎么做吗?

谢谢!

4

0 回答 0