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!

A reasonable H5 code structure allows the page to stand out among a lot of content. 1) Use semantic labels such as, etc. to organize content to make the structure clear. 2) Control the rendering effect of pages on different devices through CSS layout such as Flexbox or Grid. 3) Implement responsive design to ensure that the page adapts to different screen sizes.

The main differences between HTML5 (H5) and older versions of HTML include: 1) H5 introduces semantic tags, 2) supports multimedia content, and 3) provides offline storage functions. H5 enhances the functionality and expressiveness of web pages through new tags and APIs, such as and tags, improving user experience and SEO effects, but need to pay attention to compatibility issues.

The difference between H5 and HTML5 is: 1) HTML5 is a web page standard that defines structure and content; 2) H5 is a mobile web application based on HTML5, suitable for rapid development and marketing.

The core features of HTML5 include semantic tags, multimedia support, form enhancement, offline storage and local storage. 1. Semantic tags such as, improve code readability and SEO effect. 2. Multimedia support simplifies the process of embedding media content through and tags. 3. Form Enhancement introduces new input types and verification properties, simplifying form development. 4. Offline storage and local storage improve web page performance and user experience through ApplicationCache and localStorage.

HTML5isamajorrevisionoftheHTMLstandardthatrevolutionizeswebdevelopmentbyintroducingnewsemanticelementsandcapabilities.1)ItenhancescodereadabilityandSEOwithelementslike,,,and.2)HTML5enablesricher,interactiveexperienceswithoutplugins,allowingdirectembe

Advanced tips for H5 include: 1. Use complex graphics to draw, 2. Use WebWorkers to improve performance, 3. Enhance user experience through WebStorage, 4. Implement responsive design, 5. Use WebRTC to achieve real-time communication, 6. Perform performance optimization and best practices. These tips help developers build more dynamic, interactive and efficient web applications.

H5 (HTML5) will improve web content and design through new elements and APIs. 1) H5 enhances semantic tagging and multimedia support. 2) It introduces Canvas and SVG, enriching web design. 3) H5 works by extending HTML functionality through new tags and APIs. 4) Basic usage includes creating graphics using it, and advanced usage involves WebStorageAPI. 5) Developers need to pay attention to browser compatibility and performance optimization.

H5 brings a number of new functions and capabilities, greatly improving the interactivity and development efficiency of web pages. 1. Semantic tags such as enhance SEO. 2. Multimedia support simplifies audio and video playback through and tags. 3. Canvas drawing provides dynamic graphics drawing tools. 4. Local storage simplifies data storage through localStorage and sessionStorage. 5. The geolocation API facilitates the development of location-based services.


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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

SublimeText3 Linux new version
SublimeText3 Linux latest version

Dreamweaver Mac version
Visual web development tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.
