Skip to content

Commit 72d6668

Browse files
guangyaoguangyao
authored andcommitted
add在聊天会话时,新消息有语音提示
1 parent 7178b70 commit 72d6668

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

ios/RNNeteaseIm/RNNeteaseIm/ConversationViewController.m

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ @interface ConversationViewController ()<NIMMediaManagerDelegate,NIMMediaManager
2626
NSMutableArray *_sessionArr;
2727

2828
}
29+
@property (nonatomic,strong) AVAudioPlayer *player; //播放提示音
2930

3031
@end
3132

@@ -34,6 +35,7 @@ @implementation ConversationViewController
3435
- (void)viewDidLoad {
3536
[super viewDidLoad];
3637
// Do any additional setup after loading the view.
38+
3739
}
3840

3941
+(instancetype)initWithConversationViewController{
@@ -46,6 +48,15 @@ +(instancetype)initWithConversationViewController{
4648
return conVC;
4749
}
4850

51+
- (instancetype)init {
52+
self = [super init];
53+
if(self) {
54+
NSURL *url = [[NSBundle mainBundle] URLForResource:@"message" withExtension:@"wav"];
55+
_player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];
56+
}
57+
return self;
58+
}
59+
4960
-(void)startSession:(NSString *)sessionID withType:(NSString *)type{
5061
_sessionID = sessionID;
5162
_type = type;
@@ -509,8 +520,10 @@ - (void)onRecvMessages:(NSArray *)messages
509520
completion:nil];
510521
//标记已读消息
511522
[[NIMSDK sharedSDK].conversationManager markAllMessagesReadInSession:_session];
523+
[self.player stop];
524+
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryAmbient error:nil];
525+
[self.player play];
512526
}
513-
514527
}
515528

516529

ios/RNNeteaseIm/RNNeteaseIm/RNNotificationCenter.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ - (void)playMessageAudioTip
8181

8282
- (void)checkMessageAt:(NSArray *)messages
8383
{
84-
}
84+
85+
}
8586

8687
#pragma mark - NIMSystemNotificationManagerDelegate
8788
- (void)onReceiveCustomSystemNotification:(NIMCustomSystemNotification *)notification{//接收自定义通知

0 commit comments

Comments
 (0)