UIPasteboard's string value is nil when iphone recovered from sleep mode - ios

After recovering from sleep mode (tap sleep/wake button and then tap home button), I tried to get pasteboard string with the code blow and the result was nil.
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
self.beforeValue = pasteboard.string;
I can get it with iPhone 4S(iOS5.1.1), iPodtouch4G(iOS6.1.3), iPad(iOS6.1.3) but I cannot with 5(iOS6.1.3). Is it iPhone5 bug? Any hint is appreciated.

Related

XCTest. Detecting access gallery alert view

I have a problem with detecting UIAlertView which appear when I wont to get photo from photo gallery in UI XCTest. My code:
let app = XCUIApplication()
let alertView = app.alerts["\u{201c}MyAppName\u{201d} Would Like to Access Your Photos"]
Alert view is already on screen but in alertView I got nil. Anybody knows how to resolve this problem?
Maybe some charters in alertView Value is miss.
use index instead String Value.
let alertView = app.alerts.elementBoundByIndex(0)
and example for tap alertButton
app.alerts.elementBoundByIndex(0).buttons["OK"].tap()
it works for me

app-specific UIPasteboard

I'm trying to create app-specific UIPasteboard, but have some problems figuring out how to register it:
UIPasteboard *pasteboard = [UIPasteboard pasteboardWithName:#"myPasteboard" create:YES];
If I just create it, app continues to use generalPasteboard. I really hope that I don't have to catch cut/copy/paste operations and set items manually.
Please read this article
http://nshipster.com/uimenucontroller/ (It's about UILabel, not UITextField but is useful just for example and information about how copy/paste/edit actions work and how you can customize its' behavior)
I think you need to subclass UITextField to MyTextField for example, and override -(void)copy: and -(void)paste: methods from UIResponderStandardEditActions.
In your implementation of these methods you should use your custom UIPasteboard to copy text into and paste from it, like mentioned in this answer,
How to do copy/paste function programmatically in iphone?
but instead of using [UIPasteboard generalPasteboard] use [UIPasteboard pasteboardWithName:#"myPasteboard" create:YES]
//Copy your text field text and Just App in Pasteboard
NSString * text=textfield.text;
UIPasteboard * pasteboard=[UIPasteboard generalPasteboard];
[pasteboard setString:text];
Below is a Tutorial about Pasteboard.
http://hayageek.com/uipasteboard-example-read-write-share/
//pasteboard initialization
let pasteBoard = UIPasteboard.general
// copying the content of textview to pasteboard
if(pasteBoard.hasStrings){
pasteBoard.string = textViewPB.text
}
//pasting the content of pasteboard to textview
if(pasteBoard.hasStrings){
textViewPB.text = pasteBoard.string
}

Custom GIF Keyboard in iOS8

I am creating Custom GIF Keyboard in iOS8 using app extension. I was created layout of my custom keyboard. I was implement LongPress Gesture for selecting GIF Image but its not work. so what can i do for this or any suggestion regarding to this?
- (void)textWillChange:(id<UITextInput>)textInput {
[self.textDocumentProxy insertText:#"Hi"];
}
I also tried with UITextInputDelegate mentioned above.
This method is also deals with only text append. But My concern is to load gif or png image in input area.
I have done with long press gesture and make a method for touch handler.
-(void)tapped:(id)sender
{
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
UIImage *image = [UIImage imageNamed:#"img_temp.gif"];
NSData *imgData = UIImagePNGRepresentation(image);
[pasteboard setData:imgData forPasteboardType:[UIPasteboardTypeListImage objectAtIndex:0]];
}
I also given become first responder aswell.
-(BOOL)canBecomeFirstResponder
{
return YES;
}
I can copy text in pasteboard, but I can't copy .gif or .png image.
What Popkey, for example, are doing is copy the clicked GIF to the pasteboard.
The user then needs to long click their rich text field and paste the content into their iMessage for example.
You couldn't load a gif directly in the input area. To do that you have to copy the gif to the pasteboard and then paste the gif in the input area.
To copy the gif into the pasteboard you need to convert it into the NSData.
Here is the demo code in Swift 3.0.
let pb = UIPasteboard.general
let data = NSData(contentsOfURL: url)
if data != nil
{
self.pb.setData(data!, forPasteboardType: kUTTypeGIF as String)
}

Trouble Displaying Images On Device

I'm working on my first IOS app. The app downloads and displays data from a database via a PHP web page. That's all working fine. I also grab an image from the same web server to display in a UIImageView. This all works on fine on the Simulator.
On my test device (a 3GS), everything works except I cannot get the downloaded image to display in my UIImageView.
If there is no internet connection, I am able to display my alternate image that I've included in app's bundle on the simulator and on the device.
// Inside My data class Implementation
- (void)setUpTheData
{
--- other code ---
NSURL *myImageURL = [NSURL URLWithString:myImageURLString];
NSData *myImageRawData = [NSData dataWithContentsOfURL:myImageURL];
self.myImageData = myImageRawData;
}
- (NSData*)getTheImageData
{
return _myImageData;
}
// Inside my viewDidLoad
UIImage *theImage = [UIImage imageWithData:[theRemoteData getTheImageData]];
_testImage.image = theImage;
I've compared the image data from both the simulator and the device and they are the same.
Try viewDidAppear instead of viewDidLoad maybe?
I had set a weak pointer in my imageData property in my data class. Changing to strong fixed my problem.

How to paste text into UITextView in iOS?

I have a UITextView and i want to paste text into that UITextView with button's click event.
You know , when i click a button , the copied text from anywhere paste into that UITextView.
How can i do that?
Thanks in advance.
-(IBAction)buttonPressed:(id)sender
{
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
MsgtextView.text = [NSString stringWithFormat:#"%# %#",MsgtextView.text,pasteboard.string;
}
Check this
You can use the UIPasteboard class.
Try this code
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
textView.text = pasteboard.string;

Resources