-2

I downloaded a sample project from here(haptic sampler) and I cannot run because of several issues. I solved signing identifier.

The error messages say:

  • ~/PlayingACustomHapticPatternFromAFile/HapticSampler/ViewController.swift:66:19: Type 'CHHapticEngine.StoppedReason' has no member 'gameControllerDisconnect'

  • ~/PlayingACustomHapticPatternFromAFile/HapticSampler/ViewController.swift:68:19: Type 'CHHapticEngine.StoppedReason' has no member 'engineDestroyed'

if I delete these parts, another error says:

  • Thread 1: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value

Here are my questions.

  1. Do same issues happen to you?

  2. How can I fix this problem?

Here's my environment specification.

  • macOS Catalina 10.15.6
  • Xcode 11.6
  • iPhone 7 iOS 13.6

enter image description here

Tiz
  • 31
  • 5

3 Answers3

1

Haptic feedback needs an actual device since it uses a vibration motor. It can not be run on a simulator. That is why you are getting the error message "Failed to create engine!". To fix it connect to an actual device and select a team in "Signing & Capabilities" and run.

Shreeram Bhat
  • 2,849
  • 2
  • 11
  • 19
  • Thank you. But I had this app run on my iPhone so it can’t be a problem. I should’ve written in the question. – Tiz Aug 02 '20 at 11:52
  • I've got your point. I actually don't own any iPhone with iOS 14 installed. That makes sense. I appreciate your answer. – Tiz Aug 02 '20 at 12:04
  • @Tiz iOS 14 should only be necessary for the two cases that are throwing errors, which you mention you deleted. Haptic feedback is supported in iOS 13. Perhaps you need Xcode 12...? – Sylvan D Ash Aug 02 '20 at 12:11
  • I am really sorry. I screwed up this whole topic, not mentioning my hardware specifications. iPhone 7, I currently use is not even supported by core haptics. – Tiz Aug 02 '20 at 12:24
0

The problem is that the enum cases

.gameControllerDisconnect

And

.engineDestroyed

Were introduced in iOS 14, Xcode 12 beta. But you are running an earlier version so, as the error message says, they don’t exist.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • I understood. You really helped me and I was totally misunderstood. As described https://developer.apple.com/documentation/corehaptics/playing_haptics_on_game_controllers here, these features are to be introduced in coming iOS and Xcode. Thank you. – Tiz Aug 02 '20 at 12:03
  • The OP did mention that he deleted those two cases though... – Sylvan D Ash Aug 02 '20 at 12:09
-1

Replace the following lines of ViewController.swift Line 48 in the createEngine() function.

if engine == nil {
    print("Failed to create engine!")
}

With:

guard let engine = engine else {
    print("Failed to create engine!")
    return
}

That should resolve the compile + runtime errors you're currently getting

Sylvan D Ash
  • 1,047
  • 13
  • 24
  • You are not actually fixing the problem that he is facing with the app. Your code makes app unusable since it returns before executing any useful code. Down voted. – Shreeram Bhat Aug 02 '20 at 11:49