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

时间:2017-10-04 18:47:59

标签: ios objective-c cordova cordova-plugins

我是obj-c的新手,我正在尝试为方形连接库创建一个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];
}

提前致谢!

1 个答案:

答案 0 :(得分:1)

错误日志说明您需要知道的全部内容。没有方法'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的实例。