我遇到了以下问题:我正在将旧的 Phonegap 2.7 项目升级到 Phonegap 3.0,但找不到其中一个插件。
PhoneGap 的错误:
ERROR: Plugin 'SoundPlug' not found, or is not a CDVPlugin. Check your plugin mapping in config.xml.
[CDVCommandQueue executePending] [Line 117] FAILED pluginJSON = [
"SoundPlug1195442045",
"SoundPlug",
"getVolume",
[
]
]
www-root 中的 config.xml:
<feature name="SoundPlug">
<param name="ios-package" value="SoundPlug" />
<param name="onload" value="true" />
</feature>
<feature name="SocialSharing">
<param name="ios-package" value="SocialSharing" />
<param name="onload" value="true" />
</feature>
问题在于 SoundPlug,SocialSharing 没有给出任何警告(或者那是因为它在首先加载的 SoundPlug 上失败)。
在 SoundPlug.h 中:
#import <AudioToolbox/AudioServices.h>
#import <MediaPlayer/MediaPlayer.h>
#import <Cordova/CDV.h>
@interface SoundPlug : CDVPlugin
- (void) setVolume:(CDVInvokedUrlCommand*)command;
- (void) getVolume:(CDVInvokedUrlCommand*)command;
@结尾
在 SoundPlug.m 中:
#import "SoundPlug.h"
#import <MediaPlayer/MediaPlayer.h>
@implementation SoundPlug
- (void) setVolume:(CDVInvokedUrlCommand*)command
{
MPMusicPlayerController* musicPlayer = [MPMusicPlayerController applicationMusicPlayer];
NSInteger volume = [(NSString *)[command.arguments objectAtIndex:0] integerValue];
//musicPlayer.volume = 1; // max volume
//musicPlayer.volume = 0; // min volume (mute)
musicPlayer.volume = volume * 0.0625; // 1 bar on the overlay volume display
NSLog(@"Volume set to %f", musicPlayer.volume);
}
-(void) getVolume:(CDVInvokedUrlCommand*)command
{
MPMusicPlayerController* musicPlayer = [MPMusicPlayerController applicationMusicPlayer];
CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDouble:musicPlayer.volume];
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
}
@end
重要的是:平台是iOS7。我从头开始重新创建项目并导入文件。