ios - 在 obj-c 中调用类方法时出错

标签 ios objective-c cordova cordova-plugins

我是 obj-c 新手,我正在尝试为 square connect lib 创建一个 Cordova 插件。

我正在尝试创建类 SCCAPIRequest 的实例. 但我收到错误:

 error: no known class method for selector
  'requestWithCallbackURL:amount:locationID:notes:metadata:supportedTenderTypes:error:'

这是我的功能

- (void)requestCharge: (CDVInvokedUrlCommand *)command {
int amount = [[command.arguments objectAtIndex: 0] intValue];
NSDictionary* options = [command.arguments objectAtIndex: 1];

CDVPluginResult *pluginResult;

if( amount < 0 || amount == 0) {
 NSLog(@"Error: Ammount to charge is 0");
 NSString *errorResponse = @"Error: Ammount to charge is 0";
 pluginResult = [CDVPluginResult 
 resultWithStatus:CDVCommandStatus_ERROR messageAsString:errorResponse];
}

[self setOptions:options];

NSError *error = nil;
SCCAPIRequest *request = [SCCAPIRequest requestWithCallbackURL:[NSURL 
URLWithString:yourCallbackURLString]
                                      amount:amount
                                locationID:self.locationID
                                      notes:self.note
                                    metadata:self.metadata
                              supportedTenderTypes:self.tenders
                                        error:&error];


NSData *response = [NSKeyedArchiver archivedDataWithRootObject:request];

if(error) {
  pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR 
  messageAsArrayBuffer:response];
} else {
 pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK 
  messageAsArrayBuffer:response];
}

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

提前致谢!

最佳答案

错误日志说明了您需要知道的一切。没有方法'requestWithCallbackURL:amount:locationID:notes:metadata:supportedTenderTypes:error:'。您正在调用 SCCAPIRequest 的不存在的 init 方法。

如果您要在其头文件中查看该类的 init 方法,特别是在此链接上:https://github.com/square/SquarePointOfSaleSDK-iOS/blob/master/Sources/SCCAPIRequest.h ,您将看到可以使用两种不同的 init 方法。

+ (nullable instancetype)requestWithCallbackURL:(nonnull NSURL *)callbackURL
                                         amount:(nonnull SCCMoney *)amount
                                 userInfoString:(nullable NSString *)userInfoString
                                     locationID:(nullable NSString *)locationID
                                          notes:(nullable NSString *)notes
                                     customerID:(nullable NSString*)customerID
                           supportedTenderTypes:(SCCAPIRequestTenderTypes)supportedTenderTypes
                              clearsDefaultFees:(BOOL)clearsDefaultFees
                returnAutomaticallyAfterPayment:(BOOL)autoreturn
                                          error:(out NSError *__nullable *__nullable)error;

+ (nullable instancetype)requestWithCallbackURL:(nonnull NSURL *)callbackURL
                                         amount:(nonnull SCCMoney *)amount
                                 userInfoString:(nullable NSString *)userInfoString
                                     merchantID:(nullable NSString *)merchantID
                                          notes:(nullable NSString *)notes
                                     customerID:(nullable NSString*)customerID
                           supportedTenderTypes:(SCCAPIRequestTenderTypes)supportedTenderTypes
                              clearsDefaultFees:(BOOL)clearsDefaultFees
                returnAutomaticallyAfterPayment:(BOOL)autoreturn
                                          error:(out NSError *__nullable *__nullable)error __deprecated_msg("Use requestWithCallbackURL:amount:userInfoString:locationID:notes:customerID:supportedTenderTypes:clearsDefaultFees:returnAutomaticallyAfterPayment:error: instead.");

因此,请使用其中之一来正确创建 SCCAPIRequest 实例。

关于ios - 在 obj-c 中调用类方法时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46572090/

相关文章:

objective-c - 长按 UI 元素(或如何确定按下的是哪个元素?)

ios - 如何从 Objective-C 调用 swift 泛型函数

javascript - Phonegap - 设备信息不工作

ios - iOS 非订阅应用的免费试用期

ios - xcode - 如何将 xcode 6 Storyboard文件降级为 xcode 5?

ios - Foundation 框架中未定义 CGFloat

android - phonegap resolveLocalFileSystemURL 不适用于 android 上的内容 uri

cordova - ionic API 和 ionic native API 之间的区别

ios - 我如何在我自己的 iOS 项目中使用 pjsip?

ios - 在多编辑模式下调整 UITableViewCell 分隔线