我正在尝试更改Cordova插件,以便我可以从javascript更改iOS音乐类别,但我在Cordova构建日志中收到警告
知道我的代码出了什么问题吗?第一个参数正在工作,但第二个参数不是
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: 警告:指向整数转换的不兼容指针发送'NSString * __ strong'到'AVAudioSessionCategoryOptions'类型的参数'(又名'enum AVAudioSessionCategoryOptions')[--Wint-conversion] [[AVAudioSession sharedInstance] setCategory:category withOptions:options error:nil]; ^ ~~~~~~~~~~~在模块'AVFoundation'中导入 /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: 注意:在这里将参数传递给参数'options' - (BOOL)setCategory:(NSString *)category withOptions:(AVAudioSessionCategoryOptions)options错误:(NSError **)outError NS_AVAILABLE_IOS(6_0); ^
答案 0 :(得分:0)
您无法将NSString
作为options
传递给:
[[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;
参见DOC here