展示ShowAPI_SDK 0.1.4

ShowAPI.SDK 0.1.4

测试已测试
语言语言 Obj-CObjective C
许可证 MIT
发布上次发布2020年6月

bluedarker维护。



 
依赖项
AFNetworking/Serialization~> 3.2.1
AFNetworking/Security~> 3.2.1
AFNetworking/NSURLSession~> 3.2.1
AFNetworking/Reachability~> 3.2.1
 

  • 作者
  • bluedarker

showapi_sdk_ios

CI Status Version License Platform

示例

要运行测试示例项目,请克隆仓库,然后首先从示例目录运行pod install

然后在XCode中运行Tests/Tests.m

要求

安装

ShowAPI.SDK可以通过CocoaPods获得。要安装它,只需将以下行添加到您的Podfile中

use_frameworks!
pod "ShowAPI_SDK"

使用方法

首先需要导入“ShowAPI_SDK”

#import <ShowAPI_SDK/ShowAPIRequest.h>

普通方式请求ShowAPI数据,以下以全球IP归属地查询为例

//创建请求实例
//这里需要替换为你自己的appid和secret,你可以在这里找到 https://www.showapi.com/console#/myApp
ShowAPIRequest *request=[[ShowAPIRequest alloc] initWithAppid:@"appid" andSign:@"secret" ];

//调用全球IP归属地查询api
[request post:@"https://route.showapi.com/20-1"//IP归属地查询接入点的接口url,
timeout:20000//超时设置为20秒
params:[[NSDictionary<NSString*,NSString*> alloc] initWithObjectsAndKeys:@"116.4.201.181",@"ip", nil]//传入ip
withCompletion:^(NSDictionary<NSString *,id> *result) {
//打印返回结果

NSData *jsonData = [NSJSONSerialization dataWithJSONObject:result options:NSJSONWritingPrettyPrinted error:nil];
// NSData转为NSString
NSString *jsonStr = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];

NSLog(@"返回结果为:%@",jsonStr);


}];

带上传文件方式请求ShowAPI数据,以下以二维码识别为例

//文件需要换为你自己的测试文件
NSURL *filePath = [[NSBundle mainBundle] URLForResource:@"showapi" withExtension:@"jpg"];
NSData *imgData = [[NSData alloc] initWithContentsOfURL:filePath];
//    NSLog(@"img is:%@",imgData);


//创建请求实例
//这里需要替换为你自己的appid和secret,你可以在这里找到 https://www.showapi.com/console#/myApp
ShowAPIRequest *request=[[ShowAPIRequest alloc] initWithAppid:@"appid" andSign:@"secret" ];

//验证码识别api
[request post:@"https://route.showapi.com/887-2"//二维码识别接口地址
timeout:20000//超时设置为20秒
params:[[NSDictionary<NSString*,NSString*> alloc] initWithObjectsAndKeys:@"1",@"handleImg", nil] //普通传入参数
fileParams:[[NSDictionary<NSString*,NSData*> alloc] initWithObjectsAndKeys:imgData,@"img", nil] //文件参数
withCompletion:^(NSDictionary<NSString *,id> *result) {
//打印返回结果

NSData *jsonData = [NSJSONSerialization dataWithJSONObject:result options:NSJSONWritingPrettyPrinted error:nil];
// NSData转为NSString
NSString *jsonStr = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];

NSLog(@"返回结果为:%@",jsonStr);

} ];

上传文件使用base64编码文件POST请求ShowAPI数据,以下以二维码识别为例

//文件需要换为你自己的测试文件
NSURL *filePath = [[NSBundle mainBundle] URLForResource:@"showapi" withExtension:@"jpg"];
NSData *imgData = [[NSData alloc] initWithContentsOfURL:filePath];
//    NSLog(@"img is:%@",imgData);

//base64编码文件为base64字符串
NSString *encodedImageStr = [imgData base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithCarriageReturn];

//创建请求实例
//这里需要替换为你自己的appid和secret,你可以在这里找到 https://www.showapi.com/console#/myApp
ShowAPIRequest *request=[[ShowAPIRequest alloc] initWithAppid:@"appid" andSign:@"secret" ];

//验证码识别api
[request post:@"https://route.showapi.com/887-4"//二维码识别接口地址
timeout:20000//超时设置为20秒
params:[[NSDictionary<NSString*,NSString*> alloc] initWithObjectsAndKeys:@"1",@"handleImg",encodedImageStr,@"imgData", nil] //普通传入参数
withCompletion:^(NSDictionary<NSString *,id> *result) {
//打印返回结果

NSData *jsonData = [NSJSONSerialization dataWithJSONObject:result options:NSJSONWritingPrettyPrinted error:nil];
// NSData转为NSString
NSString *jsonStr = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];

NSLog(@"返回结果为:%@",jsonStr);

} ];

作者

bluespring, [email protected]

许可证

ShowAPI_SDK 在MIT许可下可用。有关更多信息,请参阅LICENSE文件。