我是 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/