You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
79 lines
2.9 KiB
79 lines
2.9 KiB
4 years ago
|
//
|
||
|
// MinPlugin.m
|
||
|
// Runner
|
||
|
//
|
||
|
// Created by 冯美坎 on 2021/7/7.
|
||
|
//
|
||
|
|
||
|
#import "MinPlugin.h"
|
||
|
#import <Foundation/Foundation.h>
|
||
|
|
||
|
@implementation MinPlugin
|
||
|
|
||
|
-(void)open:(NSString *)appid url:(NSString *)wgtUrl param:(NSDictionary *)dict block:(void (^)(void))block{
|
||
|
if (![DCUniMPSDKEngine isExistsApp:appid]) {
|
||
|
//不存在准备下载
|
||
|
[self downloadWgt:wgtUrl appid:appid block:nil success:^{
|
||
|
[self openUniApp:appid dict:dict];
|
||
|
}];
|
||
|
}else{
|
||
|
[self openUniApp:appid dict:dict];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
-(void)openUniApp:(NSString *)name dict:(NSDictionary *)dict{
|
||
|
DCUniMPConfiguration *configuration = [[DCUniMPConfiguration alloc] init];
|
||
|
[configuration setShowAnimated:YES];
|
||
|
[configuration setHideAnimated:YES];
|
||
|
[configuration setOpenMode:DCUniMPOpenModePresent];
|
||
|
[configuration setEnableGestureClose:YES];
|
||
|
[configuration setArguments:dict];
|
||
|
[DCUniMPSDKEngine openUniMP:name configuration:configuration completed:^(DCUniMPInstance * _Nullable uniMPInstance, NSError * _Nullable error) {
|
||
|
if (uniMPInstance) {
|
||
|
NSLog(@"打开成功");
|
||
|
}else{
|
||
|
NSLog(@"打开失败:%@",error);
|
||
|
}
|
||
|
}];
|
||
|
}
|
||
|
|
||
|
|
||
|
-(void)downloadWgt:(NSString *)url appid:(NSString *)appid block:(void (^)(NSString *))block success:(void (^)(void))success{
|
||
|
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
|
||
|
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];
|
||
|
NSLog(@"url:%@",url);
|
||
|
NSURL *URL = [NSURL URLWithString:url];
|
||
|
NSURLRequest *request = [NSURLRequest requestWithURL:URL];
|
||
|
|
||
|
NSURLSessionDownloadTask *downloadTask = [manager downloadTaskWithRequest:request progress:^(NSProgress * _Nonnull downloadProgress) {
|
||
|
//
|
||
|
NSLog(@"downloadProgress:%f",downloadProgress.fractionCompleted);
|
||
|
//block([NSString stringWithFormat:@"loading...%f",downloadProgress.fractionCompleted]);
|
||
|
} destination:^NSURL * _Nonnull(NSURL * _Nonnull targetPath, NSURLResponse * _Nonnull response) {
|
||
|
NSURL *documentsDirectoryURL = [[NSFileManager defaultManager] URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil];
|
||
|
return [documentsDirectoryURL URLByAppendingPathComponent:[response suggestedFilename]];
|
||
|
} completionHandler:^(NSURLResponse * _Nonnull response, NSURL * _Nullable filePath, NSError * _Nullable error) {
|
||
|
NSLog(@"File downloaded to: %@", filePath);
|
||
|
if ([DCUniMPSDKEngine releaseAppResourceToRunPathWithAppid:appid resourceFilePath:filePath.path]) {
|
||
|
NSLog(@"应用资源文件部署成功");
|
||
|
//直接打开
|
||
|
success();
|
||
|
}
|
||
|
}];
|
||
|
[downloadTask resume];
|
||
|
}
|
||
|
|
||
|
|
||
|
-(void)uniMPOnClose:(NSString *)appid{
|
||
|
NSLog(@"小程序关闭");
|
||
|
}
|
||
|
|
||
|
-(void)defaultMenuItemClicked:(NSString *)identifier{
|
||
|
NSLog(@"胶囊点击");
|
||
|
}
|
||
|
|
||
|
|
||
|
@end
|
||
|
|