From 024161fbe569f5cfe9a4d41b443c1668c25a86d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B6=A6=E7=94=9F?= Date: Fri, 26 Oct 2018 10:42:29 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9readme=E4=BB=8B=E7=BB=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README-CN.md | 55 ++++++++++++++++++++--- README.md | 49 +++++++++++++++++++- buildOSXFramework.sh | 46 +++++++++++++++++++ buildFramework.sh => buildiOSFramework.sh | 0 4 files changed, 142 insertions(+), 8 deletions(-) create mode 100755 buildOSXFramework.sh rename buildFramework.sh => buildiOSFramework.sh (100%) diff --git a/README-CN.md b/README-CN.md index d6cd5a9f..7353dd75 100644 --- a/README-CN.md +++ b/README-CN.md @@ -16,7 +16,7 @@ 需要引入OSS iOS SDK framework。 -您可以在MacOS系统中直接使用在本工程生成framwork: +您可以在MacOS系统中直接使用本工程,选择对应的scheme为AliyunOSSSDK OSX,然后生成framwork: ```bash # clone工程 @@ -26,16 +26,16 @@ $ git clone git@github.com:aliyun/aliyun-oss-ios-sdk.git $ cd aliyun-oss-ios-sdk # 执行打包脚本 -$ sh ./buildFramework.sh +$ sh ./buildiOSFramework.sh # 进入打包生成目录,AliyunOSSiOS.framework生成在该目录下 $ cd Products && ls ``` -注意:buildFramework.sh脚本生成的framework是支持i386,x86_64,armv7,arm64架构的版本,所以当您需要archive product时,需要直接使用工程文件生成只支持真机的framework版本。 - 在Xcode中,直接把framework拖入您对应的Target下即可,在弹出框勾选`Copy items if needed`。 +**注意:buildiOSFramework.sh脚本生成的framework是支持i386,x86_64,armv7,arm64架构的版本,所以当您需要archive product时,需要直接使用工程文件生成只支持真机的framework版本。** + ### Pod依赖 如果工程是通过pod管理依赖,那么在Podfile中加入以下依赖即可,不需要再导入framework: @@ -79,8 +79,6 @@ WWDC 2016开发者大会上,苹果宣布从2017年1月1日起,苹果App Stor ### 对于OSSTask的一些说明 -**注意: 建议OSSClient的生命周期和应用程序的生命周期保持一致(如果您不希望这样,也可以在调用API时增加[task waitUntilFinished]以确保在task完成之前OSSClient不被释放)。** - 所有调用api的操作,都会立即获得一个OSSTask,如: ``` @@ -129,6 +127,51 @@ client = [[OSSClient alloc] initWithEndpoint:endpoint credentialProvider:credent ``` +**注意: 如果您的应用只用到一个[数据中心](https://help.aliyun.com/document_detail/31837.html)下的bucket,建议保持OSSClient实例与应用程序的生命周期一致(比如在Appdelegate.m的 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions])中进行初始化,如下所示:** + +```objc +@interface AppDelegate () + +@property (nonatomic, strong) OSSClient *client; + +@end + +/** + * 获取sts信息的url,配置在业务方自己的搭建的服务器上。详情可见https://help.aliyun.com/document_detail/31920.html + */ +#define OSS_STS_URL @"oss_sts_url" + + +/** + * bucket所在的region的endpoint,详情可见https://help.aliyun.com/document_detail/31837.html + */ +#define OSS_ENDPOINT @"your bucket's endpoint" + +@implementation AppDelegate + + +- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { + // Override point for customization after application launch. + + // 初始化OSSClient实例 + [self setupOSSClient]; + + return YES; +} + +- (void)setupOSSClient { + + // 初始化具有自动刷新的provider + OSSAuthCredentialProvider *credentialProvider = [[OSSAuthCredentialProvider alloc] initWithAuthServerUrl:OSS_STS_URL]; + + // client端的配置,如超时时间,开启dns解析等等 + OSSClientConfiguration *cfg = [[OSSClientConfiguration alloc] init]; + + _client = [[OSSClient alloc] initWithEndpoint:OSS_ENDPOINT credentialProvider:credentialProvider clientConfiguration:cfg]; +} + +``` + ### STEP-2. 上传文件 这里假设您已经在控制台上拥有自己的Bucket。SDK的所有操作,都会返回一个`OSSTask`,您可以为这个task设置一个延续动作,等待其异步完成,也可以通过调用`waitUntilFinished`阻塞等待其完成。 diff --git a/README.md b/README.md index 06512a0d..0be3ae13 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ This document mainly describes how to install and use the OSS iOS SDK. This docu The OSS iOS SDK framework needs to be introduced. -You can use this project to directly generate a framework in MacOS : +You can use this AliyunOSSSDK.xcworkspace,and select scheme which named AliyunOSSSDK OSX to directly generate a framework in MacOS : ```bash # Clone the project @@ -26,7 +26,7 @@ $ git clone git@github.com:aliyun/aliyun-oss-ios-sdk.git $ cd aliyun-oss-ios-sdk # Run the packaging script -$ sh ./buildFramework.sh +$ sh ./buildiOSFramework.sh # Enter the generated packaging directory where the AliyunOSSiOS.framework will be generated $ cd Products && ls @@ -123,6 +123,51 @@ client = [[OSSClient alloc] initWithEndpoint:endpoint credentialProvider:credent ``` +**Notice:if your app's buckets only at one [data center](https://www.alibabacloud.com/help/doc-detail/31837.htm),we recommend you to keep the lifecycle of OSSClient's instance consistent with your app.the code below demonstrate the usage** + +```objc +@interface AppDelegate () + +@property (nonatomic, strong) OSSClient *client; + +@end + +/** + * the url to fetch sts info,for detail please refer to https://help.aliyun.com/document_detail/31920.html + */ +#define OSS_STS_URL @"oss_sts_url" + + +/** + * the endpoint for OSS used in app, for detail please refer to https://help.aliyun.com/document_detail/31837.html + */ +#define OSS_ENDPOINT @"your bucket's endpoint" + +@implementation AppDelegate + + +- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { + // Override point for customization after application launch. + + // initialize OSSClient + [self setupOSSClient]; + + return YES; +} + +- (void)setupOSSClient { + + // initialize credential provider,which auto fetch and update sts info from sts url. + OSSAuthCredentialProvider *credentialProvider = [[OSSAuthCredentialProvider alloc] initWithAuthServerUrl:OSS_STS_URL]; + + // set config for oss client networking + OSSClientConfiguration *cfg = [[OSSClientConfiguration alloc] init]; + + _client = [[OSSClient alloc] initWithEndpoint:OSS_ENDPOINT credentialProvider:credentialProvider clientConfiguration:cfg]; +} + +``` + ### Step-2. Upload a file Suppose that you have a bucket in the OSS console. An *OSSTask* will be returned after each SDK operation. You can configure a continuation for the task to achieve asynchronous callback. You can also use the *waitUntilFinished* to block other requests and wait until the task is finished. diff --git a/buildOSXFramework.sh b/buildOSXFramework.sh new file mode 100755 index 00000000..d7432652 --- /dev/null +++ b/buildOSXFramework.sh @@ -0,0 +1,46 @@ +#!/bin/sh + +PROJECT_NAME='AliyunOSSSDK' +TARGET_NAME="AliyunOSSSDK OSX" +SRCROOT='.' + +# Sets the target folders and the final framework product. +FMK_NAME='AliyunOSSOSX' + +# Install dir will be the final output to the framework. +# The following line create it in the root folder of the current project. +INSTALL_DIR=${SRCROOT}/Products/${FMK_NAME}.framework + +# Working dir will be deleted after the framework creation. +WRK_DIR=./build +DEVICE_DIR=${WRK_DIR}/Release/${FMK_NAME}.framework + +# -configuration ${CONFIGURATION} +# Clean and Building both architectures. +# xcodebuild -configuration "Release" -target "${FMK_NAME}" -sdk iphoneos clean build +# xcodebuild -configuration "Release" -target "${FMK_NAME}" -sdk iphonesimulator clean build +xcodebuild -configuration Release -workspace "${PROJECT_NAME}.xcworkspace" -scheme "${TARGET_NAME}" -sdk macosx clean build SYMROOT="${WRK_DIR}" + +# Cleaning the oldest. +if [ -d "${INSTALL_DIR}" ] +then + rm -rf "${INSTALL_DIR}" +fi + +mkdir -p ${SRCROOT}/Products + +cp -LR "${DEVICE_DIR}" "${INSTALL_DIR}" + + +rm -r "${WRK_DIR}" + +if [ -d "${INSTALL_DIR}/_CodeSignature" ] +then + rm -rf "${INSTALL_DIR}/_CodeSignature" +fi + +if [ -f "${INSTALL_DIR}/Info.plist" ] +then + rm "${INSTALL_DIR}/Info.plist" +fi + diff --git a/buildFramework.sh b/buildiOSFramework.sh similarity index 100% rename from buildFramework.sh rename to buildiOSFramework.sh