Привязка Xamarin.iOS для WePay

Я создаю привязку Xamarin для WePay.iOS SDK, используя объективный маркер. https://github.com/wepay/wepay-ios

Мне удалось создать файлы APIDefinition.cs и StructsAndEnums.cs. Однако, когда я создал проект привязки, он не компилируется успешно.

[Export ("initWithSwipedInfo:")]
    IntPtr Constructor (NSObject swipedInfo);

    // -(instancetype)initWithEMVInfo:(id)emvInfo;
    [Export ("initWithEMVInfo:")]
    IntPtr Constructor (NSObject emvInfo);

Я понимаю, что мне нужно изменить NSOBject на правильный тип данных. Однако, когда я просматриваю файл Objective C. Я не могу понять, какой тип данных я должен использовать. Я ценю, если кто-то может направить меня в этом.

Класс Objective-C

@interface WPPaymentInfo : NSObject
@property (nonatomic, strong, readonly) NSString *firstName;
@property (nonatomic, strong, readonly) NSString *lastName;
@property (nonatomic, strong, readonly) NSString *email;
@property (nonatomic, strong, readonly) NSString *paymentDescription;
@property (nonatomic, readonly) BOOL isVirtualTerminal;
@property (nonatomic, strong, readonly) WPAddress *billingAddress;
@property (nonatomic, strong, readonly) WPAddress *shippingAddress;
@property (nonatomic, strong, readonly) id paymentMethod;
@property (nonatomic, strong, readonly) id swiperInfo;
@property (nonatomic, strong, readonly) id manualInfo;
@property (nonatomic, strong, readonly) id emvInfo;

- (instancetype) initWithSwipedInfo:(id)swipedInfo;
- (instancetype) initWithEMVInfo:(id)emvInfo;
- (instancetype) initWithFirstName:(NSString *)firstName
                      lastName:(NSString *)lastName
                         email:(NSString *)email
                billingAddress:(WPAddress *)billingAddress
               shippingAddress:(WPAddress *)shippingAddress
                    cardNumber:(NSString *)cardNumber
                           cvv:(NSString *)cvv
                      expMonth:(NSString *)expMonth
                       expYear:(NSString *)expYear
               virtualTerminal:(BOOL)virtualTerminal;

- (void) addEmail:(NSString *)email;
@end

person Libin Joseph    schedule 19.05.2016    source источник


Ответы (2)


swipedInfo и emvInfo имеют внутренний тип NSMutableDictionary.

См. здесь:

- (void) handleSwipeResponse:(NSDictionary *) responseData 
{
    NSDictionary *info = @{@"firstName"         : [WPRoamHelper firstNameFromRUAData:responseData],
                           @"lastName"          : [WPRoamHelper lastNameFromRUAData:responseData],
                           @"paymentDescription": pan ? pan : @"",
                           @"swiperInfo"        : responseData
                        };

    WPPaymentInfo *paymentInfo = [[WPPaymentInfo alloc] initWithSwipedInfo:info]; 
}
person y2chaits    schedule 19.05.2016
comment
Но как мы можем иметь один и тот же тип данных с одинаковым количеством параметров. Это даст ошибку сборки, верно? - person Libin Joseph; 19.05.2016
comment
@LibinJoseph Я не знаю, как работает Xamarin, но на стороне iOS сигнатуры методов разные. - person y2chaits; 19.05.2016

@y2chaits Xamarin работает поверх Mono и это C#. C# не допускает перегрузки с одной и той же сигнатурой. Итак, лучше вместо этого создать конкретный тип данных. Вы думали так же, когда меняли WPAddress.

В этом случае вы можете установить один конструктор в NSObject, а второй в NSDictionary (см. здесь: https://github.com/dikoga/WePayBinding/blob/master/WePayBinding/ApiDefinition.cs). И тебе будет хорошо.

Однако эта привязка уже сделана. Он создается, но есть одна проблема (http://forums.xamarin.com/discussion/66446/how-to-get-more-information-when-the-app-crashes). Может быть, вы можете приложить некоторые усилия, чтобы заставить его работать, поскольку он уже есть на github.

person Diego Koga    schedule 02.06.2016