Skip to content

Commit

Permalink
修改声音问题
Browse files Browse the repository at this point in the history
  • Loading branch information
BailingIOS committed May 18, 2018
1 parent 0c38c55 commit 24b1b8a
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions ios-rongcallkit/RongCallKit/RCCall.mm
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ @interface RCCall () <RCCallReceiveDelegate>
@property(nonatomic, strong) AVAudioPlayer *audioPlayer;
@property(nonatomic, strong) NSMutableArray *callWindows;
@property(nonatomic, strong) NSMutableArray *locationNotificationList;
@property(nonatomic, assign) BOOL isCallVibrating;
@end

@implementation RCCall
Expand All @@ -45,6 +46,7 @@ + (instancetype)sharedRCCall {
pRongVoIP.maxMultiVideoCallUserNumber = 9;
pRongVoIP.callWindows = [[NSMutableArray alloc] init];
pRongVoIP.locationNotificationList = [[NSMutableArray alloc] init];
pRongVoIP.isCallVibrating = NO;

// agoraRegisterVideoFrameObserver(RCDVideoFrameObserver::sharedObserver(), true, true);
// agoraRegisterAudioFrameObserver(RCDAudioFrameObserver::sharedObserver());
Expand All @@ -62,8 +64,7 @@ - (void)registerNotification {
}

- (void)appDidBecomeActive {
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(triggerVibrateRCCall) object:nil];
[[AVAudioSession sharedInstance] setActive:NO withOptions:AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation error:nil];
[self stopReceiveCallVibrate];
for (UILocalNotification *notification in self.locationNotificationList) {
if ([notification.userInfo[@"appData"][@"callId"] isEqualToString:self.currentCallSession.callId]) {
[[UIApplication sharedApplication] cancelLocalNotification:notification];
Expand Down Expand Up @@ -260,9 +261,7 @@ - (void)dismissCallViewController:(UIViewController *)viewController {
}
}
[viewController dismissViewControllerAnimated:YES completion:nil];

[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(triggerVibrateRCCall) object:nil];
[[AVAudioSession sharedInstance] setActive:NO withOptions:AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation error:nil];
[self stopReceiveCallVibrate];
}

- (RCCallSession *)currentCallSession {
Expand Down Expand Up @@ -295,6 +294,8 @@ - (void)didCancelCallRemoteNotification:(NSString *)callId
inviterUserId:(NSString *)inviterUserId
mediaType:(RCCallMediaType)mediaType
userIdList:(NSArray *)userIdList {
[self stopReceiveCallVibrate];

for (UILocalNotification *notification in self.locationNotificationList) {
if ([notification.userInfo[@"appData"][@"callId"] isEqualToString:callId]) {
[[UIApplication sharedApplication] cancelLocalNotification:notification];
Expand All @@ -321,10 +322,7 @@ - (void)didReceiveCallRemoteNotification:(NSString *)callId
}
#endif

//默认情况按静音或者锁屏键会静音
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategorySoloAmbient error:nil];
[self triggerVibrateRCCall];
[self startReceiveCallVibrate];

UILocalNotification *callNotification = [[UILocalNotification alloc] init];
callNotification.alertAction = NSLocalizedStringFromTable(@"LocalNotificationShow", @"RongCloudKit", nil);
Expand Down Expand Up @@ -399,6 +397,25 @@ - (void)loadErrorAlertWithConfirm:(NSString *)title message:(NSString *)message
});
}

- (void)startReceiveCallVibrate
{
self.isCallVibrating = YES;
//默认情况按静音或者锁屏键会静音
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategorySoloAmbient error:nil];
[self triggerVibrateRCCall];
}

- (void)stopReceiveCallVibrate
{
if (self.isCallVibrating)
{
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(triggerVibrateRCCall) object:nil];
[[AVAudioSession sharedInstance] setActive:NO withOptions:AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation error:nil];
self.isCallVibrating = NO;
}
}

- (void)triggerVibrateRCCall {
__weak typeof(self) weakSelf = self;
NSString *version = [UIDevice currentDevice].systemVersion;
Expand Down

0 comments on commit 24b1b8a

Please sign in to comment.