-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix:#2110 deactivate the old session when playing again #2111
fix:#2110 deactivate the old session when playing again #2111
Conversation
@mvn-haiphung-dn I just merged in #2091 -- would you mind seeing if this is still an issue with those fixes? |
@dcvz I think we've tried to use latest release (RC08) and we still have this problem. It seems like only deactivating session and activating it back resolves the problem 😔 |
thanks for confirming @kirillzyusko <3 |
@kirillzyusko can you describe the problem you were seeing? What Unity game was involved? |
@puckey it was very hard to isolate the problem that we had, because Unity games are developed by another company and it's not open source code, so we were not able to provide a repro. Basically steps to reproduce were described in #2110 - when you play an audio after you played a game you will not see a song in notification center. I've tried to debug this problem a little bit - from my observation our Unity module just changes category to #if TARGET_IPHONE_SIMULATOR
#else
#import "ReactNativeUnityView.h"
#import "ReactNativeUnity.h"
#import <AVFAudio/AVAudioSession.h>
NSDictionary* appLaunchOpts;
@implementation ReactNativeUnityView
-(id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[ReactNativeUnityView changeAudioSessionCategory:AVAudioSessionCategoryAmbient]; // <- ambient on mount
_uView = [[[ReactNativeUnity launchWithOptions:appLaunchOpts] appController] rootView];
[FrameworkLibAPI registerAPIforNativeCalls:self];
}
return self;
}
+ (void)changeAudioSessionCategory:(AVAudioSessionCategory)category {
// schedule async operation and execute it as soon as possible
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
NSError *setCategoryErr = nil;
NSError *activationErr = nil;
[[AVAudioSession sharedInstance] setCategory:category error:&setCategoryErr];
[[AVAudioSession sharedInstance] setActive:YES error:&activationErr];
NSLog(@"AVAudioSession changed. Category error: %@. Activation error: %@", [setCategoryErr localizedDescription], [activationErr localizedDescription]);
});
}
- (void)layoutSubviews
{
[super layoutSubviews];
[_uView removeFromSuperview];
_uView.frame = self.bounds;
[self insertSubview:_uView atIndex:0];
}
+ (void)pauseUnity:(BOOL * _Nonnull)pause
{
[[ReactNativeUnity ufw] pause:pause];
}
+ (void)unloadUnity
{
UIWindow * main = [[[UIApplication sharedApplication] delegate] window];
if(main != nil) {
[main makeKeyAndVisible];
if ([ReactNativeUnity ufw]) {
[self changeAudioSessionCategory:AVAudioSessionCategoryPlayback]; // <- playback on unmount
[[ReactNativeUnity ufw] unregisterFrameworkListener:[ReactNativeUnity ufw]];
[[ReactNativeUnity ufw] unloadApplication];
}
}
}
+ (void)UnityPostMessage:(NSString*)gameObject methodName:(NSString*)methodName message:(NSString*) message {
dispatch_async(dispatch_get_main_queue(), ^{
[[ReactNativeUnity ufw] sendMessageToGOWithName:[gameObject UTF8String] functionName:[methodName UTF8String] message:[message UTF8String]];
});
}
- (void)sendMessageToMobileApp:(NSString *)message {
if (self.onUnityMessage) {
NSDictionary* data = @{
@"message": message
};
self.onUnityMessage(data);
}
}
@end
#endif I've tried to add Are you concerned by this fix? Or maybe want us to test any upcoming PR? |
Fix #2110