zerowords zerowords - 1 year ago 204
iOS Question

copy and paste text into ios simulator

This must be documented somewhere, but I can't find it.

In my app using the iPad simulator there is a textfield into which I want the user to paste text. In the real world the user will copy the text from Safari address into the textfield. But I am trying to do that in the ios ipad simulator, but with only partial results.

After I reRUN the app, I can immediately paste text into the textfield with the Mac's

Edit|Paste Text
menu or with Shift-Command-V, (but not with just
, but that's Ok). The need for the Shift is annoying but I can live with it.

But then if I try to copy another URL on the Mac and then again,
Edit|Paste Text
or even use the
bubble on the simulator, I don't get the new text, but the original text.

Is that common? Is that a feature of the simulator that it is not connected live to the clipboard on the host computer?

Answer Source

Be careful to avoid conflating the mac's clipboard with the simulator's clipboard. They are not the same.

The simulator is simulating an iOS device, with it's own iOS clipboard which apps running on that device (simulator) use via the iOS pup-up select-all/copy/paste UI items.

Completely separate from that: your mac has it's own clipboard and content. The Simulator program running on your mac provides the Edit > Paste Text menu item. The program implements that menu item by accessing your mac clipboard and types the text into the simulator as if the user used the keyboard. The iOS clipboard is neither accessed nor affected by the Simulator application's Edit menu functions.

Update: As of Xcode 6, you need to choose the Edit > Paste menu item in the iOS Simulator (this transfers the data between the Mac clipboard and the iOS Clipboard), then tap in the field in the simulator and tap the "Paste" bubble.

In your question you don't specify which "Safari" you're copying the URL from. It could be the mac safari application or the simulator's safari app. Doing a copy from the mac safari program goes to the mac clipboard, doing a copy from the safari app goes to the iOS clipboard inside the simulator.

I think your issues are coming from confusing the two, thinking there's one clipboard everything is sharing.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download