Reputation: 658
1) I copy image from UIPasteboard
using this method [UIPasteboard generalPasteboard].image;
2) After creating an image i want to clean the UIPasteboard
. so i write this method [UIPasteboard generalPasteboard].image = nil;
But this working fine on ios 4 and ios 5 But it gives problem on ios 6.
3) In my app i want to clean UIPasteboard
or nil the UIPasteboard
value. How can i do this on ios 6?
Upvotes: 0
Views: 1781
Reputation: 3677
I am sorry but the accepted answer is just misleading/incorrect. This will not clear the existing value from the pasteboard.
The second argument to setValue:forPasteboardType:
is a string identifier for the item. As the documentation suggests, it may be a UTI (look in MobileCoreServices) or a user defined string.
The method call in the accepted answer uses UIPasteboardNameGeneral
which is an identifier for the entire pasteboard itself (and not a key in one if the items in the array of dictionaries in [UIPasteboard items]
). Since the pasteboard does not contain an item for that key, that call will be a no-op. It is easy to verify this yourself. [[UIPasteboard generalPasteboard] name]
is equal to UIPasteboardNameGeneral
. Also, containsPasteboardTypes:
using that key will return NO
.
Now to address what might be happening in iOS 6. Apple is likely using a UTI (say kUTTypePNG
) as the key for the image data being stored in the pasteboard. They are likely ensuring that the value being set for that key is indeed an NSData (which nil
is not).
To address your conundrum, may I suggest one of the following:
+ (UIPasteboard *)pasteboardWithName:(NSString *)pasteboardName create:(BOOL)create
persistent
property to YES on the same.Hope this helps.
Upvotes: 1
Reputation: 690
This is what I currently use
UIPasteboard *pb = [UIPasteboard generalPasteboard];
[pb setValue:@"" forPasteboardType:UIPasteboardNameGeneral];
Upvotes: 0