SDK接入
Last updated
2023-07-10 18:19:32
{"value":"##SDK\u63a5\u5165\n\n####1.Android \u63a5\u5165\n\n##### \u6dfb\u52a0SDK\u81f3Android\u5de5\u7a0b\n\nKiwi\u63d0\u4f9b\u7684Andoid sdk\u4e3aKiwi.aar\uff0c\u5305\u542barmeabi-v7a\u3001arm64-v8a\u3001x86\u4e09\u79cdarch\u3002 \u4ee5Android Studio\u4e3a\u4f8b\uff0c\u63a8\u8350\u5c06Kiwi.aar\u590d\u5236\u5230libs\u76ee\u5f55\uff0c\u53c2\u8003[\u8fd9\u91cc](https:\/\/blog.csdn.net\/fengyulinde\/article\/details\/79989813) \u9002\u5f53\u6dfb\u52a0\u4ee5\u4e0b\u5185\u5bb9\u81f3\u5de5\u7a0b\u7684build.gradle\u4e2d\n![](https:\/\/tp2lravq.hk03.1112oss.com\/20230710180537wmvr8gutc0res3u0b00ar6ojcqmfpb71.png)\n##### \u5f15\u5165\u5305\n![](https:\/\/tp2lravq.hk03.1112oss.com\/20230710180704b21i62721e72g6sh4ebn40h2bnt5igc5.png)\n##### \u8c03\u7528\u521d\u59cb\u5316\u63a5\u53e3\n\n```java\n\/**\n * @breif \u8f6c\u5316\u63a5\u53e3\uff0c\u5c06rs\u6807\u8bc6\u8f6c\u6362\u4e3a\u672c\u5730\u8bbf\u95ee\u3002\u4e0d\u4f1a\u8bbf\u95ee\u7f51\u7edc\uff0c\u4e0d\u4f1a\u5361\u987f\n * @param name \u63a7\u5236\u53f0\u914d\u7f6e\u7684\u9632\u62a4\u76ee\u6807rs\u6807\u8bc6\n * @param ip \u8f6c\u6362\u540e\u7684ip\n * @param port \u8f6c\u6362\u540e\u7684\u7aef\u53e3\n * @return 0\u8868\u793a\u6210\u529f\uff0c\u975e0\u8868\u793a\u5931\u8d25\uff0c\u8bf7\u54a8\u8be2Kiwi\u5f00\u53d1\u4eba\u5458\n *\/\npublic static int ServerToLocal(String name, StringBuffer ip, StringBuffer port);\n```\n\u8c03\u7528\u4ee3\u7801\u793a\u4f8b\uff1a\n![](https:\/\/tp2lravq.hk03.1112oss.com\/20230710181545a3ndklosw44rsg73e24eu1fs04c4qfud.png)\n[\u4ee3\u7801\u6df7\u6dc6\n\n\u6ce8\u610f\uff1a\u5982\u679c\u4f7f\u7528 proguard \u8fdb\u884c\u6df7\u6dc6\u4ee3\u7801\uff0c\u9700\u8981\u5728 `proguard-rules.pro` \u6587\u4ef6\u4e2d\u65b0\u589e\u4e00\u884c `-keep class com.kiwi.sdk.**{*;}`\n#### 2.iOS \u63a5\u5165\n\n##### \u6dfb\u52a0SDK\u81f3iOS\u5de5\u7a0b\n\nKiwi\u63d0\u4f9b\u7684iOS sdk\u4e3aKiwi.framework\uff0c\u5305\u542barm64, x86_64\u4e24\u79cdarch\u3002\n\n- \u9009\u4e2d\u9879\u76ee\u540d\u79f0\n- \u9009\u4e2dTARGETS\n- \u5207\u6362\u5230General\n- \u4e0b\u62c9\u627e\u5230 `Frameworks, Libraries, and Embeded Content`\n- \u70b9\u51fb\u201c+\u201d\u53f7\uff0c\u70b9\u51fb `And Other... -> And File...`\uff0c\u9009\u62e9 Kiwi.framework \u6587\u4ef6\n- Embed \u9009\u62e9 `Do Not Embed`\n\n##### \u5f15\u5165\u5934\u6587\u4ef6\n\n```objectivec\n#import <Kiwi\/Kiwi.h>\n```\n\n##### \u8c03\u7528\u521d\u59cb\u5316\u63a5\u53e3\n\n```objectivec\n\/**\n * @breif \u521d\u59cb\u5316\u63a5\u53e3\uff0c\u4e0d\u9700\u8981\u91cd\u590d\u8c03\u7528\u63a5\u53e3\u3002\u4f1a\u8bbf\u95ee\u7f51\u7edc\uff0c\u4e0d\u8981\u653e\u5728UI\u7ebf\u7a0b\u4e2d\n * @param appkey \u63a7\u5236\u53f0\u83b7\u53d6\u7684appkey\n * @return 0\u8868\u793a\u6210\u529f\uff0c\u975e0\u8868\u793a\u5931\u8d25\uff0c\u8bf7\u54a8\u8be2Kiwi\u5f00\u53d1\u4eba\u5458\n *\/\n+(int) Init:(const char *)appkey;\n```\n\n\u8c03\u7528\u4ee3\u7801\u793a\u4f8b\uff1a\n\n```objectivec\n\/\/ \u8bf7\u66ff\u6362\u771f\u5b9eappkey\nconst char *appkey = \"P8+LRKkfH6m59+x\/WBk+8l74OmBMSRdK7rYg+FaS\/74=\";\nint ret = [Kiwi Init:appkey];\nNSLog(@\"Kiwi Init return %d\", ret);\n```\n\n##### \u8c03\u7528\u8f6c\u5316\u63a5\u53e3\n\n```objectivec\n\/**\n * @breif \u8f6c\u5316\u63a5\u53e3\uff0c\u5c06rs\u6807\u8bc6\u8f6c\u6362\u4e3a\u672c\u5730\u8bbf\u95ee\u3002\u4e0d\u4f1a\u8bbf\u95ee\u7f51\u7edc\uff0c\u4e0d\u4f1a\u5361\u987f\n * @param name \u63a7\u5236\u53f0\u914d\u7f6e\u7684\u9632\u62a4\u76ee\u6807rs\u6807\u8bc6\n * @param ip \u8f6c\u6362\u540e\u7684ip\u7f13\u51b2\u533a\u6307\u9488\n * @param ip_len \u8f6c\u6362\u540e\u7684ip\u7f13\u51b2\u533a\u957f\u5ea6\n * @param port \u8f6c\u6362\u540e\u7684\u7aef\u53e3\u7f13\u51b2\u533a\u6307\u9488\n * @param port_len \u8f6c\u6362\u540e\u7684\u7aef\u53e3\u7f13\u51b2\u533a\u957f\u5ea6\n * @return 0\u8868\u793a\u6210\u529f\uff0c\u975e0\u8868\u793a\u5931\u8d25\uff0c\u8bf7\u54a8\u8be2Kiwi\u5f00\u53d1\u4eba\u5458\n *\/\n+(int) ServerToLocal:(const char*)name :(char*)ip :(int)ip_len :(char*)port :(int)port_len;\n```\n\n\u8c03\u7528\u4ee3\u7801\u793a\u4f8b\uff1a\n\n```objectivec\nchar ip[40] = {0};\nchar port[40] = {0};\n\n\/\/ \u8bf7\u66ff\u6362\u771f\u5b9ers\u6807\u8bc6\nconst char *name = \"echo\";\nint ret = [Kiwi ServerToLocal:name :ip :sizeof(ip) :port :sizeof(port)];\nNSLog(@\"L4 ServerToLocal return %d\", ret);\nif (ret != 0) {\n return;\n}\n \nNSString* url = [NSString stringWithFormat:@\"http:\/\/%s:%s\/index.html\", ip, port];\n\/\/ \u8bbf\u95eeurl ...\n```\n\n#### 3.Windows \u63a5\u5165\n##### \u6dfb\u52a0SDK\u81f3Windows\u5de5\u7a0b\n\nKiwi\u63d0\u4f9b\u7684SDK\u4e3a\u52a8\u6001\u5e93\uff0c\u5305\u542bKiwi.dll\u3001Kiwi.h\u3001Kiwi.lib\u4e09\u90e8\u5206\u3002\n\n- \u5c06Kiwi.h\u653e\u5165\u5de5\u7a0b\u7684\u5934\u6587\u4ef6\u76ee\u5f55\u4e2d\n- \u6253\u5f00\u5de5\u7a0b->\u5c5e\u6027->\u94fe\u63a5\u5668->\u8f93\u5165->\u9644\u52a0\u4f9d\u8d56\u9879\uff0c\u6dfb\u52a0Kiwi.lib\uff0c\u6ce8\u610fDebug\u548cRelease\u914d\u7f6e\u90fd\u9700\u8981\u8bbe\u7f6e\n- \u7f16\u8bd1\u5b8c\u6210\u540e\uff0c\u5c06Kiwi.dll\u4e0e\u5de5\u7a0b\u751f\u6210\u7684exe\u653e\u5230\u540c\u4e00\u76ee\u5f55\u8fd0\u884c\n\n##### \u8c03\u7528\u4ee3\u7801\u793a\u4f8b\n\n```cpp\n#include <stdio.h>\n\n#include \"Kiwi.h\"\n\nint main() {\n char appkey[] = \"Your appkey\";\n char target[] = \"Your target\";\n\n char ip[64] = {0};\n char port[16] = {0};\n\n int ret = KiwiInit(appkey);\n if (ret != 0) {\n printf(\"KiwiInit failed %d\\n\", ret);\n return ret;\n }\n\n ret = KiwiServerToLocal(target, ip, sizeof(ip), port, sizeof(port));\n if (ret != 0) {\n printf(\"KiwiServerToLocal failed %d\\n\", ret);\n return ret;\n }\n\n printf(\"KiwiServerToLocal success %s %s\\n\", ip, port);\n getchar();\n\n return 0;\n}\n```\n\n#### 4.\u9644\u5f55\n##### Kiwi\u63a5\u53e3\u9519\u8bef\u7801\n\n```cpp\nenum KiwiStatus\n{\n KiwiOK = 0,\n KiwiParam = -1,\n kiwiAppkey = -2,\n KiwiApiRequestFailed = -3,\n KiwiNetwork = -4,\n KiwiNoSuchRsName = -5,\n KiwiConnect = -6,\n KiwiNetworkRead = -7,\n KiwiNetworkWrite = -8,\n KiwiJson = -9,\n KiwiJsonNoRoot = -10,\n KiwiJsonNoMember = -11,\n KiwiJavaRuntime = -12,\n KiwiCherryRpcFailed = -13,\n KiwiNoRss = -14,\n KiwiNoApp = -15,\n KiwiUnknow = -999\n};\n```\n"}