Disclaimer: under answer requires calling non-public Apple API’s, which are not allowed in AppStore submissions. Despite the fact that at this cut-off date Apple’s automated checks aren’t catching this, if that adjustments sooner or later (or a guide assessment catches the behaviour), your app may be blocked. Use this at your personal danger.
To efficiently make a brief haptic through the use of AudioServicesPlaySystemSoundWithVibration
,you must name a personal methodology in AudioToolbox.Nevertheless it’s secure for right this moment’s App Retailer, trigger my app utilizing this know-how has already passing the assessment.I am imagine that App Retailer reviewer doesn’t live performance about utilizing this know-how in your app.
🥳To make it, you want a objective-c class:
#import <Basis/Basis.h>
#import <AudioToolbox/AudioServices.h>
#import <AudioToolbox/AudioToolbox.h>
#import "vibrate.h"
void AudioServicesPlaySystemSoundWithVibration(int, id, id);
@implementation Vibrate
+ (void) vibrateMutate
{
NSMutableDictionary* dict = [NSMutableDictionary dictionary];
NSMutableArray* arr = [NSMutableArray array ];
[arr addObject:[NSNumber numberWithBool:YES]];
[arr addObject:[NSNumber numberWithInt:50]];
[arr addObject:[NSNumber numberWithBool:NO]];
[arr addObject:[NSNumber numberWithInt:10]];
[dict setObject:arr forKey:@"VibePattern"];
[dict setObject:[NSNumber numberWithDouble:.25] forKey:@"Depth"];
AudioServicesPlaySystemSoundWithVibration(4095,nil,dict); //ERROR
}
+ (void) vibrateSectionChange
{
NSMutableDictionary* dict = [NSMutableDictionary dictionary];
NSMutableArray* arr = [NSMutableArray array ];
[arr addObject:[NSNumber numberWithBool:YES]];
[arr addObject:[NSNumber numberWithInt:150]];
[arr addObject:[NSNumber numberWithBool:NO]];
[arr addObject:[NSNumber numberWithInt:10]];
[dict setObject:arr forKey:@"VibePattern"];
[dict setObject:[NSNumber numberWithDouble:.75] forKey:@"Depth"];
AudioServicesPlaySystemSoundWithVibration(4095,nil,dict);
}
@finish
and a .m file
#import <Basis/Basis.h>
#import <AudioToolbox/AudioToolbox.h>
@interface Vibrate : NSObject
+ (void)vibrateMutate;
+ (void)vibrateSectionChange;
@finish
Final, including this line to the “YOU_PROJECT_NAME-Bridging-Header.h” file that Xcode about create for you!
#import "Vibrate.h"
Lastly , you may name this methodology in you Swift code😎(if not working, relaunch your Xcode app may work):
Vibrate.vibrateMutate()
You will get a brief、Morden-style haptic in you dynamic island!