26F-Studio / Techmino

Techmino:方块研究所唯一官方仓库(Github)
https://www.studio26f.org
GNU Lesser General Public License v3.0
549 stars 68 forks source link

Weird vibrations on iOS distro #256

Open C29H25N3O5 opened 3 years ago

C29H25N3O5 commented 3 years ago

When adjusting the Vibration slider in Settings, the strength of vibration cannot be specified on iOS devices. Even when the strength was set to 10, the device still produces the same vibration strength as if the strength is 1. It acts more like switch than a slider.

Also, it is suggested that the duration of the vibration could be shortened. Currently, the duration is so long that when multiple press was conducted in a short time, the device only produces one vibration.

I don't know whether this issue occurs on Android devices but it is a major problem on iPhone.

Trebor-Huang commented 3 years ago

This is impossible to implement without changing the source code of love and introducing undocumented API's of Apple, breaking support on older iOS versions.

Not-A-Normal-Robot commented 3 years ago

I'm pretty sure it's possible to check the OS version on LOVE, and you can adjust it to that

Trebor-Huang commented 3 years ago

I'm pretty sure it's possible to check the OS version on LOVE, and you can adjust it to that

No, the change of code is done outside of this repository, and outside of LOVE runtime. We might need an iOS developer to help with that. Lua code won't do here.

C29H25N3O5 commented 3 years ago

I'm pretty sure it's possible to check the OS version on LOVE, and you can adjust it to that

No, the change of code is done outside of this repository, and outside of LOVE runtime. We might need an iOS developer to help with that. Lua code won't do here.

Alright then. If that is the case, is it possible to just remove the vibration slider on iOS (before an LÖVE update to solve this problem)?

Trebor-Huang commented 3 years ago

Good news! We're working to do exactly the change I've described. But removing that slider before the work's done seems reasonable.

haolloyin commented 3 years ago

love2d uses a very old API AudioServicesPlaySystemSound(kSystemSoundID_Vibrate); which can only vibrate for about 0.5 seconds. See https://love2d.org/wiki/love.system.vibrate

image

The implementation is here: https://github.com/love2d/love/blob/master/src/common/ios.mm#L394-L400

The declaration is here: https://github.com/love2d/love/blob/master/src/common/ios.h#L67-L69 and it says Causes devices with vibration support to vibrate for about 0.5 seconds. is actually incorrect, because since iOS 10, there is a new API UIImpactFeedbackGenerator that can generate very light vibrations (requires iOS 10+).

The iOS development documentation is available at https://developer.apple.com/documentation/uikit/uiimpactfeedbackgenerator?language=objc

Only 7% of iOS users worldwide are now using iOS 12 or lower, Apple's official source https://developer.apple.com/support/app-store/

image

So, if Techmino's iOS developers manually change love2d's src/common/ios.mm#L398 to the following when packaging it would solve the problem (tested on my own iPhone X with iOS 14.7, it works perfect).

if (@available(iOS 10.0, *)) {
    UIImpactFeedbackGenerator *feedBackGenertor = [[UIImpactFeedbackGenerator alloc] initWithStyle:UIImpactFeedbackStyleMedium];
    [feedBackGenertor impactOccurred];
} else {
    AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
}
Trebor-Huang commented 3 years ago

Should this be closed?

C29H25N3O5 commented 3 years ago

YES.

C29H25N3O5 commented 3 years ago

It seems that this issue has found its way back to the latest version of iOS.

ParticleG commented 3 years ago

Fixed with latest PR#3 of Techmino-iOS repo

ParticleG commented 1 year ago

Okay, now we need to add iOS 13.0+ API for even finer controlsimpactOccurredWithIntensity. Also need to change: image