Wednesday 7 May 2014

Sharing Data using UIPasteboard in iOS app

Sharing using General pasteboard

UIPasteboard *appPasteBoard = [UIPasteboard generalPasteboard];
appPasteBoard.persistent = YES;
[appPasteBoard setString: @"String To Copy"];

UIPasteboard *appPasteBoard = [UIPasteboard generalPasteboard];
NSString *textCopied = [appPasteBoard string];


Sharing using User pasteboard

UIPasteboard *userPasteBoard =[UIPasteboard pasteboardWithName:@"UserDefined" create:YES];
userPasteBoard.persistent=YES;
[userPasteBoard setString:@"String To Copy"];

UIPasteboard *userPasteBoard =[UIPasteboard pasteboardWithName:@"UserDefined" create:YES];
userPasteBoard.persistent=YES;
NSString *textCopied=[userPasteBoard string];

Copy Image to General Pasteboard

UIImage * image=[UIImage imageWithContentsOfFile:@"FILE_PATH"];
UIPasteboard * pasteboard=[UIPasteboard generalPasteboard];
[pasteboard setImage:image];

No comments:

Post a Comment