StorieCloudSDK 0.1.8

StorieCloudSDK 0.1.8

测试已测试
语言语言 Obj-CObjective C
许可 商业
发布最新发布2016年8月

Michael Gaylord维护。



 
依赖项
Alamofire~> 3.3
SwiftyJSON~> 2.3
RxSwift~> 2.0
RxCocoa~> 2.0
Moya/RxSwift~> 7.0
SwiftyBeaver~> 0.5
FileMD5Hash~> 2.0
 

Storie云SDK

Storie云SDK提供了与Storie云API交互的简单接口。更多信息和开发者访问Storie云,请访问https://developer.storie.com

Storie云API的特点

流式视频

为了在线播放大型视频文件,Apple 强烈建议使用HTTP Live Streaming (HLS)。设置一个完整的服务器端转码服务成本很高且耗时。Storie云API旨在简化此过程,包括将你的视频对象发送到我们的云存储服务,提供完全可定制的自适应比特率流并支持真正的可恢复背景上传。《不再缓冲》只需几行代码。

上传视频

我们为移动视频开发了一种专有传输机制,并将其添加到我们的SDK中。上传将自动恢复,可以在后台运行并保证交付。

转换视频

Storie云支持多种视频转换工具。我们提供转换为高性能、自适应比特率视频流(HLS & MPEG-DASH),或动画GIF,或者在开发者控制台中操作视频。控制你的视频,准备进行分析、分发和存储。

分析视频

提取关键词、位置、文本和商标。识别面部、情感和人口统计学。StorieCloud提供了一套强大且高度精确的视频分析工具。使用我们的安全搜索分析工具以通知您内容。

分发视频

我们的灵活回调架构被设计用来向您的服务器基础设施发送反馈,并通过性能优异的内容分发网络将反馈分发给您的用户。

存储视频

运行一个完全冗余的、云存储视频的基础设施非常复杂。基于Google Cloud Storage,我们结合了低访问延迟和完全冗余,确保您的数据在任何时候都是安全且完全可访问的,所有这些只需非常低的成本。

我们为自家应用AppStore构建了这个基础设施,其效果非常好(已过100,000个视频的测试),因此我们希望让其他开发者也能使用。

有关我们云视频API的更多信息,请访问 https://developer.storie.com 或查看其使用: https://itunes.apple.com/us/app/storie-video-storytelling/id950300668?mt=8

先决条件

该SDK完全兼容Objective-C和Swift 2.2,并需要iOS SDK 8.0或更高版本的最低部署目标。如果您需要Swift 2.3和3.0的构建版本,请联系我们。

您还需要一个API密钥。我们目前正在努力完善开发者控制台,因此请通过邮箱 [email protected] 获取您的API密钥和设置说明。

文档

Storie云API文档可在: https://storie-developers.readme.io/docs 查找,SDK文档可在: https://developer.storie.com/docs/ios/index.html 查找。

您还可以在本项目的 /Example/ 文件夹中查看我们的Swift和Objective-C示例应用。

如果您想尝试任何示例项目,可以使用Cocoapods命令: pod try StorieCloudSDK

开始使用

设置

Swift

将以下代码添加到您的 AppDelegate.swift 文件顶部,以便使用Storie云SDK:

import StorieCloudSDK

然后在您的 AppDelegate.swift 中添加一个属性以存储您的 StoriePlatform 对象。

var storiePlatform: StoriePlatform?

为了初始化 storiePlatform 属性,在您的 AppDelegate:didFinishLaunchingWithOptions() 的开头添加以下内容。现在请联系我们获取API密钥 [email protected]

self.storiePlatform = try? StoriePlatform(apiKey: "{API_KEY}")

更多内容请访问 StoriePlatform文档

Objective-C

将以下代码添加到您的 AppDelegate.m 文件顶部,以便使用storie云SDK。

@import StorieCloudSDK;

然后在您的 AppDelegate.m 中添加一个属性以存储 StoriePlatform 对象。

@property (nonatomic, strong) StoriePlatform *storiePlatform;

为了初始化 storiePlatform 属性,在您的 [AppDelegate didFinishLaunchingWithOptions:] 的开头添加以下内容。您需要从storie API开发者控制台中获取API_KEY。

NSError *error;
self.storiePlatform = [[StoriePlatform alloc] initWithApiKey:@"{API_KEY}" error:&error];

更多内容请访问 StoriePlatform文档

使用

上传视频文件

Storie SDK仅支持Quicktime和MPEG-4视频文件。以下内容将开始向Storie API上传新的文件。

Swift语言版本:

let videoFileURL = = NSURL(fileURLWithPath: "file://path_to_my_file/to_upload.mp4")
do {
    try storiePlatform.upload(videoFileURL, userInfo: ["localObjectID" : "12345566"],
                                     callbackData: ["serverObjectID" : "1233454"]
                                      serviceName: @"DEFAULT")
} catch let error {
    NSLog("Error uploading video at URL: \(fileURL) : \(error)")
}

Objective-C语言版本:

NSError *error;
NSURL *videoFileURL = [NSURL fileURLWithPath:@"file://path_to_my_file/to_upload.mp4"];
[storiePlatform upload:videoFileURL
            userInfo:@{@"localObjectID" : @"12345677"}
        callbackData:@{@"serverObjectID" : @"12345677"}
        serviceName: @"DEFAULT"
        thumbnailTime:0.3
              onError:^(NSError *error){
            NSLog(@"Error initializing upload: %@", error);
        }  onUploadInitialized: ^{
            NSLog(@"Upload initialized successfully.");
        }];

跟踪上传进度

检查上传进度的方法有两种。第一种是实现StoriePlatformDelegate协议并将其分配给您的StoriePlatform实例。

有关您将通过StoriePlatformDelegate收到的回调的更多信息,请访问:https://developer.storie.com/docs/ios/Protocols/StoriePlatformDelegate.html

第二种方式是在UploadNotifications上注册NSNotification观察者。有关可用常量的信息,请访问:https://developer.storie.com/docs/ios/Structs/UploadNotifications.html

在Objective-C中,您需要导入

#import <StorieCloudSDK/ObjcConstants.h>

然后您将可以使用以下通知名称和常量,它们在功能上与Swift中指定的UploadNotifications结构体中指定的一致

extern NSString* const UploadNotificationUploadFailed;
extern NSString* const UploadNotificationUploadInitializing;
extern NSString* const UploadNotificationUploadProgress;
extern NSString* const UploadNotificationUploadAllComplete;
extern NSString* const UploadNotificationUploadComplete;
extern NSString* const UploadNotificationUploadStarted;
extern NSString* const UploadNotificationUploadResumed;
extern NSString* const UploadNotificationUploadProgressKey;
extern NSString* const UploadNotificationUploadTotalProgressKey;
extern NSString* const UploadNotificationUploadErrorKey;
extern NSString* const UploadNotificationUploadObjectKey;
extern NSString* const UploadNotificationUploadCompletedResultsKey;
extern NSString* const UploadNotificationUploadUserInfoKey;

检索视频文件信息

如果您想了解您已上传的视频的属性,包括其当前状态,可以使用videoInfo函数。

Swift语言版本:

do {
    try storiePlatform.videoInfo(videoID) { video in
        NSLog("Video found: \(video.videoID) - status: \(video.status?.rawValue)")
    }
} catch let error {
    NSLog("Error getting video: \(error)")
}

Objective-C语言版本:

NSError *error;
[storiePlatform getVideoInfo: text error:&error success:^(NSDictionary<NSString *,id> *result) {
    NSLog(@"Video found: %@", result);
}];

启用可恢复的后台上传功能

如果您希望在启动时自动从上次中断处恢复任何失败或停止的下载,请在创建StoriePlatform实例后,将其添加到didFinishLaunchingWithOptions()方法中

Swift语言版本:

storiePlatform?.initializeUploads()

Objective-C语言版本:

[self.storiePlatform initializeUploads];

最后,为了正确管理您的应用的背景上传会话,您需要实现应用程序代理方法:application(application: UIApplication, handleEventsForBackgroundURLSession identifier: String, completionHandler: Void->()),使其看起来像这样

Swift语言版本:

final func application(application: UIApplication,
  handleEventsForBackgroundURLSession identifier: String,
  completionHandler: Void->()) {
    if application.applicationState == UIApplicationState.Active { return }
    storiePlatform?.handleEventsForBackgroundSession(identifier, completionHandler: completionHandler)
}

Objective-C语言版本:

- (void) application:(UIApplication *)application handleEventsForBackgroundURLSession:(NSString *)identifier
   completionHandler:(void (^)())completionHandler {
    if (application.applicationState == UIApplicationStateActive) { return;}
    [self.storiePlatform handleEventsForBackgroundSession:identifier completionHandler:completionHandler];
}

然后启用您的目标的“功能”列表中的“后台模式”,并确保选择“后台检索”。

capabilities-configuration

运行您的应用,并通过测试上传文件来确保一切正常工作。

注意:关于后台上传。在调试应用程序时,即使切换到其他应用程序或返回到主屏幕,应用程序也永远不会置于后台。测试后台上传的唯一可靠方法是脱离调试器运行应用程序。