BBASMPackageManagementService.h 4.26 KB
//
//  BBASMPackageManagementService.h
//  SWAN
//
//  Created by baidu on 2018/10/24.
//  Copyright © 2018 baidu. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "BBASMPMSCommon.h"
#import "BBASMPMSRequestItem.h"

NS_ASSUME_NONNULL_BEGIN

#define BBASMPMSService [BBASMPackageManagementService shared]

/**
 * Package Management Service(PMS) is used for requesting swan app and swan core package.
 */
@interface BBASMPackageManagementService : NSObject

+ (nullable instancetype)shared;
- (instancetype)init UNAVAILABLE_ATTRIBUTE;
+ (instancetype)new UNAVAILABLE_ATTRIBUTE;

/**
 * Use GET to request swan app package info from server.
 * 
 * @param requestItem   Local package info, `bundleID`, `category`, `packageVersion`, `frameworkVersion` are required,
 *                      `subID`, `appSignature`, `extensionVersion` and `pagePath` are optional.
 * @param appInfoBlock  A call back to take back app info and how many packages need to download. It will be executed if exist before downloading the package.
 * @param mainPackageProgress Call back of main package download progress if the main package exsit, maybe call back not on main thread.
 * @param download      Callback contains package info if successful, throw an error if failed to get the package.
 *                      Maybe call back multiple times if there is more than one package to download.
 * @param completion    Callback contains the task state when all the download task completed.
 */
- (BOOL)getAppPackageWithRequestItem:(BBASMPMSRequestItem *)requestItem
                        appInfoBlock:(nullable PMSAppInfoBlock)appInfoBlock
                 mainPackageProgress:(nullable PMSDownloaderProgressBlock)mainPackageProgress
                            download:(nullable PMSPackageDownloadBlock)download
                          completion:(nullable PMSCompletionBlock)completion;

/**
 * Use GET to request plugin, such as sConsole.
 *
 * @param requestItem `bundle_id`, `category`, `plugin_ver` are required.
 * @param download Callback after plugin is downloaded or failed.
 * @param completion Callback contains the task state when all the download task completed.
 */
- (void)getPluginWithRequestItem:(BBASMPMSRequestItem *)requestItem
                        download:(nullable PMSPackageDownloadBlock)download
                      completion:(nullable PMSCompletionBlock)completion;


/**
 * Use POST to request a package list from server.
 *
 * @param requestItem       Local package info, `bundleIDs` are required.
 * @param appInfoListBlock  App infos call back. If there are app info array from server, the block will be executed if exist before downloading the package.
 * @param download          Callback contains package info if successful, throw an error if failed to get the package.
 *                          Maybe call back multiple times if there is more than one package to download.
 * @param completion        Callback contains the task state when all the download task completed.
 */
- (void)getAppPackageListWithRequestItem:(BBASMPMSRequestItem *)requestItem
                        appInfoListBlock:(nullable PMSAppInfoListBlock)appInfoListBlock
                                download:(nullable PMSAppListDownloadBlock)download
                              completion:(nullable PMSAppListCompletionBlock)completion;

/// Use POST to request openbundleid from server with appKeys,need use bdtls 
/// @param appID 当前appID
/// @param appKeys 需转换appKeys数组
/// @param success 成功回调
/// @param failure 失败回调
+ (void)requestPackageBundleIDWithAppID:(NSString *)appID
                                appKeys:(NSArray *)appKeys
                                success:(nullable void (^)(NSDictionary * _Nullable responseHeaders, NSDictionary *responseData))success
                                failure:(nullable void (^)(NSError *error, NSInteger reponseStausCode))failure;

/// Use POST to request Dependencies
/// @param requestItem 请求信息
/// @param download 成功回调
/// @param completion 失败回调
- (void)getDependenciesWithRequestItem:(BBASMPMSRequestItem *)requestItem
                              download:(nullable PMSDependenciesDownloadBlock)download
                            completion:(nullable PMSDependenciesCompletionBlock)completion;

@end

NS_ASSUME_NONNULL_END