2017-04-09 109 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'不是一個字符串,但數字 –