Simulate force touch / 3D touch on iPhone 6S or iPhone 6S Plus simulators
Asked Answered
T

10

100

I am trying to simulate a force touch using Xcode 7 GM on the iPhone 6S or iPhone 6S Plus simulator. In particular, I am trying to simulate the force touch on the icon of the test app which is implementing Application Shortcuts.

Let me know if there is a solution to simulate this, I tried the long press which the Watch simulator uses to simulate force touch, didn't work since the iPhone captures it as a long press gesture.

Update: I downloaded the ViewControllerPreview Sample code from Apple. Running their sample application I see that the simulator, although an iPhone 6s, does not support for 3D / force touch feature. I am still unsure if it would support the feature if I were to be using a macbook with a force touch enabled trackpad.

enter image description here

EDIT: Can someone with a macbook that has a force touch trackpad attempt to use the force touch on the trackpad to simulate 3D touch on the iPhone 6s or 6s Plus simulator? My theory is that you can maybe use the force touch trackpad on the new MacBooks to simulate the 3D touch on new iPhone simulators. Add a comment noting the results if you try it and I can update the post.

EDIT2: It seems that Force Touch trackpads on the newer model macbook pros do not help.

Thitherto answered 10/9, 2015 at 0:31 Comment(5)
Don't you have to use Xcode 7.1 beta?Langland
Option is disabled when run using 7.1BUlrick
Looks like there is a radar out on this. openradar.appspot.com/22635686Concurrence
Force Touch on the 2015 Macbook Pro doesn't help..Airborne
You can consider to use this too.Edwyna
L
74

It says here! at the bottom of the page....

Development Environment

Xcode 7 supports 3D Touch development. All the debugging features of Xcode are available for implementing the new features.

Keep the following in mind:

With Xcode 7.0 you must develop on a device that supports 3D Touch. Simulator in Xcode 7.0 does not support 3D Touch.

With Xcode 7.0 you must implement your peek and pop view controllers in code. Interface Builder in Xcode 7.0 does not provide graphical support for configuring view controllers or transitions for 3D Touch.

Be sure to test your app with 3D Touch both enabled and disabled, ensuring that all features are available to all users. On a 3D Touch device, you can disable 3D Touch in Settings > General > Accessibility > 3D Touch

So unfortunately it looks like we need to get our hands on the actual devices to do it. :-(

EDIT.....

As of Xcode 7.3 there is a way to do this if your MacBook's trackpad supports force touch. See answer by @iPrabu.

Lecturer answered 11/9, 2015 at 22:45 Comment(9)
Well,it seems that we have to wait 2-3 weeks before we can test the 3D touch stuff.Cackle
Just FYI, there's a tool that i linked on my answer, that lets you emulate the force touch to show the Quick Actions menu.Bankable
One oddity is that if you run the 6S or 6S Plus simulators the Hardware option "Force Touch Pressure" is enabled. On all other simulators it is not. So it looks like they got part of the way through implementing 3D touch in the simulator, but then gave up. Time to buy a new phone...Proportional
The linked page now says Xcode 7.1 does not support 3D Touch.Banka
Speaking as a QA dev... this sucks.Ferric
Anyone know if this is still the case for Xcode 7.3?Virtuosity
@LucasAzzopardi 3D touch is supported in Xcode 7.3 only if you have a trackpad with force touchHeterotypic
@kris-gellci You should accept iPrabu's more up-to-date answerPhlogopite
One thing that's important to note for future readers is that iPhone XR is one phone that does not support 3D touch while the X, XS and XS Max do.Byars
B
64

For those that are developing Quick Actions (App Shortcuts) you can use this script that enables you to simulate a deep press on an app on the simulator.

https://github.com/DeskConnect/SBShortcutMenuSimulator

Here's a screenshot: enter image description here

For those that are looking at how to add the actions on the first place, there are two options, Static and Dynamic. You can set only 4 options, it will first show all Static ones, and if there's space, show Dynamic ones.

Here's how to add Static shortcuts. It's pretty easy, just add some keys on the main Info.plist

In this example i will be adding two static options one with Default Search icon, and the other with custom icon from asset catalog.

<key>UIApplicationShortcutItems</key>
<array>
    <dict>
        <key>UIApplicationShortcutItemTitle</key>
        <string>Add Event (with custom icon)</string>
        <key>UIApplicationShortcutItemType</key>
        <string>com.reverse.appname.addevent</string>
        <key>UIApplicationShortcutItemIconFile</key>
        <string>custom-icon-from-asset-catalog</string>
        <key>UIApplicationShortcutItemSubtitle</key>
        <string>Here you can add some text below the option</string>
    </dict>
    <dict>
        <key>UIApplicationShortcutItemTitle</key>
        <string>Search Event (with default icon)</string>
        <key>UIApplicationShortcutItemType</key>
        <string>com.reverse.appname.searchevents</string>
        <key>UIApplicationShortcutItemIconType</key>
        <string>UIApplicationShortcutIconTypeSearch</string>
        <key>UIApplicationShortcutItemSubtitle</key>
        <string>Here you can add some text below the option</string>
    </dict>
</array>
Bankable answered 22/9, 2015 at 19:5 Comment(8)
Great, thanks a lot! Have you managed to simulate Peek and Pop functionality?Going
@Going not yet no, but at least you can now test on the real device. And most likely the simulator will get that working in the following update, the menu option is already there.Bankable
I can't show shortcut Item can you please help me..?Chladek
@DipenChudasama sure, i've updated my answer to show you how to add the shortcuts.Bankable
Fantastic answer! Thanks a lot.Salver
It not working for me. Terminal display given logs : No devices are booted.Ollieollis
It works Xcode (7.3.1) just install the old 9.1 simulator from preferencesMauricemauricio
For iOS versions above 9.1, use the fork from PoomSmart: github.com/PoomSmart/SBShortcutMenuSimulatorCardialgia
A
43

With Xcode 7.3 you can test the 3D touch feature in simulator but with only one constraint. (Xcode7.3 release notes reference)

The machine(macbook/mac with trackpad) your are developing should have 3D touch capability.

You can find it under iOS simulator Hardware menu.

Comments from Pavel Alexeev: Be sure to enable “Force Click and haptic feedback” in System Preferences → Trackpad

enter image description here

Askew answered 4/4, 2016 at 5:6 Comment(4)
Be sure to enable “Force Click and haptic feedback” in System Preferences → TrackpadSekofski
As an additional requirement you must use the latest Simulator, I tried iOS 9.2 for a couple of minutes without success - with 9.3 it works ;)Seabury
Searched for a few minutes and ended up realizing that I was simulating using an iPhone 6 and not a 6s, which is why the button was grayed out for meDiggins
It only works with the trackpad. If one has a regular mouse(not sure about magic mouse) connected, that wont workArrester
I
10

Force pressure in iOS (eg: Peek & Pop) is not exposed through Xcode 7.0 nor Xcode 7.1 Beta's Simulator. The pressure touch options are only relevant for watchOS devices in those versions of Simulator. If you have the Xcode 7.1 beta, you'll notice that the menu option is actually disabled.

With Xcode 7.3 and the iOS 9.3 and later simulator runtimes, you can test peek/pop functionality using a force touch trackpad.

Iorgo answered 10/9, 2015 at 4:17 Comment(1)
How to calculate whether it is Shallow Press or Deep Press?Madson
H
9

You can enable 3D Touch in simulator. Thanks to this library.

  • After adding it Using a combination of the command, control, and shift keys 3D Touch can be enabled.

  • Don't forget to add library in Debug environment only. Exclude it from Release environment.

Horny answered 23/1, 2016 at 5:45 Comment(4)
Is that just for peep and pop or for home shortcuts as well ?Ouphe
Yes its for peep and pop only. You can use this for home shortcuts.Horny
Hi, :S! the Peek&Pop function don´t work on Simulator 6s plus with Xcode 7.2 when I do the longer press and use the combination of the command, control, and shift ... can you tell me why? ThanksHilel
@Horny : Peek&Pop function don´t work on Simulator 6s plus with Xcode 7.2 when I do the longer press and use the combination of the command, control, and shift ...Ibby
D
2

For the "Home Screen Quick Actions" touch I made the following:

  • created an object of UIMutableApplicationShortcutItem

  • put it into launchOptions to UIApplicationLaunchOptionsShortcutItemKey

  • and thats it

It looks like user did the 3d touch on the app icon.

    let shortcut = UIMutableApplicationShortcutItem(type: ShortcutIdentifier.Third.type,
        localizedTitle: "Title",
        localizedSubtitle: "Subtitle",
        icon: UIApplicationShortcutIcon(type: .Play), userInfo: [
        AppDelegate.applicationShortcutUserInfoIconKey: UIApplicationShortcutIconType.Play.rawValue
        ]
    )

    let launchOption = [
        "UIApplicationLaunchOptionsShortcutItemKey" : shortcut
    ]

    launchOptions = launchOption

(application:didFinishLaunchingWithOptions:)

Dustheap answered 12/9, 2015 at 10:54 Comment(1)
I did something similar to test it out but it would be nice to do the full test. There are several ways to enter the application via an app shortcut. One way is when the application is running in the background and you foreground it via the app shortcut.Thitherto
B
1

There's a bit of code here that allows you to test 3D Touch peek & pop in the simulator. Bear in mind this is code for iOS 9.0, and some of the internal/private methods have changed in 9.1 so you'll need to make a few minor changes (Hint: the word 'Position' changed to 'Location' in one of the method names).

https://gist.github.com/nickfrey/07e2c6d8d2e5444fb91d

Both this and https://github.com/DeskConnect/SBShortcutMenuSimulator mentioned in other answers allow you to test for 3D Touch without an actual device fairly competently.

Brought answered 16/11, 2015 at 10:22 Comment(0)
U
1

Officially Xcode 7.1 supports 3D touch but not on simulator. You need to have actual device in order to test. Check last paragraph of documentation from Apple.

Apple Document

3D touch not supported on simulator

However, you can use third-party tools to test it on simulator such as one highlighted by Nicolas S above.

Upali answered 27/11, 2015 at 12:22 Comment(0)
S
0

The newer macbooks are having force-touch enabled touch pad. I think these options will only work in that.

Shower answered 3/4, 2016 at 11:3 Comment(0)
A
0

It worked for me with XCode 9 & iphone 8 simulator. In your mac go to system preference -> Trackpad -> Enable Force click and haptic feedback.

enter image description here

Then press firmly on any part of iphone simulator to perform force touch action.

Acicular answered 8/1, 2018 at 16:16 Comment(2)
I did this, but it still doesn't work :( Xcode 9.4.1, iPhone X simulator.Terena
@Terena You have to use trackpad instead of mouse. It works for me on Xcode 10, but it was not obvious I have to use Trackpad in MacBook. Of course "Force Click and haptic feedback" must be checked.Jetblack

© 2022 - 2024 — McMap. All rights reserved.