初始化接口
SDK自动初始化接口
结合配置文件(AliyunEmasServices-Info.plist)使用,无需配置appKey和appSecret。
接口定义
- (instancetype)autoInit;
SDK初始化接口
此方法会初始化为单实例。
接口定义
- (instancetype)initWithAccountID:(int)accountID;
参数说明
参数 | 类型 | 是否必填 | 说明 |
accountId | int | 是 | 系统分配的Account ID,当您开通HTTPDNS后,您可以在控制台获取到您对应的Account ID信息。 |
SDK启用鉴权功能的初始化接口
初始化并开启鉴权功能。
接口定义
- (instancetype)initWithAccountID:(int)accountID secretKey:(NSString *)secretKey;
参数说明
参数 | 类型 | 是否必填 | 说明 |
accountId | int | 是 | 系统分配的Account ID,当您开通HTTPDNS后,您可以在控制台获取到您对应的Account ID信息。 |
secretKey | NSString | 是 | 鉴权对应的secretKey。 |
校正App签名时间
进行该操作后,如果有偏差,每次网络请求都会对设备进行时间校正;不进行该操作的话将以设备时间为准。
重要
使用场景:有可能手机上的时间不太准确。
校正操作在App的一个生命周期内生效,App重启后需要重新设置才能重新生效,可以重复设置。
您需要一个时间服务,可以自建,简单的时间戳接口就可以,请求这个时间服务返回正确的时间,然后将时间填入本接口,SDK就能知道和正确时间差了多少。
接口定义
- (void)setAuthCurrentTime:(NSUInteger)authCurrentTime;
参数说明
参数 | 类型 | 是否必填 | 说明 |
authCurrentTime | NSUInteger | 是 | 用于校正的时间戳。 |
HTTPDNS服务实例化接口
HTTPDNS服务实例化接口。
接口定义
+ (instancetype)sharedInstance;
自定义TTL时长
接口定义
@protocol HttpdnsTTLDelegate <NSObject>
/// 自定义HOST的TTL时长
/// @return 返回需要自定义的TTL时长
/// @param host 域名
/// @param ipType 当前查询的IP类型
/// @param ttl 当次域名解析返回的TTL
- (int64_t)httpdnsHost:(NSString *)host ipType:(AlicloudHttpDNS_IPType)ipType ttl:(int64_t)ttl;
@end
代码示例
@interface AppDelegate ()< HttpDNSDegradationDelegate, HttpdnsTTLDelegate >
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[HttpDnsService sharedInstance] setTestLogHannder:[HelpTestLog shareInstance]];
//传入对应的accountID
HttpDnsService *httpdns = [[HttpDnsService alloc] initWithAccountID:xxx];
httpdns.ttlDelegate = self;
return YES;
}