In iOS17 dynamic island have capable to interactive with Button and Toggle .I wish to make a haptic effect when tap the button in dynamic island.
The normal solution NOT working in dynamic island likeUIImpactFeedbackGenerator.init(style: UIImpactFeedbackGenerator.FeedbackStyle.light).impactOccurred().
After I make a lot of trying,I find the oldest way to generate a haptic——AudioServicesPlayAlertSound(SystemSoundID(kSystemSoundID_Vibrate))is still working.
But the problem is does AudioServicesPlayAlertSound can play a short haptic?
The answer is Yes!
Disclaimer: below solution requires calling private Apple API's, which aren't allowed in AppStore submissions. Even though at this point in time Apple's automated checks aren't catching this, if that changes in the future (or a manual review catches the behaviour), your app might be blocked. Use this at your own risk.
To successfully make a short haptic by using
AudioServicesPlaySystemSoundWithVibration,you have to call a private method in AudioToolbox.But it's safe for today's App Store, cause my app using this technology has already passing the review.I'm believe that App Store reviewer does not concert about using this technology in your app.To make it, you need a objective-c class:
(raw objective-c version)
and a .m file
Last, adding this line to the "YOU_PROJECT_NAME-Bridging-Header.h" file that Xcode about create for you!
Finally , you can call this method in you Swift code(if not working, relaunch your Xcode app might work):
You'll get a short、Morden-style haptic in you dynamic island!