Xamarin iOS私有API使用

use*_*863 2 iphone-privateapi xamarin.ios nsurlrequest ios xamarin

我想实现我在iOS私有API Xamarin的项目.

有人可以解释一下,我如何在Xamarin中实现以下私有API?

我想,我需要建立一个绑定的项目,但我不能得到它的工作.

在我的本机iOS项目中运行时,以下代码有效.

我的.h文件:

#import <Foundation/Foundation.h>

@interface NSURLRequest (IgnoreSSL)

+ (BOOL)allowsAnyHTTPSCertificateForHost:(NSString*)host;

@end
Run Code Online (Sandbox Code Playgroud)

我的.m文件:

#import "NSURLRequest+IgnoreSSL.h"

@interface NSURLRequest ()
@end

@implementation NSURLRequest (IgnoreSSL)

+ (BOOL)allowsAnyHTTPSCertificateForHost:(NSString*)host
{
    // ignore certificate errors only for this domain
    return YES;
}

@end
Run Code Online (Sandbox Code Playgroud)

mig*_*aza 5

你可以做的是在Objective-C中创建一个小型库,它只执行你在那里做的事情(覆盖NSURLRequest中的静态方法)并将其与你的应用程序链接.

或者,如果您想使用纯C#执行此操作,您可以尝试创建NSUrlRequest的子类,然后添加如下代码:

class MyUrlRequest : NSUrlRequest {
    // Provide any constructors that you need

    [Export ("allowsAnyHTTPSCertificateForHost:")]
    static bool Allow (string host) { return true; }
}
Run Code Online (Sandbox Code Playgroud)

然后创建MyUrlRequest的实例而不是NSUrlRequest.