1. Create a project
Open the terminal, switch to the desktop, and then use ' ionic ' to create a test project named Counttest.
CD./desktop/
sudo ionic start Countdemo
Or
Use Cordova, but late Cordova do not know how to boot ionic, if you know please leave a message to tell me, thank you! sudo Cordova create Countdemo Com.twenty.CountDemo Countdemo
1: Project creation to the desktop directory name,
The name of the 2:ios Bundle identifier,
3: Project name if you go to 2, 3 steps, the IOS Bundle ID will be created by itself, and the project name in 3 is the directory name in the default 1.
The items we create do not have writable permissions , only readable permissions , because the Modify Counttest permission is readable and writable .
This allows you to modify Counttest files and sub-files.
2. Compiling iOS Project Project
Compile the ' iOS Project structure ' directory platform by using ' ionic '. The command is as follows:
Add platforms for iOS projects
sudo ionic platform add iOS
or sudo Cordova platform add iOS
Output is added successfully
Wait a few minutes
Compiling iOS projects
sudo ionic build iOS
or sudo Cordova build iOS
If ' * * BUILD succeeded ' succeeds, you can see the file ' platform ' add an iOS platform folder.
Use the official Apple development tool ' Xcode ' to open if you do not have permission to modify permissions using the command:
sudo chmod-r 777.
`. Represents the current folder ',
Open the post structure as follows
Our custom plugins are in the ' Plugins ' folder.
3. Plugin Development
Create a ' Countadd ' object that inherits the ' Cdvplugin ' object.
PS: ' Cdvplugin ' is the connection object for the Cordova library.
' Command + B ' compile Xcode, program error ' ' cordova/cordova.h ' File not found '
By looking at the contents of the ' cordovalib ' library file, the header file ' CDV.h ' in this library contains all the class header files and is therefore modified as follows:
The compilation succeeds again.
In the CountAdd.h file, declare a method: Calculate the size. The ' Cdvinvokedurlcommand * ' object is a parameter that is passed automatically when the URL command is called. Implement this method in ' COUNTADD.M ' .
In ' countadd.m ' , we add the following code:
1: Gets the unique ID of the command to invoke;
2: Get the first index value of the passed array; (subsequent detailed explanation)
3: The number given to get +1;
5: Set the status by judging the result of the plugin, the value passed by the success status message, the value passed by the failed status message;
6: Send the result of the plugin to the corresponding ID by invoking the proxy
4. Configuration
By using Webstorm to open the ' Countdemo ' project you created, we create our own plugin directory ' Com.twenty.CountTest ' in the project ' Plugins ' folder , the structure is as follows:
iOS: Store the Countadd class that Xcode just created,
www: js file that is called and Countadd is stored
Plugin.xml: Configure the contents of iOS and Cordova. Copy ' OC class ' to ' iOS folder ' directory, ' www ' directory to create a JS file like ' OC class name '
The contents of the ' plugin.xml ' file are as follows:
The name in the box must be consistent, the names are arbitrary;
The value in the circle is consistent with the class name of the Cdvplugin class that inherits from the OC;
The horizontal line part name must match the JS name
Wen/springer (author of Jane's book)
Original link: HTTP://WWW.JIANSHU.COM/P/10CCA2464FCF
Copyright belongs to the author, please contact the author to obtain authorization, and Mark "book author".
iOS uses object-c custom Cordova plugin (-)