PhoneGap日历插件iOS无响应

时间:2014-07-01 18:12:47

标签: javascript ios cordova calendar

<div class="jumbotron">
    <h1>Set Up Appointment</h1>

    <form action="" id="input" method="get" name="input">
        document.addEventListener('deviceready', function(){ var cal; cal =
        window.plugins.calendarPlugin; $('#submit').click(function() { function
        createEvent(title,location,notes, startDate, endDate){ var title =
        document.getElementById=("name"); var notes =
        document.getElementById=("location"); var startDate =
        document.getElementById=("startDate"); var endDate =
        document.getElementById=("endDate");
        cal.createEvent(title,location,notes,startDate,endDate); } }); },
        false);<a href="https://www.nycm.com/Default.asp" target=
        "blank"><img src=
        "http://www.nycm.com/apcd/images/LogoTitle.gif"></a><br>

        <div class="inputTable" style="width:300px">
            <table>
                <tr>
                    <td>Name</td>

                    <td><input id="name" type="text"></td>
                </tr>

                <tr>
                    <td>Location</td>

                    <td><input id="location" type="text"></td>
                </tr>

                <tr>
                    <td>Start Date</td>

                    <td><input id="startDate" type="date"></td>
                </tr>

                <tr>
                    <td>End Date</td>

                    <td><input id="endDate" type="date"></td>
                </tr>

                <tr>
                    <td>Additional Info</td>

                    <td><input id="notes" type="text"></td>
                </tr>
            </table>

            <div class="submitButton">
                <input id="submit" type="submit" value="Submit">
            </div>
        </div><br>
    </form>
</div>

它接受了输入,但它没有在手机上的原生日历中发生事件。

我使用X代码通过Mac上的PhoneGap构建来运行它。

我真的只需要知道如何使用PhoneGap将javascript连接到iOS上的本机日历。

任何帮助都会很棒。

1 个答案:

答案 0 :(得分:0)

尝试这个。

确保您已在config.xml中定义插件

<feature name="CustomPlugin">
      <param name="ios-package" value="CustomPlugin" />
</feature>

使用Objective-C代码实现插件

CustomPlugin.h

#import <Foundation/Foundation.h>
#import <Cordova/CDV.h>

@interface CustomPlugin : CDVPlugin

- (void)sayHello:(CDVInvokedUrlCommand*)command;

@end

CustomPlugin.m

#import "CustomPlugin.h"

    @implementation CustomPlugin

    - (void)sayHello:(CDVInvokedUrlCommand*)command{

        NSString *responseString =
            [NSString stringWithFormat:@"Hello World, %@", [command.arguments objectAtIndex:0]];

        CDVPluginResult *pluginResult =
            [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:responseString];

        [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
    }

    @end

从JavaScript调用插件

function initial(){
    var name = $("#NameInput").val();
    cordova.exec(sayHelloSuccess, sayHelloFailure, "CustomPlugin", "sayHello", [name]);
}

function sayHelloSuccess(data){
    alert("OK: " + data);
}

function sayHelloFailure(data){
    alert("FAIL: " + data);
}