PhoneGap 3.0 iOS plugin
PhoneGap 3.0 iOS plugin
我开始为iOS编写PhoneGap插件,但我在通过cordova.exec()
调用Objective C代码中的一个简单NSLog()
时遇到了问题。随着PhoneGap 3.0的最新发布,以及可能令人困惑的PhoneGap/Cordova命名,很难在网上找到提供任何最新或有效示例的资源。
这是我的基本目标C代码:
// BLLog.h
#import <Cordova/CDV.h>
@interface BLLog : CDVPlugin
- (void)log:(CDVInvokedUrlCommand *)command;
@end
和
#import "BLLog.h"
@implementation BLLog
- (void)log:(CDVInvokedUrlCommand *)command
{
NSLog(@"Hey, it works!");
}
@end
我的html/javascript与phonegap create
生成的代码非常相似,只是添加了一些内容。
<html>
<head>
...
</head>
<body>
...
<script type="text/javascript" src="phonegap.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript">
app.initialize();
document.addEventListener('deviceready', function () {
app.log();
}, false);
</script>
</body>
</html>
此代码包含cordova.exec()
:
var app = {
...
log: function () {
alert('log');
cordova.exec(function (){ console.log('success') }, function () { console.log('error') }, 'BLLog', 'log', []);
}
};
这是我的config.xml
:
<?xml version='1.0' encoding='utf-8'?>
<widget id="com.metaio.app" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:gap="http://phonegap.com/ns/1.0">
<name>GapApp</name>
<description>
Hello World sample application that responds to the deviceready event.
</description>
<author email="support@phonegap.com" href="http://phonegap.com">
PhoneGap Team
</author>
<feature name="http://api.phonegap.com/1.0/device" />
<preference name="permissions" value="none" />
<preference name="orientation" value="default" />
<preference name="target-device" value="universal" />
<preference name="fullscreen" value="true" />
<preference name="webviewbounce" value="true" />
<preference name="prerendered-icon" value="true" />
<preference name="stay-in-webview" value="false" />
<preference name="ios-statusbarstyle" value="black-opaque" />
<preference name="detect-data-types" value="true" />
<preference name="exit-on-suspend" value="false" />
<preference name="show-splash-screen-spinner" value="true" />
<preference name="auto-hide-splash-screen" value="true" />
<preference name="disable-cursor" value="false" />
<preference name="android-minSdkVersion" value="7" />
<preference name="android-installLocation" value="auto" />
<icon src="icon.png" />
<icon gap:density="ldpi" gap:platform="android" src="res/icon/android/icon-36-ldpi.png" />
<icon gap:density="mdpi" gap:platform="android" src="res/icon/android/icon-48-mdpi.png" />
<icon gap:density="hdpi" gap:platform="android" src="res/icon/android/icon-72-hdpi.png" />
<icon gap:density="xhdpi" gap:platform="android" src="res/icon/android/icon-96-xhdpi.png" />
<icon gap:platform="blackberry" src="res/icon/blackberry/icon-80.png" />
<icon gap:platform="blackberry" gap:state="hover" src="res/icon/blackberry/icon-80.png" />
<icon gap:platform="ios" height="57" src="res/icon/ios/icon-57.png" width="57" />
<icon gap:platform="ios" height="72" src="res/icon/ios/icon-72.png" width="72" />
<icon gap:platform="ios" height="114" src="res/icon/ios/icon-57-2x.png" width="114" />
<icon gap:platform="ios" height="144" src="res/icon/ios/icon-72-2x.png" width="144" />
<icon gap:platform="webos" src="res/icon/webos/icon-64.png" />
<icon gap:platform="winphone" src="res/icon/windows-phone/icon-48.png" />
<icon gap:platform="winphone" gap:role="background" src="res/icon/windows-phone/icon-173.png" />
<gap:splash gap:density="ldpi" gap:platform="android" src="res/screen/android/screen-ldpi-portrait.png" />
<gap:splash gap:density="mdpi" gap:platform="android" src="res/screen/android/screen-mdpi-portrait.png" />
<gap:splash gap:density="hdpi" gap:platform="android" src="res/screen/android/screen-hdpi-portrait.png" />
<gap:splash gap:density="xhdpi" gap:platform="android" src="res/screen/android/screen-xhdpi-portrait.png" />
<gap:splash gap:platform="blackberry" src="res/screen/blackberry/screen-225.png" />
<gap:splash gap:platform="ios" height="480" src="res/screen/ios/screen-iphone-portrait.png" width="320" />
<gap:splash gap:platform="ios" height="960" src="res/screen/ios/screen-iphone-portrait-2x.png" width="640" />
<gap:splash gap:platform="ios" height="1024" src="res/screen/ios/screen-ipad-portrait.png" width="768" />
<gap:splash gap:platform="ios" height="768" src="res/screen/ios/screen-ipad-landscape.png" width="1024" />
<gap:splash gap:platform="winphone" src="res/screen/windows-phone/screen-portrait.jpg" />
<feature name="BLLog" onload="true">
<param name="ios-package" value="BLLog" />
</feature>
<access origin="http://127.0.0.1*" />
</widget>
我还尝试用<plugin name="BLLog" value ="BLLog" '>
替换<feature>
标签,但这也不起作用。
最后,这里是XCode输出:
2013-07-30 11:36:40.810 GapApp[407:907] ERROR: Plugin 'BLLog' not found, or is not a CDVPlugin. Check your plugin mapping in config.xml.
2013-07-30 11:36:40.812 GapApp[407:907] -[CDVCommandQueue executePending] [Line 116] FAILED pluginJSON = [
"BLLog870927167",
"BLLog",
"log",
[
]
]
我建议在github中进行搜索。看看其他插件。
有一点令人困惑,那就是它们使用的名称与xcode相同。他们可能引用了xcode项目中的config.xml。
我在github上看到的所有插件都是plugin.xml
https://github.com/sectore/phonegap3-native-ios-plugin?files=1
看看这个例子。这可能会有所帮助。
这是你的整个config.xml吗?
我没有看到PG版本或其他必需参数的声明。
我还以为它应该是plugin.xml
<param name="ios-package" value="CDVLogger"/>
</feature>
</config-file>
<js-module src="www/console-via-logger.js" name="console">
<clobbers target="console" />
</js-module>
<js-module src="www/logger.js" name="logger">
<clobbers target="cordova.logger" />
</js-module>
<header-file src="src/ios/CDVLogger.h" />
<source-file src="src/ios/CDVLogger.m" />
</platform>
我绝对没有资格回答这个问题。只是观察。
相关文章:
- Ckeditor-plugin:插入虚假元素add不情愿<p>标签前后
- 如何确定javascript已经完成了某些操作.ios上的
- 压缩phonegap中ios的图像插件
- React Native通过Navigator将用户输入数据传递到选项卡栏IOS中的组件
- 如何在iOS应用程序中从Firebase中删除超过6小时的数据
- 是否可以使用iframe API在iOS浏览器上播放youtube视频
- iOS 中的按钮触摸状态
- 在iOS 4.3中未调用UIWebView shouldStartLoadWithRequest
- 在iOS和Android上使用React native时,我还能使用本机第三方lirbraries吗
- 谷歌地图根本不适用于Meteor-iOS
- Facebook登录不适用于iOS的应用内浏览器
- 绕z轴旋转时出现iOS陀螺仪错误
- 触摸启动事件未在iframe iOS 6中启动
- 有没有一种方法可以检测ios<>使用jquery和触发器操作形成导航按钮
- 无法在Cordova 4.0 ios中将jpg/jpeg图像转换为Base64
- iOS鼠标中心绑定只工作一次
- javascript函数访问ios本机功能
- Loopback AngularJS JavaScript SDK - Gruntfile plugin
- Moment js and IOS
- PhoneGap 3.0 iOS plugin