简体   繁体   中英

Change the cordova-nativeaudio plugin

I am trying to change a Cordova plugin so I can change the iOS music category from javascript but I get a warning in the Cordova build log

Any idea what I is wrong with my code? The first parameter is working but the second not

audio.setCategory('AVAudioSessionCategoryAmbient', 
                  'AVAudioSessionCategoryOptionMixWithOthers')

and iOS section:

- (void) setCategory:(CDVInvokedUrlCommand *)command {

    NSArray* arguments = command.arguments;
    NSString *category = [arguments objectAtIndex:0];
    NSString *options = [arguments objectAtIndex:1];

    [[AVAudioSession sharedInstance] setCategory:category withOptions:options error:nil];


    [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK] callbackId:command.callbackId];
}

I receive the following warning

/project/koeriersapp/Plugins/cordova-plugin-nativeaudio/NativeAudio.m:67:71: warning: incompatible pointer to integer conversion sending 'NSString *__strong' to parameter of type 'AVAudioSessionCategoryOptions' (aka 'enum AVAudioSessionCategoryOptions') [-Wint-conversion] [[AVAudioSession sharedInstance] setCategory:category withOptions:options error:nil]; ^~~~~~~~~~~~ In module 'AVFoundation' imported from /project/koeriersapp/Plugins/cordova-plugin-nativeaudio/NativeAudio.h:11: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS10.1.sdk/System/Library/Frameworks/AVFoundation.framework/Frameworks/AVFAudio.framework/Headers/AVAudioSession.h:364:85: note: passing argument to parameter 'options' here - (BOOL)setCategory:(NSString *)category withOptions:(AVAudioSessionCategoryOptions)options error:(NSError **)outError NS_AVAILABLE_IOS(6_0); ^

You cannot pass NSString as options to:

[[AVAudioSession sharedInstance] setCategory:category withOptions:options error:nil]; 

It should be AVAudioSessionCategoryOptions enumeration.

To solve it you can write your matcher as:

AVAudioSessionCategoryOptions optionsOrig = 0;

if([options isEqualToString: @"AVAudioSessionCategoryOptionMixWithOthers"]){
    optionsOrig = AVAudioSessionCategoryOptionMixWithOthers;
}

[[AVAudioSession sharedInstance] setCategory: category withOptions:optionsOrig error:nil];

Ref:

- (BOOL)setCategory:(NSString *)category 
    withOptions:(AVAudioSessionCategoryOptions)options 
          error:(NSError * _Nullable *)outError;

See DOCs here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM