Phonegap for iOS plug-in development

Source: Internet
Author: User

1. Create a phonegap project myplugin

Environment

Xcode4.5.1

Phonegap2.1.0

2. Create an implementation in subclass under the plugin folder

////  MyPlugin.h//  MyPGPlugin////  Created by kllmctrl on 12-10-29.////#import <Cordova/CDV.h>@interface MyPlugin : CDVPlugin- (void) add:(CDVInvokedUrlCommand*)command;@end

# Import "myplugin. H "# import <Cordova/CDV. h> @ implementation myplugin-(void) add :( cdvinvokedurlcommand *) command {cdvpluginresult * pluginresult = nil; nsstring * JavaScript = nil; @ try {nsstring * echo = [command. arguments objectatindex: 0]; nsstring * echo2 = [command. arguments objectatindex: 1]; If (echo! = Nil & [Echo length]> 0 & echo2! = Nil & [echo2 length]> 0) {/*** add string */nsstring * addresult = [nsstring stringwithformat: @ "% @", Echo, echo2]; pluginresult = [cdvpluginresult resultwithstatus: cdvcommandstatus_ OK messageasstring: addresult]; JavaScript = [pluginresult tosuccesscallbackstring: Command. callbackid];} else {pluginresult = [cdvpluginresult resultwithstatus: cdvcommandstatus_error]; JavaScript = [pluginresult toerrorcallbackstring: Command. callbackid] ;}}@ catch (nsexception * exception) {pluginresult = [cdvpluginresult resultwithstatus: Invalid messageasstring: [Exception reason]; JavaScript = [pluginresult toerrorcallbackstring: Command. callbackid];} [self writejavascript: javascript];} @ end

3. create and implement myplugin. js under the WWW-> JS folder

var MyPlugin = {add: function(args,args2,addSuc,addFaild) {    cordova.exec(addSuc, addFaild, "MyPlugin", "add", [args,args2]);}};

4.modify index.html

<! Doctype HTML> <! -- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. see the notice file distributed with this work for additional information regarding copyright ownership. the ASF licenses this file to you under the Apache license, version 2.0 (the "License"); you may not use this file license t in compliance with the license. you may obtain a copy of the license athttp: // your unless required by applicable law or agreed to in writing, software distributed under the license is distributed on an "as is" basis, without warranties or conditions of any kind, either express or implied. see the license for the specific language governing permissions and limitations under the license. --> <HTML> 

5. Configure Cordova. plist

Create myplugin = myplugin in plugins

6. Run

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.