Copying audio into general UIPasteboard

760 views Asked by At

I am implementing Audio Copy feature in my audio synthesis app using the general UIPasteboard so that the audio that was copied can be pasted in MAPI: AudioCopy/AudioPaste or Intua Audio Sharing enabled apps. There seems to be a problem in the process and the copied audio does not appear in a AudioPaste enabled app.

This is what I am doing to copy the audio into the general UIPasteboard.

NSData *newItemData = [NSData dataWithContentsOfFile:[dataPath stringByAppendingPathComponent:@"converted.wav"]];      


// This is the copy operation using the General Pasteboard otherwise known as the Intua Pasteboard
UIPasteboard *board = [UIPasteboard generalPasteboard];
[board setPersistent:TRUE];
NSData *dataFile = newItemData;

if (!dataFile) {
    NSLog(@"Can't open file");
}

// Create chunked data and append to clipboard
NSUInteger sz = [dataFile length];
NSUInteger chunkNumbers = (sz / GP_CLIPBOARD_CHUNK_SIZE) + 1;
NSMutableArray *items = [NSMutableArray arrayWithCapacity:chunkNumbers];
NSRange curRange;

for (NSUInteger i = 0; i < chunkNumbers; i++) {
    curRange.location = i * GP_CLIPBOARD_CHUNK_SIZE;
    curRange.length = MIN(GP_CLIPBOARD_CHUNK_SIZE, sz - curRange.location);
    NSData *subData = [dataFile subdataWithRange:curRange];
    NSDictionary *dict = [NSDictionary dictionaryWithObject:subData forKey:(NSString *)kUTTypeAudio];
    [items addObject:dict];
}

board.items = items;

After doing this step, when I launch an AudioPaste compatible app, I do not see the audio I just copied. Could you spot any fault in my Audio Copy code?

1

There are 1 answers

1
Hayden On

I'm not convinced that your path you're creating by adding "converted.wav" exists. I would check that the file path exists before continuing through with the copy. You may find that path looks something like "myAudioFile.wavconverted.wav".

As a minor note, the General Pasteboard that's returned by [UIPasteboard generalPasteboard] is always persistent, so you don't need to set it to persistent.