0

I'm developing an app in both Swift 4 and Objective-C that loads a set of m4a audio files (tried local and via http) to pasteboard.

Basically, this works when loading text to pasteboard let pasteBoard = UIPasteboard.general pasteBoard.string = "Paste me!"

Also, this works when loading an image to pasteboard

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

But when working with mp4 files, i tried different approaches Option 1. Loading from data from 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"];

Last line i tried public.mpeg4-audio public.audio like in https://developer.apple.com/library/content/documentation/Miscellaneous/Reference/UTIRef/Articles/System-DeclaredUniformTypeIdentifiers.html

In this case, i receive an error :

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.}}}

I search a lot about the "No loader block available for type public.mpeg4." and no results were found.

Option 2. Swift

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)
}

In this case, no error in received (not even in catch), when i debug the code i see that data1 var is getting the info from file. setData statement does something and this appears in console

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) 

So yeah, i'm stuck here. I'm usually not using swift or objective-c so maybe is just my lack of practice.

Any idea what to do?

Thanks!

  • Did you check the `data1` is correct? Try using `NSURLSessionTask` to download data and see what the problem is. – Ryan Apr 20 '18 at 17:18
  • Tried already. data1 is exactly what expected, same size, did a breakpoint and tested in hex format. Error happens when setData. Somebody said that setData takes more time than expected, so I also waited for sometime. – Xavier Alfeiran Sainz Apr 21 '18 at 03:53

0 Answers0