我的应用程序可以播放音乐,即使在后台模式下也能继续播放音乐。
但是在我安装了sinch!之后,当应用程序进入后台模式时,音乐会停止。
在功能方面,我打开了background modes: audio
语音IP和远程通知。我试图在进入后台([self.sinchClient stopListeningOnActiveConnection];
[self.sinchClient terminate];)
之前杀死sinchservices,但它没有用。
有什么建议吗?
这是我的代码
-(void)playUsingSession:(SPTSession *)session {
// Create a new player if needed
if (self.player == nil) {
self.player = [[SPTAudioStreamingController alloc] initWithClientId:[SPTAuth defaultInstance].clientID];
}
[self.player loginWithSession:session callback:^(NSError *error) {
if (error != nil) {
return;
}
[self initSinchClient:session.canonicalUsername];
NSURL *trackURI = [NSURL URLWithString:@"spotify:track:58s6EuEYJdlb0kO7awm3Vp"];
[self.player playURIs:@[ trackURI ] fromIndex:0 callback:^(NSError *error) {
if (error != nil) {
return;
}
}];
}];
}
- (void)sendMessageToMe{
NSArray *recipients = @[self.session.canonicalUsername];
SINOutgoingMessage *message = [SINOutgoingMessage messageWithRecipients:(NSArray *)recipients text:@"test"];
[self.sinchClient.messageClient sendMessage:message];
}
#pragma mark - SINClientDelegate methods
- (void)clientDidStart:(id<SINClient>)client {
self.sinchMessageClient = [self.sinchClient messageClient];
self.sinchMessageClient.delegate = self;
[self performSelector:@selector(sendMessageToMe) withObject:nil afterDelay:1];
}
- (void)initSinchClient:(NSString*)userId {
self.sinchClient = [Sinch clientWithApplicationKey:SINCH_APPLICATION_KEY
applicationSecret:SINCH_APPLICATION_SECRET
environmentHost:SINCH_ENVIRONMENT_HOST
userId:userId];
[self.sinchClient setSupportMessaging:YES];
[self.sinchClient setSupportActiveConnectionInBackground:YES];
self.sinchClient.delegate = self;
[self.sinchClient start];
[self.sinchClient startListeningOnActiveConnection];
}