HBuilder is used to write H5 projects, and Xcode is used to write iOS native plug-ins. What I need to achieve is to click Print on the H5 page and run the iOS native plug-in to connect to the Bluetooth printer and print out the obtained content.
First go to the HBuilder documentation, download the HBuilder offline packaging iOS version SDK, run HBuilder-Hello, and start native plug-in development based on the HBuilder-Hello project.
HTML5+ base extension adopts a three-layer structure, JS layer, PluginBridge layer and Native layer. The three layers of functions are:
JS layer: Called on the Webview page, trigger the Native layer code and obtain the execution results. PluginBridge layer: Process the JS layer request and trigger the Native layer extension plug-in code.
Native layer: The platform native code of the plug-in extension is responsible for executing business logic and returning the execution results to the requested page.
First register the corresponding relationship
Modify the feature.plist file in PandoraAPI.bundle and add the corresponding relationship between the JS plug-in alias and the Native plug-in class. The SDK base will find and generate the corresponding relationship based on the corresponding relationship. Native object and execute the corresponding method.
plugintest is the class name of the plug-in class you want to extend. Create the plugintest class in iOS and inherit it from PGPlugin. Import PGPlugin.h and PGMethod.h in .h.
#include "PGPlugin.h" #include "PGMethod.h"
If If you need a static library, just drag the .a and .h files into the project. The methods in native are divided into synchronous and asynchronous methods. I will only introduce the asynchronous methods here
- (void)PluginTestFunctionArrayArgu:(PGMethod *)msg { NSArray *pArray = [NSArray array]; if (msg) { //CallBackid 异步方法的回调id,H5+ 会根据回调ID通知JS层运行结果成功或者失败 NSString *cdId = [msg.arguments objectAtIndex:0]; //用户的参数会在第二个参数传回,可以按照Array方式传入 pArray = [msg.arguments objectAtIndex:1]; NSLog(@"cdId: %@ pArray: %@",cdId,pArray); // 如果使用Array方式传递参数 NSString *pResultString = [NSString stringWithFormat:@"%@ %@ %@ %@ %@ %@ %@",[pArray objectAtIndex:0],[pArray objectAtIndex:1], [pArray objectAtIndex:2],[pArray objectAtIndex:3],[pArray objectAtIndex:4], [pArray objectAtIndex:5],[pArray objectAtIndex:6]]; NSLog(@"pResultString: %@",pResultString); //可以直接调用所导入的静态库里面的方法 NSString *UUID = [ZQDeviceSDK Prn_GetPortList:1]; NSString *port = [UUID stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; [self startPrintText:pArray andUUID:port]; // 运行Native代码结果和预期相同,调用回调通知JS层运行成功并返回结果 PDRPluginResult *result = [PDRPluginResult resultWithStatus:PDRCommandStatusOK messageAsString:pResultString]; // 如果Native代码运行结果和预期不同,需要通过回调通知JS层出现错误,并返回错误提示// PDRPluginResult *resultError = [PDRPluginResult resultWithStatus:PDRCommandStatusError messageAsString:@"出错了!"]; //通知JS层Native层运行结果,JS Pluginbridge会根据cbid找到对应的回调方法并触发 [self toCallback:cdId withReslut:[result toJSONString]]; } }
Function in js
document.addEventListener( "plusready", function(){ // 声明的JS“扩展插件别名” var _BARCODE = 'plugintest',B = window.plus.bridge; var plugintest ={ // 声明异步返回方法 // 通知Native层plugintest扩展插件运行”PluginTestFunction”方法 //参数为所需传入原生的参数 PluginTestFunctionArrayArgu : function (Argus, successCallback, errorCallback ){ var success = typeof successCallback !== 'function' ? null : function(args) { successCallback(args); }, fail = typeof errorCallback !== 'function' ? null : function(code) { errorCallback(code); }; callbackID = B.callbackId(success, fail); //这里写上原生中的异步方法名 return B.exec(_BARCODE, "PluginTestFunctionArrayArgu", [callbackID, Argus]); } window.plus.plugintest = plugintest; }, true );
Code called in H5
plus.plugintest.PluginTestFunctionArrayArgu( printData, function( result ) { mui.alert( result ); },function(result){ mui.alert(result) });
The general development process is like this. In fact, the real trouble is not the code but the various debugging of the IDE..
The following is Import the H5 project into Xcode to implement offline packaging. In the manifest.json of the project, modify the appid so that it is consistent with the appid in Xcode. Version and Build correspond to the name and code
under version. Change the manifest. Delete all the Chinese comments in json, and then import the H5 project into the www directory under Pandora. Remember to import all the files under the project into www, instead of importing the project folder directly into www, otherwise it will run. Don’t open the app.
Change the name of the folder on the upper level of www to the name consistent with the Appid. To modify the icon, you can put the icon into HBuilder to generate an icon of the corresponding size. This is very user-friendly.. Before iOS For development, you go to the artist. Then you change the project name, etc. I won’t go into details one by one.
【Related recommendations】
1. Free h5 online video tutorial
3. php.cn original html5 video tutorial
The above is the detailed content of Example code for H5 project development of iOS plug-in function. For more information, please follow other related articles on the PHP Chinese website!

Web standards and technologies have evolved from HTML4, CSS2 and simple JavaScript to date and have undergone significant developments. 1) HTML5 introduces APIs such as Canvas and WebStorage, which enhances the complexity and interactivity of web applications. 2) CSS3 adds animation and transition functions to make the page more effective. 3) JavaScript improves development efficiency and code readability through modern syntax of Node.js and ES6, such as arrow functions and classes. These changes have promoted the development of performance optimization and best practices of web applications.

H5 is not just the abbreviation of HTML5, it represents a wider modern web development technology ecosystem: 1. H5 includes HTML5, CSS3, JavaScript and related APIs and technologies; 2. It provides a richer, interactive and smooth user experience, and can run seamlessly on multiple devices; 3. Using the H5 technology stack, you can create responsive web pages and complex interactive functions.

H5 and HTML5 refer to the same thing, namely HTML5. HTML5 is the fifth version of HTML, bringing new features such as semantic tags, multimedia support, canvas and graphics, offline storage and local storage, improving the expressiveness and interactivity of web pages.

H5referstoHTML5,apivotaltechnologyinwebdevelopment.1)HTML5introducesnewelementsandAPIsforrich,dynamicwebapplications.2)Itsupportsmultimediawithoutplugins,enhancinguserexperienceacrossdevices.3)SemanticelementsimprovecontentstructureandSEO.4)H5'srespo

The tools and frameworks that need to be mastered in H5 development include Vue.js, React and Webpack. 1.Vue.js is suitable for building user interfaces and supports component development. 2.React optimizes page rendering through virtual DOM, suitable for complex applications. 3.Webpack is used for module packaging and optimize resource loading.

HTML5hassignificantlytransformedwebdevelopmentbyintroducingsemanticelements,enhancingmultimediasupport,andimprovingperformance.1)ItmadewebsitesmoreaccessibleandSEO-friendlywithsemanticelementslike,,and.2)HTML5introducednativeandtags,eliminatingthenee

H5 improves web page accessibility and SEO effects through semantic elements and ARIA attributes. 1. Use, etc. to organize the content structure and improve SEO. 2. ARIA attributes such as aria-label enhance accessibility, and assistive technology users can use web pages smoothly.

"h5" and "HTML5" are the same in most cases, but they may have different meanings in certain specific scenarios. 1. "HTML5" is a W3C-defined standard that contains new tags and APIs. 2. "h5" is usually the abbreviation of HTML5, but in mobile development, it may refer to a framework based on HTML5. Understanding these differences helps to use these terms accurately in your project.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

Atom editor mac version download
The most popular open source editor

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Zend Studio 13.0.1
Powerful PHP integrated development environment

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software