iOS copy/paste routines

Some basic iOS copy/paste sample code:

#import "UIPasteboard.h"

void iphone_copy(char *text) {
  UIPasteboard *pb = [UIPasteboard generalPasteboard];
  NSString *nstext = [NSString stringWithCString:text encoding:NSUTF8StringEncoding];
  [pb setValue:nstext forPasteboardType:@"public.plain-text"];
}

const char *iphone_paste() {
  UIPasteboard *pb = [UIPasteboard generalPasteboard];
  NSString *nstext = [pb valueForPasteboardType:@"public.utf8-plain-text"];
  return [nstext cStringUsingEncoding:NSUTF8StringEncoding];
}

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>