【问题标题】:calling javascript event strings in to native iOS calendar iPHone将 javascript 事件字符串调用到原生 iOS 日历 iPHone
【发布时间】:2014-03-06 09:40:09
【问题描述】:

我们已经在 phonegap 环境中开发了 iPhone 应用程序。我想在 Objective-C Xcode 中调用下面的 javascritpt 函数来在原生 iOS 日历中创建一个事件。

//calendar.js

var calendarPlugin = {
createEvent: function(title, location, notes, startDate, endDate, successCallback, errorCallback) {
    cordova.exec(
        successCallback, // success callback function
        errorCallback, // error callback function
        'CalendarPlugin', // mapped to our native Java class called "CalendarPlugin"
        'addCalendarEntry', // with this action name
        [{                  // and this array of custom arguments to create our entry
            "title": title,
            "description": notes,
            "eventLocation": location,
            "startTimeMillis": startDate.getTime(),
            "endTimeMillis": endDate.getTime()
        }]
    ); 
 }

}

我有Objective C中日历事件的基本代码,我只需要将字符串值从javascript传递给这个日历事件Obj-c方法。在下面的 webview 方法中写什么

 - (BOOL)webView:(UIWebView*)theWebView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType

【问题讨论】:

标签: javascript objective-c cordova


【解决方案1】:

我不确定日历部分,但这个可以帮助你。

确保您已经在 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);
}

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多