iOS播放自定义提示音和震动

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/sdsd13212/article/details/52891169
@implementation LKVibrate{
    SystemSoundID soundID;
}

void soundCompleteCallback(SystemSoundID sound,void * clientData) {
    AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
    AudioServicesPlaySystemSound(sound);
}
- (void) playVibration{
    AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
}

- (void) stopVibration{
    AudioServicesDisposeSystemSoundID(kSystemSoundID_Vibrate);
}

- (void)playAlertSound{
    usleep(1000);
    NSString *soundFile = [[NSBundle mainBundle] pathForResource:@"doorbell.wav" ofType:nil];
    AudioServicesCreateSystemSoundID((__bridge CFURLRef) [NSURL fileURLWithPath:soundFile], &soundID);
    
    AudioServicesPlaySystemSound(soundID);
    AudioServicesAddSystemSoundCompletion(soundID, NULL, NULL, soundCompleteCallback, NULL);
}

-(void)stopAlertSound{
    AudioServicesDisposeSystemSoundID(soundID);
    AudioServicesRemoveSystemSoundCompletion(soundID);
}

+ (instancetype)shareLKVibrate{
    static id _instance;
    static dispatch_once_t _onceToken;
    dispatch_once(&_onceToken, ^{
        _instance = [[self alloc]init];
    });
    return _instance;
}

参考文章:帅气的链接

AudioServicesPlaySystemSound属性列表:帅气的链接
展开阅读全文

没有更多推荐了,返回首页