ChatGPT解决这个技术问题 Extra ChatGPT

Copy 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 Edit|Paste, 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 Paste 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?

Do it on a device. Don't trust the way the simulator operates for how it will work.

h
hardanger

I found that even with Edit > Automatically sync pasteboard ticked, the feature didn't work.

However, simply unticking and then reticking this option fixed the feature!

Hope it works for someone.


This worked for me to re-enable clipboard sharing after upgrading to Xcode 10.1.
Yes, this is working. However, for one time only. Had to repeat the same steps again next time, to get it working. Anyway, happy that some option is there :)
Worked for me! Thank you taking the time to post.
It's not working for me I use M1
K
Kevin

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.


In Xcode 9 (maybe before) there is a menu item under edit "Automatically sync pasteboard" I think that will keep your mac's clipboard and the simulator's clipboard synced, so they are always the same.
S
Shane

Copy text on the mac, then click the text field in the simulator and press

Shift Command V


Ended up being a combination for me? Super weird. I had to Paste in the menu bar, and then do this to get the paste.
Looks like this approach works often but not all the time. In my case 100% working method is to Cmd+C some text, then copy it by mouse context menu, then in Simulator Cmd+V, Cmd+Shift+V, paste via menu. Strange but works...
C
Chathurka

Please click "Automatically sync pasteboard" option in Simulator edit option.

https://i.stack.imgur.com/aG8XB.png


I've had to uncheck that to get my pasteboard to work but I'm happy I can copy/paste again!
hmmm doesn't seem to work as of os x 10.13.6 and xcode 10.1, unless i am doing something else wrong with my settings
Cap without Hero!
All others answers about just cmd+c - cmd+v should be removed. thx
K
Kirill Kudaev

Xcode 10.0+:

Turning the Automatic Pasteboard Sync off and then back on again solved the issue.

You might have to do that multiple times. Sometimes it takes a while to trigger it for some reason.

(Edit -> Automatic Pasteboard Sync)


R
Rajashekar

What worked for me is this.

1) copy text from Mac

2) In simulator do edit->paste or Command V (I think this copies the text from mac clipboard to iOS Simulator clipboard).

3) Highlight the textfield in simulator and then do command + Shift + V.


M
Mansur76

Similar thing happened to me and I found a strange workaround, it may help anyone else that may come across the same issue. Try the following steps:

Disable and then re-enable the Automatically Sync Pasteboard option, it's found under the Edit menu on the Simulator Copy the text you want from your Mac Paste the text again on your Mac on a text editor like Atom or even your browsers Address Bar Select all the text Cmd+A and then cut/copy Cmd+X/Cmd+C You should now be able to paste the text on the simulator


D
Daniel Lizik

I updated to os x 10.13.6 and xcode 10.1 and there is an added menu in edit

https://i.imgur.com/sVBSWdt.png

click get pasteboard then you will be able to paste via the paste tooltip in simulator


I had to click Send Pasteboard in order to paste in the simulator. Get Pasteboard did the reverse action, it took the iOS clipboard into the Mac clipboard.
this is now the correct answer except as qwertzguy points out, you've got it backwards
D
Digital Dom

Nothing from the above solutions worked for me. I am using M1 Apple. The thing that worked was this thread https://github.com/flutter/flutter/issues/74970

In short, if you are using iOS 14.0 to build the app, you will have the above issues.

In order to solve it, what I did was installing iOS 13.7 in xCode by going to Preferences -> Components -> iOS 13.7 -> then rebuild the app in the xCode.


What are you doing? You already have posted the same answer on this page. I've even edited it to fix the typos and mistakes...
I am using M1 and this problem happens when the Xcode update. I have to install ios 13.7 and it works fine again.
M
Mor4eza

Just Disable and then re-enable the Automatically Sync Pasteboard option from Edit menu, fixed my problem.

https://i.stack.imgur.com/6zJCF.png


A
Aashutosh Prakash

After trying a lot and nothing work on M1 Macs and simulator above 14 I have taken the different route to solve problem.

Apple script to type the text in simulator.

tell application "System Events"
set texttosay to "Sample Text"
display dialog "Text to type:" default answer "white: "
set texttosay to the text returned of the result
repeat
    delay 2
    repeat 1 times
        keystroke texttosay
        delay 1
        keystroke return
    end repeat
    exit repeat
end repeat
end tell

Steps:

Run above script in apple scripts and paste the text in dialogue box you want to type in simulator. click the input-box to populate the value.

Hope that helps in your problem.

Thanks


E
Eliram

In a new emulator, I got no "paste" option and sync did not work for the simulator. It appears that in the simulator you MUST copy something to the internal clipboard before the sync actually works.


This saved my butt! Xcode 10.2 newly installed, new Simulator, nothing worked. Then copied a tiny bit of code and voíla - I got the paste menu! Thanks!!!
A
Adil Malik

Sometimes it's very difficult to type long URLs in iOS simulator. There should be some way to copy URL from Max OS to iOS text field. Here's how you can do it:

Copy some text from Mac

Open the simulator and click on a text field where you want to paste the text

Now in Simulator menu click on Edit -> Paste Text

and that's it. Your text from the Mac OS copy buffer should now be there in iOS simulator's text field.


J
JerryZhou

Three steps:(The key point is make sure that the "Paste" help menu is keeping visible when you use " ⌘ + V".)

make sure you select the point you want to past in the simulator, and the editMenu with "Paste" is show. use keyboard on mac," ⌘ + V", to paste the text into simulator clipboard. click the "Paste" on editMenu that show above, to paste the text into simulator textField.

https://i.stack.imgur.com/DMuxp.png


b
bgarr

None of these solutions worked for me. I'm using Simulator 11.4. And after trying each of these, I realized all I needed to do was copy something on my Mac using Command + C, and then in the simulator text field, simply hold down the mouse click for an extra second or two, and the paste menu popped up automatically, and worked great.

https://i.stack.imgur.com/SmQJp.png


N
Nikolay Shubenkov

sometimes you just need to select Hardware -> reset content and settings in simulator menu. then all works automatically as easy and transparent as working in MacOS with other applications


O
Ohmy

This works for me. On Safari version 8.0.3 and IOs simulator version 8.1

Copy text from Safari - highlight text then cmd-v or Edit>Copy. In Ios Simulator click Edit>Paste. On TextField or TextView right click then select Paste.


R
Rishab

This is what I found.

Copy text from mac. In simulator open safari and highlight the address bar by clicking it. Press Cmd + V Click once on address bar. Paste drop down shall appear. Tap on paste.

Shift + Cmd + V works great too.


w
wj2061

⌘ + V : When iOS simulator is in front,copy the contents of the OS X clipboard over to iOS, but doesn't paste it. Again, this works for both text and images. So you need to do as follows: 1.copy text anywhere in your macOS except iOS simulator. 2.in iOS simulator, click ⌘ + V, copy text from macOS clipboard to iOS simulator's clipborad. 3.in iOS simulator, TextField or TextView click -> Edit ->Paste.