2017-04-09 216 views
0

我试图改变科尔多瓦插件,这样我就可以改变从iOS音乐类别JavaScript,但我得到的科尔多瓦警告生成日志更改科尔多瓦,nativeaudio插件

任何想法,我是错我的代码?第一个参数是工作,但第二个不

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

和iOS节:

- (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]; 
} 

我收到以下警告

/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); ^

+0

仅供参考,phongap已过时,使用'cordova'名 –

回答

0

你不可错过NSStringoptions到:

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

它应该是AVAudioSessionCategoryOptions枚举。

为了解决它,你可以写你的匹配为:

AVAudioSessionCategoryOptions optionsOrig = 0; 

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

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

编号:

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

请参阅Google文档here

+0

所以它应该是一个像0x1和0x2的数字? –

+0

为什么这个工作呢[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient withOptions:AVAudioSessionCategoryOptionDuckOthers error:nil]; –

+0

@JeroenWelzenVan由于'AVAudioSessionCategoryOptionDuckOthers'不是一个字符串,但数字 –