我有散列數據的方法將被髮送到我的API的請求。我用這樣的:
window.plugins.protocol.hamac data, (results) =>
# work with results
本機代碼看起來是這樣的:
- (void)hamac:(CDVInvokedUrlCommand*)command {
NSLog(@"HAMAC STARTED!");
CDVPluginResult* pluginResult = nil;
@try {
NSDictionary* data = [command.arguments objectAtIndex:0];
if (data != nil) {
// prepare string to be hashed
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary: @{
@"status": @YES,
@"h": [self sha1:[NSString stringWithFormat:@"%@", stringToHash]
}];
} else {
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary: @{
@"status": @NO,
@"error": @"No data!"
}];
}
} @catch (NSException* e) {
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary: @{
@"status": @NO,
@"error": @"Failed to hash data"
}];
}
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}
你確定你正在使用的插件「deviceready」被觸發後? –
是的,我的整個應用程序啓動後,deviceready事件被觸發。 –
你能不能請示一些代碼?喜歡你如何使用你的插件? –