iOS Question Player error on iOS 13

Pendrush

Well-Known Member
Licensed User
Longtime User
This code
B4X:
- (void)register {
   MPRemoteCommandCenter* center = [MPRemoteCommandCenter sharedCommandCenter];
   center.playCommand.enabled = true;
   center.pauseCommand.enabled = true;
   [center.playCommand addTarget:self action:@selector(play)];
   [center.pauseCommand addTarget:self action:@selector(pause)];
}
called with
B4X:
NativeMe.RunMethod("register", Null) ' this is line 727 from error log below

give this error in iOS 13 simulator:
Application_Start
Application_Active
Test device id: 00000000-0000-0000-0000-000000000000
*** Assertion failure in -[MPRemoteCommand addTarget:action:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/MediaPlayer_Sim/MobileMusicPlayer-4017.200.33/SDK/MPRemoteCommand.m:134
Error occurred on line: 727 (pApp)
Unsupported action method signature. Must return MPRemoteCommandHandlerStatus or take a completion handler as the second argument.
Stack Trace: (
CoreFoundation __exceptionPreprocess + 350
libobjc.A.dylib objc_exception_throw + 48
CoreFoundation +[NSException raise:format:arguments:] + 88
Foundation -[NSAssertionHandler handleFailureInMethod:eek:bject:file:lineNumber:description:] + 191
MediaPlayer -[MPRemoteCommand addTarget:action:] + 1154
RE Beta -[b4i_papp register] + 272
CoreFoundation __invoking___ + 140
CoreFoundation -[NSInvocation invoke] + 319
RE Beta +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1672
RE Beta -[B4INativeObject RunMethod::] + 200
RE Beta -[b4i_papp _pg_resize::] + 8923
CoreFoundation __invoking___ + 140
CoreFoundation -[NSInvocation invoke] + 319
RE Beta +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1672
RE Beta -[B4IShell runMethod:] + 401
RE Beta -[B4IShell raiseEventImpl:method:args::] + 1775
RE Beta -[B4IShellBI raiseEvent:event:params:] + 1357
RE Beta +[B4IObjectWrapper raiseEvent:::] + 273
RE Beta __30-[B4IPanelView layoutSubviews]_block_invoke + 867
libdispatch.dylib _dispatch_call_block_and_release + 12
libdispatch.dylib _dispatch_client_callout + 8
libdispatch.dylib _dispatch_main_queue_callback_4CF + 1212
CoreFoundation __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
CoreFoundation __CFRunLoopRun + 2329
CoreFoundation CFRunLoopRunSpecific + 438
GraphicsServices GSEventRunModal + 65
UIKitCore UIApplicationMain + 1621
RE Beta main + 112
libdyld.dylib start + 1
??? 0x0 + 1
)

Any solution for this?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Update the inline code to:
B4X:
#If OBJC
@import MediaPlayer;
#import <AVFoundation/AVFoundation.h>
#import <AudioToolbox/AudioToolbox.h>
- (void)setAudioSession {
  AVAudioSession *audioSession = [AVAudioSession sharedInstance];
  NSError *err = nil;
  BOOL success = [audioSession setCategory:AVAudioSessionCategoryPlayback error:&err];
  if (success) {
    success = [audioSession setActive:YES error:&err];
    success = [audioSession setPreferredSampleRate:4096 error:nil];
    [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
  }
  if (!success) {
    [NSException raise:@"" format:@"Error setting audio session: %@", err];
    NSLog(@"Error setting category Audio Session: %@", [err localizedDescription]);
  }
}
- (void)register {
   MPRemoteCommandCenter* center = [MPRemoteCommandCenter sharedCommandCenter];
   center.playCommand.enabled = true;
   center.pauseCommand.enabled = true;
   [center.playCommand addTarget:self action:@selector(play)];
   [center.pauseCommand addTarget:self action:@selector(pause)];
}
- (MPMediaItemArtwork*)createArtwork:(UIImage*) image {
   return [[MPMediaItemArtwork alloc] initWithBoundsSize:image.size requestHandler:^UIImage* _Nonnull(CGSize aSize) { return image; }];
}
- (MPRemoteCommandHandlerStatus ) play {
   [self.bi raiseEvent:nil event:@"controlevent:"  params:@[@"play"]];
   return MPRemoteCommandHandlerStatusSuccess;
   
}
- (MPRemoteCommandHandlerStatus ) pause {
   [self.bi raiseEvent:nil event:@"controlevent:"  params:@[@"pause"]];
   return MPRemoteCommandHandlerStatusSuccess;
   
}
#End If
 
Upvote 0
Top