2

strong text我正在 Xamarin 中实现 iZettle 支付 SDK。我创建了绑定库并将所有头文件转换为 ApiDefintions。我坚持遵守 Xamarin 中的 iZettleSDKAuthorizationProvider 协议。

这是我的 APIDefinition.cs 文件代码;

[BaseType(typeof(NSObject))]
[Model, Protocol]
interface iZettleSDKAuthorizationProvider
{
    // @required -(void)authorizeAccountWithCompletion:(void (^ _Nonnull)(iZettleSDKOAuthToken * _Nullable, NSError * _Nullable))completion;
    [Abstract]
    [Export("authorizeAccountWithCompletion:")]
    void AuthorizeAccountWithCompletion(Action<iZettleSDKOAuthToken, NSError> completion);

    // @required -(void)verifyAccountWithUuid:(NSUUID * _Nonnull)uuid completion:(void (^ _Nonnull)(iZettleSDKOAuthToken * _Nullable, NSError * _Nullable))completion;
    [Abstract]
    [Export("verifyAccountWithUuid:completion:")]
    void VerifyAccountWithUuid(NSUuid uuid, Action<iZettleSDKOAuthToken, NSError> completion);
}

// @interface iZettleSDKAuthorization : NSObject <iZettleSDKAuthorizationProvider>
[BaseType(typeof(NSObject), Name = "_TtC10iZettleSDK23iZettleSDKAuthorization")]
[DisableDefaultCtor]
interface iZettleSDKAuthorization : IiZettleSDKAuthorizationProvider
{
    // -(instancetype _Nullable)initWithClientID:(NSString * _Nonnull)clientID callbackURL:(NSURL * _Nonnull)callbackURL error:(NSError * _Nullable * _Nullable)error enforcedUserAccount:(NSString * _Nullable (^ _Nonnull)(void))enforcedUserAccount __attribute__((objc_designated_initializer));
    [Export("initWithClientID:callbackURL:error:enforcedUserAccount:")]
    [DesignatedInitializer]
    IntPtr Constructor(string clientID, NSUrl callbackURL, [NullAllowed] out NSError error, Func<NSString> enforcedUserAccount);
}

简而言之,我希望 Xamarin ios 等效于以下代码;

 id<iZettleSDKAuthorizationProvider> authorizationProvider = [[iZettleSDKAuthorization alloc]
                           initWithClientID:clientId
                           callbackURL:[NSURL URLWithString:callbackURL]
                           error:&error
                           enforcedUserAccount:^NSString * _Nullable{
    return [AccountManager shared].enforcedUserAccount;
}];

如此处所示。所以任何人都可以帮助我,那就太好了。

4

0 回答 0