iOS-为手机添加摇一摇功能,以及 振动或者 响铃


title: iOS-为手机添加摇一摇功能,以及 振动或者 响铃
date: 2016-06-30 16:55:10
categories:

  • Code
  • iOS
    tags:
  • AudioServicesPlaySystemSound
  • AudioServicesCreateSystemSoundID

timg.jpeg
// 工程添加摇一摇方法 
#pragma mark yaoyiyao
- (BOOL)canBecomeFirstResponder
{
    return YES;// default is NO
}

- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
    //处理摇一摇之后响应的事件 
    //添加震动功能
    AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
    
    //添加手机响铃的方法
    SystemSoundID soundId;
    NSString *path = [[NSBundle mainBundle]pathForResource:@“song” ofType:@"avr"];
    AudioServicesCreateSystemSoundID((__bridge CFURLRef)[NSURL fileURLWithPath:path], &soundId);
    
    // 声音播放完毕的回调
    AudioServicesAddSystemSoundCompletion(sysSound, NULL, NULL, _systemSoundDidComplete, NULL);

    AudioServicesPlaySystemSound(soundId);
}

void _systemSoundDidComplete(SystemSoundID ssID, void*clientData) {
    AudioServicesDisposeSystemSoundID(ssID);
    
}


你可能感兴趣的:(iOS-为手机添加摇一摇功能,以及 振动或者 响铃)