从任何地方将混合应用程序部署到任何设备,仅需几秒钟 - http://www.storkhq.io/
- (void)viewDidLoad
{
[super viewDidLoad];
// Prepare delivery - configure Stork (default version will be 0.0.0)
[[Stork sharedClient] prepareDeliveryWithProjectToken:@"your-project-token" withVersion:@"your-project-version"];
[[Stork sharedClient] prepareDeliveryWithWebView:self.webView];
// Start Stork delivery - Stork now handles downloads and updates
[[Stork sharedClient] deliver];
}
Stork 是一个平台,用于管理并部署在原生 iOS、Android、Windows Phone 和 Cordova 包装器内的混合 HTML5 应用程序。您所需做的就是提供 projectToken
和 version
,Stork 将处理其余工作。它会下载并安装您的 HTML5 应用的最新版本,这样您的用户无需通过 App Store 推送更改即可始终运行最新的更新。
需要从 HTML/JS 与原生 iOS 进行通信?没问题!Stork 配备了一个本地桥接器,允许进行此类通信。但这是尚未官方发布的功能,在这之前您可以使用 Cordova。
StorkConsoleViewController
在您的设备上运行应用程序时进行调试 - 了解更多StorkLoaderViewController
在下载和安装新内容时向用户显示(这样他们就不会遇到空白屏幕) - 了解更多此设置具有最少的工作量,但提供了最多的功能。以下是正在发生的事情
Stork
对象将加载您的 web 应用程序(了解更多关于 deliver)[Stork sharedClient]
来初始化 StorkLoaderViewController
[Stork sharedClient]
的代理为 StorkLoaderViewController
实例,这使得 StorkLoaderViewController
能够接收显示所需的所有信息,并在完成下载后隐藏Stork
开始分发(这将检查新的部署,下载它们,并将它们加载到 webview 中)@interface ViewController ()<StorkDelegate>
@property (nonatomic, strong) StorkLoaderViewController *storkLoaderViewController;
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Prepare delivery - configure Stork
[[Stork sharedClient] prepareDeliveryWithProjectToken:@"your-project-token" withVersion:@"your-app-version"];
[[Stork sharedClient] prepareDeliveryWithWebView:self.webView];
// OPTIONAL - Use this fancy view controller to show loading status
self.storkLoaderViewController = [StorkLoaderViewController addToViewController:self withStork:[Stork sharedClient]];
// Start Stork delivery - Stork now handles downloads and updates
[[Stork sharedClient] deliver];
}
@end
Stork
对象是这个库的核心。它处理 API 通信、下载 HTML 网络应用、加载 UIWebView,以及包含工作目录和存放目录的状态等。以下是重要方面的详细说明。
sharedClient
通过在 Stork
上调用 sharedClient
方法,您可以在整个应用程序中获得一个单一实例。Stork 中内置了单例,因为大多数应用程序实际上只需要一个 UIWebView 实例,它只需要一个 Stork
实例。
然而,如果您需要的话,可以实例化自己的(和多个)Stork
对象。
Stork *storkSingleton = [Stork sharedClient];
prepareDelivery
Stork
对象有几个以 prepareDelivery
前缀开头的方法。这些方法应该只执行一次,并在调用 deliver
方法之前被调用,因为它们要么是 1) 执行分发所必需的,要么是 2) 确定 Stork
为您执行工作的方式。
如果您的项目令牌和/或版本没有定义,Stork 实例将无法找到任何部署
如果您的 webview 没有定义,Stork 实例将无法自动加载您的 webview
kStorkBehaviorNone
- 不做任何事情
kStorkBehaviorCheckNewDeploy
- 检查是否有新的部署可用 - 点击 手动请求下载和安装
kStorkBehaviorDownloadNewDeploy
- 检查是否有新的部署可用并在后台下载它 - 将在下次应用程序启动或手动安装时重新加载
kStorkBehaviorReloadNewDeploy
- 检查是否有新的部署可用,在后台下载它,安装它,并重新加载 webview
想要手动控制 Stork 吗? - 点击 这里了解更多信息
// Configures this Stork instance with your project token and app version
[[Stork sharedClient] prepareDeliveryWithProjectToken:@"your-project-token" withVersion:@"your-app-version"];
// Configures this Stork instance with which webview will be loaded with the web app
[[Stork sharedClient] prepareDeliveryWithWebView:self.webView];
// Configures this Stork instance's behavior when 'delivery' is called - checks for deploy, download new deploy if available, and then reload the web view
[[Stork sharedClient] prepareDeliveryWithOnDeliverBehavior:kStorkBehaviorReloadNewDeploy withOnEnterForeground:kStorkBehaviorReloadNewDeploy];
deliver
一旦调用 deliver
,Stork
实例将开始工作。
注意:由于UIWebView将自动重新加载,这可能无法提供最佳的用户体验。稍后会有其他配置使其更加完善。
[[Stork sharedClient] deliver];
代理
Stork提供了一个可以设置代理,即StorkDelegate
。该代理调用- (void)stork:(Stork *)stork finishedOperation:(StorkOperation)operation withData:(NSDictionary *)data withError:(NSError *)error
将获取所有可能发生的不同类型的状态更新和错误。
kStorkOperationDownloadProgressUpdated
kStorkNotificationUserInfoProgress
- 进度为CGFLoat - 0.54kStorkOperationDidUpdateWorkingDirectory
kStorkNotificationUserInfoUrl
- 指向索引页面的NSString URL@interface ViewController ()<StorkDelegate>
@end
@implementation ViewController
- (void)viewDidLoad
{
// ... other setup code
// Being a delegate but we don't really need to in this example
[[Stork sharedClient] setDelegate:self];
// ... other setup code
}
#pragma mark - StorkDelegate
- (void)stork:(Stork *)stork finishedOperation:(StorkOperation)operation withData:(NSDictionary *)data withError:(NSError *)error {
switch (operation) {
case kStorkOperationNewDeployAvailable:
NSLog(@"New deploy available");
break;
case kStorkOperationNoNewDeployAvailable:
NSLog(@"No new deploy avaiable");
break;
case kStorkOperationFailedCheckingNewDeployAvailable:
NSLog(@"Failed while checking for new deploy - %@", error);
break;
case kStorkOperationDownloadProgressUpdated:
NSLog(@"Download progress - %@", [data objectForKey:kStorkNotificationUserInfoProgress]);
break;
case kStorkOperationDownloadedNewDeploy:
NSLog(@"Downloaded new deploy");
break;
case kStorkOperationFailedToDownloadNewDeploy:
NSLog(@"Failed to download new deploy - %@", error);
break;
case kStorkOperationWillUpdateWorkingDirectory:
NSLog(@"Will update working directory");
break;
case kStorkOperationDidUpdateWorkingDirectory:
NSLog(@"Did update working directory - %@", [data objectForKey:kStorkNotificationUserInfoUrl]);
break;
case kStorkOperationFailedToUpdateWorkingDirectory:
NSLog(@"Failed to update working directory - %@", error);
break;
case kStorkOperationDidReloadedWebView:
NSLog(@"Did reload web view - %@", [data objectForKey:kStorkNotificationUserInfoUrl]);
break;
default:
break;
}
}
@end
有时您可能想要手动检查新部署,下载新部署或从暂存目录更新
使用此调用来检查新部署。如果您希望让用户在安装最新部署时有所行动,可以使用这个选项来通知他们一个新的部署。
[[Stork sharedClient] checkForNewDeploy:^(NSDictionary *data, NSError *error) {
if (!error) {
// Found new deploy
NSDictionary *deploy = [data objectForKey:kStorkNotificationUserInfoDeploy];
}
}];
使用此调用来从最新检查的部署下载,如果有,并将其下载到暂存目录。
// Returns YES if Stork can download a new deploy
BOOL hasNewDeploy = [[Stork sharedClient] downloadNewDeploy:^(NSDictionary *data, NSError *error) {
if (!error) {
// Downloaded successfully into holding directory
}
}];
使用此调用来将部署从暂存目录移动到工作目录,并使用最新部署重新加载web视图。
// Returns YES if there is a deploy in the holding directory to update with
BOOL canUpdateFromHolding = [[Stork sharedClient] updateWithHoldingDeploy:^(NSDictionary *data, NSError *error) {
if (!error) {
// Incase you need this - you probably don't
NSURL *urlOfWorkingDirectory = [data objectForKey:kStorkNotificationUserInfoUrl];
}
}];
[[Stork sharedClient] checkForNewDeploy:^(NSDictionary *data, NSError *error) {
if (!error) {
// Found new deploy
NSDictionary *deploy = [data objectForKey:kStorkNotificationUserInfoDeploy];
}
} andDownload:^(NSDictionary *data, NSError *error) {
if (!error) {
// Downloaded successfully into holding directory
}
}];
[[Stork sharedClient] checkForNewDeploy:^(NSDictionary *data, NSError *error) {
if (!error) {
// Found new deploy
NSDictionary *deploy = [data objectForKey:kStorkNotificationUserInfoDeploy];
}
} andDownload:^(NSDictionary *data, NSError *error) {
if (!error) {
// Downloaded successfully into holding directory
}
} andUpdateWithHolding:^(NSDictionary *data, NSError *error) {
if (!error) {
// Incase you need this - you probably don't
NSURL *urlOfWorkingDirectory = [data objectForKey:kStorkNotificationUserInfoUrl];
}
}];
Josh Holtz, [email protected], @joshdholtz
在威斯康星州密尔沃基由RokkinCat手动编码
Stork 在 MIT 许可证下可用。有关更多信息,请参阅 LICENSE 文件。