diff --git a/uni_modules/uni-exit/utssdk/interface.uts b/uni_modules/uni-exit/utssdk/interface.uts index aae2adc5b3ded0e2c7b1dfb4af8214ffdf03abb2..49b8ff734a0adc8845643df34dff2cab6a085fac 100644 --- a/uni_modules/uni-exit/utssdk/interface.uts +++ b/uni_modules/uni-exit/utssdk/interface.uts @@ -61,12 +61,16 @@ export interface Uni { * "android": { * "osVer": "5.0", * "uniVer": "3.8.15", - * "unixVer": "3.9.0" + * "uniUtsPlugin": "3.9.0", + * "unixVer": "3.9.0", + * "unixUtsPlugin": "3.9.0" * }, * "ios": { * "osVer": "x", * "uniVer": "x", - * "unixVer": "x" + * "uniUtsPlugin": "x", + * "unixVer": "x", + * "unixUtsPlugin": "x" * } * }, * "web": { diff --git a/uni_modules/uni-fileSystemManager/package.json b/uni_modules/uni-fileSystemManager/package.json index 94e2f8ba7d10b3c33b06caa624fddd72e3125f8d..751b7babe78e6d46860bf96293f85fde1b90d38d 100644 --- a/uni_modules/uni-fileSystemManager/package.json +++ b/uni_modules/uni-fileSystemManager/package.json @@ -37,7 +37,7 @@ "getFileSystemManager": { "name": "getFileSystemManager", "app": { - "js": false, + "js": true, "kotlin": true, "swift": false } diff --git a/uni_modules/uni-fileSystemManager/utssdk/app-android/FileDescriptorUtil.uts b/uni_modules/uni-fileSystemManager/utssdk/app-android/FileDescriptorUtil.uts index 9b223f9245f0d4be717d52193903d91ade87ef28..cec6a188094ec662b80636043a6bb055b6c86709 100644 --- a/uni_modules/uni-fileSystemManager/utssdk/app-android/FileDescriptorUtil.uts +++ b/uni_modules/uni-fileSystemManager/utssdk/app-android/FileDescriptorUtil.uts @@ -1,7 +1,7 @@ import File from 'java.io.File' import ParcelFileDescriptor from 'android.os.ParcelFileDescriptor' import { OpenFileOptions, OpenFileSuccessResult, OpenFileSyncOptions } from '../interface'; -import { UniErrorSubject, UniErrors } from '../unierror'; +import { UniErrorSubject,FileSystemManagerFailImpl,FileSystemManagerUniErrors } from '../unierror'; export class FileDescriptorUtil { public openMap : Map = new Map() @@ -28,12 +28,12 @@ export class FileDescriptorUtil { case 'ax': //类似于 'a',但如果路径存在,则失败 { if (file.exists()) { - let err = new UniError(UniErrorSubject, 1301005, UniErrors.get(1301005)!); + let err = new FileSystemManagerFailImpl(1301005); options.fail?.(err) options.complete?.(err) } else { if (file.parentFile?.exists() == false) { - let err = new UniError(UniErrorSubject, 1300002, UniErrors.get(1300002)!); + let err = new FileSystemManagerFailImpl(1300002); options.fail?.(err) options.complete?.(err) return @@ -66,7 +66,7 @@ export class FileDescriptorUtil { case 'ax+': //类似于 'a+',但如果路径存在,则失败 { if (file.exists()) { - let err = new UniError(UniErrorSubject, 1301005, UniErrors.get(1301005)!); + let err = new FileSystemManagerFailImpl(1301005); options.fail?.(err) options.complete?.(err) } else { @@ -84,7 +84,7 @@ export class FileDescriptorUtil { case 'r': //打开文件用于读取。 如果文件不存在,则会发生异常 { if (!file.exists()) { - let err = new UniError(UniErrorSubject, 1300002, UniErrors.get(1300002)!); + let err = new FileSystemManagerFailImpl(1300002); options.fail?.(err) options.complete?.(err) } else { @@ -104,7 +104,7 @@ export class FileDescriptorUtil { case 'r+': //打开文件用于读取和写入。 如果文件不存在,则会发生异常 { if (!file.exists()) { - let err = new UniError(UniErrorSubject, 1300002, UniErrors.get(1300002)!); + let err = new FileSystemManagerFailImpl(1300002); options.fail?.(err) options.complete?.(err) } else { @@ -136,7 +136,7 @@ export class FileDescriptorUtil { case 'wx'://类似于 'w',但如果路径存在,则失败 { if (file.exists()) { - let err = new UniError(UniErrorSubject, 1301005, UniErrors.get(1301005)!); + let err = new FileSystemManagerFailImpl(1301005); options.fail?.(err) options.complete?.(err) } else { @@ -168,7 +168,7 @@ export class FileDescriptorUtil { case 'wx+': // 类似于 'w+',但如果路径存在,则失败 { if (file.exists()) { - let err = new UniError(UniErrorSubject, 1301005, UniErrors.get(1301005)!); + let err = new FileSystemManagerFailImpl(1301005); options.fail?.(err) options.complete?.(err) } else { @@ -187,7 +187,7 @@ export class FileDescriptorUtil { } } } catch (e) { - let err = new UniError(UniErrorSubject, 1300201, UniErrors.get(1300201)! + ":" + e + " " + options.filePath); + let err = new FileSystemManagerFailImpl(1300201); options.fail?.(err) options.complete?.(err) } @@ -206,10 +206,10 @@ export class FileDescriptorUtil { case 'ax': //类似于 'a',但如果路径存在,则失败 { if (file.exists()) { - throw new Error(`${msgPrefix}${UniErrors[1301005]}`) + throw new Error(`${msgPrefix}${FileSystemManagerUniErrors[1301005]}`) } else { if (file.parentFile?.exists() == false) { - throw new Error(`${msgPrefix}${UniErrors[1300002]}`) + throw new Error(`${msgPrefix}${FileSystemManagerUniErrors[1300002]}`) } else { file.createNewFile() let fd = this.open_a(file) @@ -228,7 +228,7 @@ export class FileDescriptorUtil { case 'ax+': //类似于 'a+',但如果路径存在,则失败 { if (file.exists()) { - throw new Error(`${msgPrefix}${UniErrors[1301005]}`) + throw new Error(`${msgPrefix}${FileSystemManagerUniErrors[1301005]}`) } else { let fd = this.open_ax(file) this.openMap.set(fd, file) @@ -238,7 +238,7 @@ export class FileDescriptorUtil { case 'r': //打开文件用于读取。 如果文件不存在,则会发生异常 { if (!file.exists()) { - throw new Error(`${msgPrefix}${UniErrors[1300002]}`) + throw new Error(`${msgPrefix}${FileSystemManagerUniErrors[1300002]}`) } else { let mode = ParcelFileDescriptor.MODE_READ_ONLY let pfd = ParcelFileDescriptor.open(file, mode); @@ -251,7 +251,7 @@ export class FileDescriptorUtil { case 'r+': //打开文件用于读取和写入。 如果文件不存在,则会发生异常 { if (!file.exists()) { - throw new Error(`${msgPrefix}${UniErrors[1300002]}`) + throw new Error(`${msgPrefix}${FileSystemManagerUniErrors[1300002]}`) } else { let mode = ParcelFileDescriptor.MODE_READ_WRITE let pfd = ParcelFileDescriptor.open(file, mode); @@ -270,7 +270,7 @@ export class FileDescriptorUtil { case 'wx'://类似于 'w',但如果路径存在,则失败 { if (file.exists()) { - throw new Error(`${msgPrefix}${UniErrors[1301005]}`) + throw new Error(`${msgPrefix}${FileSystemManagerUniErrors[1301005]}`) } else { let fd = this.open_w(file) this.openMap.set(fd, file) @@ -289,7 +289,7 @@ export class FileDescriptorUtil { case 'wx+': // 类似于 'w+',但如果路径存在,则失败 { if (file.exists()) { - throw new Error(`${msgPrefix}${UniErrors[1301005]}`) + throw new Error(`${msgPrefix}${FileSystemManagerUniErrors[1301005]}`) } else { let mode = ParcelFileDescriptor.MODE_CREATE | ParcelFileDescriptor.MODE_READ_WRITE | ParcelFileDescriptor.MODE_TRUNCATE let pfd = ParcelFileDescriptor.open(file, mode); diff --git a/uni_modules/uni-fileSystemManager/utssdk/app-android/index.uts b/uni_modules/uni-fileSystemManager/utssdk/app-android/index.uts index 42ba37e7e1fc4f06ba320ebb9da17d5512df219c..966bcf8eccb6c27b5a7f371796af673c178f623d 100644 --- a/uni_modules/uni-fileSystemManager/utssdk/app-android/index.uts +++ b/uni_modules/uni-fileSystemManager/utssdk/app-android/index.uts @@ -1,7 +1,7 @@ import { WriteFileOptions, ReadFileOptions, MkDirOptions, RmDirOptions, TruncateFileOptions, UnLinkOptions, ReadDirOptions, AccessOptions, RenameOptions, GetFileInfoOptions, CopyFileOptions, StatOptions, AppendFileOptions, OpenFileOptions, OpenFileSuccessCallback, OpenFileSuccessResult, SaveFileOptions, UnzipFileOptions, GetSavedFileListOptions, ReadCompressedFileOptions, ReadCompressedFileResult, RemoveSavedFileOptions, WriteOptions, WriteResult, OpenFileSyncOptions, WriteSyncOptions, CloseOptions, CloseSyncOptions, FStatOptions, FStatSuccessResult, FTruncateFileOptions, FTruncateFileSyncOptions, FStatSyncOptions, ReadZipEntryOptions, ZipFileItem, ReadZipEntryCallback, EntriesResult } from "../interface.uts" import { ReadFileSuccessResult, FileManagerSuccessResult, ReadDirSuccessResult, AccessSuccessResult, SaveFileSuccessResult, GetFileInfoSuccessResult, StatSuccessResult, FileStats, Stats, GetSavedFileListResult } from "../interface.uts" import { GetFileSystemManager, FileSystemManager } from "../interface.uts" -import { UniErrorSubject, UniErrors } from "../unierror.uts" +import { FileSystemManagerFailImpl, FileSystemManagerUniErrorSubject, FileSystemManagerUniErrors, UniErrors } from "../unierror.uts" import { FileDescriptorUtil } from "./FileDescriptorUtil" import File from "java.io.File" import Base64 from "android.util.Base64" @@ -18,6 +18,7 @@ import Option from 'android.app.VoiceInteractor.PickOptionRequest.Option'; import FileDescriptor from 'java.io.FileDescriptor'; import ParcelFileDescriptor from 'android.os.ParcelFileDescriptor'; import ByteBuffer from 'java.nio.ByteBuffer'; +import InputStream from 'java.io.InputStream'; class AndroidStats implements Stats, io.dcloud.uts.log.LogSelf, io.dcloud.uts.json.IJsonStringify { /** @@ -96,7 +97,7 @@ class AndroidFileSystemManager implements FileSystemManager { let isSandyBox = isSandyBoxPath(filePath, true) if (!isSandyBox) { currentDispatcher.async(function (_) { - let err = new UniError(UniErrorSubject, 1300013, UniErrors.get(1300013)! + ":" + options.path); + let err = new FileSystemManagerFailImpl(1300013); options.fail?.(err) options.complete?.(err) }, null) @@ -110,7 +111,7 @@ class AndroidFileSystemManager implements FileSystemManager { * 文件不存在 */ currentDispatcher.async(function (_) { - let err = new UniError(UniErrorSubject, 1300002, UniErrors.get(1300002)! + ":" + options.path); + let err = new FileSystemManagerFailImpl(1300002); options.fail?.(err) options.complete?.(err) }, null) @@ -178,14 +179,14 @@ class AndroidFileSystemManager implements FileSystemManager { let tempRecursive = recursive let isSandyBox = isSandyBoxPath(filePath, true) if (!isSandyBox) { - throw new UniError(UniErrorSubject, 1300013, msgPrefix + UniErrors.get(1300013)!) + throw new UniError(FileSystemManagerUniErrorSubject, 1300013, msgPrefix + FileSystemManagerUniErrors.get(1300013)!) } let targetFile = new File(filePath) if (!targetFile.exists()) { /** * 文件不存在 */ - throw new UniError(UniErrorSubject, 1300002, msgPrefix + UniErrors.get(1300002)!); + throw new UniError(FileSystemManagerUniErrorSubject, 1300002, msgPrefix + FileSystemManagerUniErrors.get(1300002)!); } if (tempRecursive == true && targetFile.isDirectory()) { // 如果当前是目录,并且设置 则需要遍历所有子目录 @@ -233,7 +234,7 @@ class AndroidFileSystemManager implements FileSystemManager { let isSandyBox = isSandyBoxPath(filePath, true) if (!isSandyBox) { currentDispatcher.async(function (_) { - let err = new UniError(UniErrorSubject, 1300013, UniErrors.get(1300013)! + ":" + options.filePath); + let err = new FileSystemManagerFailImpl(1300013); options.fail?.(err) options.complete?.(err) }, null) @@ -247,7 +248,7 @@ class AndroidFileSystemManager implements FileSystemManager { * 文件不存在 */ currentDispatcher.async(function (_) { - let err = new UniError(UniErrorSubject, 1300002, UniErrors.get(1300002)! + ":" + options.filePath); + let err = new FileSystemManagerFailImpl(1300002); options.fail?.(err) options.complete?.(err) }, null) @@ -259,7 +260,7 @@ class AndroidFileSystemManager implements FileSystemManager { * 文件是个目录 */ currentDispatcher.async(function (_) { - let err = new UniError(UniErrorSubject, 1300021, UniErrors.get(1300021)! + ":" + options.filePath); + let err = new FileSystemManagerFailImpl( 1300021); options.fail?.(err) options.complete?.(err) }, null) @@ -274,7 +275,7 @@ class AndroidFileSystemManager implements FileSystemManager { * invalid digestAlgorithm */ currentDispatcher.async(function (_) { - let err = new UniError(UniErrorSubject, 1300022, UniErrors.get(1300022)! + ":invalid digestAlgorithm " + options.digestAlgorithm); + let err = new FileSystemManagerFailImpl(1300022); options.fail?.(err) options.complete?.(err) }, null) @@ -340,57 +341,57 @@ class AndroidFileSystemManager implements FileSystemManager { byteArray = new ByteArray(byteLen) assetStream.read(byteArray); } catch (e) { - throw new UniError(UniErrorSubject, 1300201, msgPrefix + UniErrors.get(1300201)!); + throw new UniError(FileSystemManagerUniErrorSubject, 1300201, msgPrefix + FileSystemManagerUniErrors.get(1300201)!); } // 检查目标文件 let newFilePath = UTSAndroid.convert2AbsFullPath(destPath) let isSandyBox = isSandyBoxPath(newFilePath, false) if (!isSandyBox) { - throw new UniError(UniErrorSubject, 1300013, msgPrefix + UniErrors.get(1300013)!); + throw new UniError(FileSystemManagerUniErrorSubject, 1300013, msgPrefix + FileSystemManagerUniErrors.get(1300013)!); } let newFile = new File(newFilePath) if (newFile.getParentFile() != null && !newFile.getParentFile()!.exists()) { /** * 父文件不存在 */ - throw new UniError(UniErrorSubject, 1300002, msgPrefix + UniErrors.get(1300002)!) + throw new UniError(FileSystemManagerUniErrorSubject, 1300002, msgPrefix + FileSystemManagerUniErrors.get(1300002)!) } newFile.writeBytes(byteArray) if (!newFile.exists()) { // 调用系统api 失败 - throw new UniError(UniErrorSubject, 1300201, msgPrefix + UniErrors.get(1300201)!) + throw new UniError(FileSystemManagerUniErrorSubject, 1300201, msgPrefix + FileSystemManagerUniErrors.get(1300201)!) } } else { let isSandyBox = isSandyBoxPath(filePath, true) if (!isSandyBox) { - throw new UniError(UniErrorSubject, 1300013, msgPrefix + UniErrors.get(1300013)!) + throw new UniError(FileSystemManagerUniErrorSubject, 1300013, msgPrefix + FileSystemManagerUniErrors.get(1300013)!) } let targetFile = new File(filePath) if (!targetFile.exists()) { /** * 文件不存在 */ - throw new UniError(UniErrorSubject, 1300002, msgPrefix + UniErrors.get(1300002)!) + throw new UniError(FileSystemManagerUniErrorSubject, 1300002, msgPrefix + FileSystemManagerUniErrors.get(1300002)!) } // 检查目标文件 let newFilePath = UTSAndroid.convert2AbsFullPath(destPath) isSandyBox = isSandyBoxPath(newFilePath, false) if (!isSandyBox) { - throw new UniError(UniErrorSubject, 1300013, msgPrefix + UniErrors.get(1300013)!) + throw new UniError(FileSystemManagerUniErrorSubject, 1300013, msgPrefix + FileSystemManagerUniErrors.get(1300013)!) } let newFile = new File(newFilePath) if (newFile.getParentFile() != null && !newFile.getParentFile()!.exists()) { /** * 父文件不存在 */ - throw new UniError(UniErrorSubject, 1300002, msgPrefix + UniErrors.get(1300002)!) + throw new UniError(FileSystemManagerUniErrorSubject, 1300002, msgPrefix + FileSystemManagerUniErrors.get(1300002)!) } let copyRetFile = targetFile.copyTo(newFile, true) if (!copyRetFile.exists()) { // 调用系统api 失败 - throw new UniError(UniErrorSubject, 1300201, msgPrefix + UniErrors.get(1300201)!) + throw new UniError(FileSystemManagerUniErrorSubject, 1300201, msgPrefix + FileSystemManagerUniErrors.get(1300201)!) } } } @@ -421,7 +422,7 @@ class AndroidFileSystemManager implements FileSystemManager { if (exceptionInfo != null) { currentDispatcher.async(function (_) { - let err = new UniError(UniErrorSubject, 1300201, UniErrors.get(1300201)! + ":" + exceptionInfo.message); + let err = new FileSystemManagerFailImpl(1300201); options.fail?.(err) options.complete?.(err) }, null) @@ -434,7 +435,7 @@ class AndroidFileSystemManager implements FileSystemManager { let isSandyBox = isSandyBoxPath(newFilePath, false) if (!isSandyBox) { currentDispatcher.async(function (_) { - let err = new UniError(UniErrorSubject, 1300013, UniErrors.get(1300013)! + ":" + options.destPath); + let err = new FileSystemManagerFailImpl(1300013); options.fail?.(err) options.complete?.(err) }, null) @@ -446,7 +447,7 @@ class AndroidFileSystemManager implements FileSystemManager { * 父文件不存在 */ currentDispatcher.async(function (_) { - let err = new UniError(UniErrorSubject, 1300002, UniErrors.get(1300002)! + ":" + options.destPath); + let err = new FileSystemManagerFailImpl(1300002); options.fail?.(err) options.complete?.(err) }, null) @@ -456,7 +457,7 @@ class AndroidFileSystemManager implements FileSystemManager { if (!newFile.exists()) { // 调用系统api 失败 currentDispatcher.async(function (_) { - let err = new UniError(UniErrorSubject, 1300201, UniErrors.get(1300201)!); + let err = new FileSystemManagerFailImpl(1300201); options.fail?.(err) options.complete?.(err) }, null) @@ -475,7 +476,7 @@ class AndroidFileSystemManager implements FileSystemManager { let isSandyBox = isSandyBoxPath(filePath, true) if (!isSandyBox) { currentDispatcher.async(function (_) { - let err = new UniError(UniErrorSubject, 1300013, UniErrors.get(1300013)! + ":" + options.srcPath); + let err = new FileSystemManagerFailImpl(1300013); options.fail?.(err) options.complete?.(err) }, null) @@ -487,7 +488,7 @@ class AndroidFileSystemManager implements FileSystemManager { * 文件不存在 */ currentDispatcher.async(function (_) { - let err = new UniError(UniErrorSubject, 1300002, UniErrors.get(1300002)! + ":" + options.srcPath); + let err = new FileSystemManagerFailImpl(1300002); options.fail?.(err) options.complete?.(err) }, null) @@ -498,7 +499,7 @@ class AndroidFileSystemManager implements FileSystemManager { isSandyBox = isSandyBoxPath(newFilePath, false) if (!isSandyBox) { currentDispatcher.async(function (_) { - let err = new UniError(UniErrorSubject, 1300013, UniErrors.get(1300013)! + ":" + options.destPath); + let err = new FileSystemManagerFailImpl(1300013); options.fail?.(err) options.complete?.(err) }, null) @@ -510,7 +511,7 @@ class AndroidFileSystemManager implements FileSystemManager { * 父文件不存在 */ currentDispatcher.async(function (_) { - let err = new UniError(UniErrorSubject, 1300002, UniErrors.get(1300002)! + ":" + options.destPath); + let err = new FileSystemManagerFailImpl(1300002); options.fail?.(err) options.complete?.(err) }) @@ -521,7 +522,7 @@ class AndroidFileSystemManager implements FileSystemManager { if (!copyRetFile.exists()) { // 调用系统api 失败 currentDispatcher.async(function (_) { - let err = new UniError(UniErrorSubject, 1300201, UniErrors.get(1300201)!); + let err = new FileSystemManagerFailImpl(1300201); options.fail?.(err) options.complete?.(err) }) @@ -547,7 +548,7 @@ class AndroidFileSystemManager implements FileSystemManager { let filePath = UTSAndroid.convert2AbsFullPath(oldPath) let isSandyBox = isSandyBoxPath(filePath, false) if (!isSandyBox) { - throw new UniError(UniErrorSubject, 1300013, msgPrefix + UniErrors.get(1301003)!); + throw new UniError(FileSystemManagerUniErrorSubject, 1300013, msgPrefix + FileSystemManagerUniErrors.get(1301003)!); } let targetFile = new File(filePath) @@ -555,12 +556,12 @@ class AndroidFileSystemManager implements FileSystemManager { /** * 文件不存在 */ - throw new UniError(UniErrorSubject, 1300002, msgPrefix + UniErrors.get(1300002)!) + throw new UniError(FileSystemManagerUniErrorSubject, 1300002, msgPrefix + FileSystemManagerUniErrors.get(1300002)!) } let newFilePath = UTSAndroid.convert2AbsFullPath(newPath) isSandyBox = isSandyBoxPath(newFilePath, false) if (!isSandyBox) { - throw new UniError(UniErrorSubject, 1300013, msgPrefix + UniErrors.get(1300013)!) + throw new UniError(FileSystemManagerUniErrorSubject, 1300013, msgPrefix + FileSystemManagerUniErrors.get(1300013)!) } let newFile = new File(newFilePath) @@ -568,14 +569,14 @@ class AndroidFileSystemManager implements FileSystemManager { /** * 父文件不存在 */ - throw new UniError(UniErrorSubject, 1300002, msgPrefix + UniErrors.get(1300002)!) + throw new UniError(FileSystemManagerUniErrorSubject, 1300002, msgPrefix + FileSystemManagerUniErrors.get(1300002)!) } let renameRet = targetFile.renameTo(newFile) if (!renameRet) { // 调用系统api 失败 - throw new UniError(UniErrorSubject, 1300201, msgPrefix + UniErrors.get(1300201)!) + throw new UniError(FileSystemManagerUniErrorSubject, 1300201, msgPrefix + FileSystemManagerUniErrors.get(1300201)!) } } @@ -588,7 +589,7 @@ class AndroidFileSystemManager implements FileSystemManager { let isSandyBox = isSandyBoxPath(filePath, false) if (!isSandyBox) { currentDispatcher.async(function (_) { - let err = new UniError(UniErrorSubject, 1300013, UniErrors.get(1300013)! + ":" + options.oldPath); + let err = new FileSystemManagerFailImpl(1300013); options.fail?.(err) options.complete?.(err) }) @@ -601,7 +602,7 @@ class AndroidFileSystemManager implements FileSystemManager { * 文件不存在 */ currentDispatcher.async(function (_) { - let err = new UniError(UniErrorSubject, 1300002, UniErrors.get(1300002)! + ":" + options.oldPath); + let err = new FileSystemManagerFailImpl(1300002); options.fail?.(err) options.complete?.(err) }) @@ -611,7 +612,7 @@ class AndroidFileSystemManager implements FileSystemManager { isSandyBox = isSandyBoxPath(newFilePath, false) if (!isSandyBox) { currentDispatcher.async(function (_) { - let err = new UniError(UniErrorSubject, 1300013, UniErrors.get(1300013)! + ":" + options.newPath); + let err = new FileSystemManagerFailImpl(1300013); options.fail?.(err) options.complete?.(err) }) @@ -624,7 +625,7 @@ class AndroidFileSystemManager implements FileSystemManager { * 父文件不存在 */ currentDispatcher.async(function (_) { - let err = new UniError(UniErrorSubject, 1300002, UniErrors.get(1300002)! + ":" + options.newPath); + let err = new FileSystemManagerFailImpl(1300002); options.fail?.(err) options.complete?.(err) }) @@ -636,7 +637,7 @@ class AndroidFileSystemManager implements FileSystemManager { if (!renameRet) { // 调用系统api 失败 currentDispatcher.async(function (_) { - let err = new UniError(UniErrorSubject, 1300201, UniErrors.get(1300201)!); + let err = new FileSystemManagerFailImpl(1300201); options.fail?.(err) options.complete?.(err) }) @@ -660,14 +661,14 @@ class AndroidFileSystemManager implements FileSystemManager { let targetFile = new File(filePath) let isSandyBox = isSandyBoxPath(filePath, true) if (!isSandyBox) { - throw new UniError(UniErrorSubject, 1300013, msgPrefix + UniErrors.get(1300013)!) + throw new UniError(FileSystemManagerUniErrorSubject, 1300013, msgPrefix + FileSystemManagerUniErrors.get(1300013)!) } if (!targetFile.exists()) { /** * 文件不存在,或者不是文件夹,异常 */ - throw new UniError(UniErrorSubject, 1300002, msgPrefix + UniErrors.get(1300002)!) + throw new UniError(FileSystemManagerUniErrorSubject, 1300002, msgPrefix + FileSystemManagerUniErrors.get(1300002)!) } } @@ -682,7 +683,7 @@ class AndroidFileSystemManager implements FileSystemManager { let isSandyBox = isSandyBoxPath(filePath, true) if (!isSandyBox) { currentDispatcher.async(function (_) { - let err = new UniError(UniErrorSubject, 1300013, UniErrors.get(1300013)! + ":" + options.path); + let err = new FileSystemManagerFailImpl(1300013); options.fail?.(err) options.complete?.(err) }) @@ -694,7 +695,7 @@ class AndroidFileSystemManager implements FileSystemManager { * 文件不存在,或者不是文件夹,异常 */ currentDispatcher.async(function (_) { - let err = new UniError(UniErrorSubject, 1300002, UniErrors.get(1300002)! + ":" + options.path); + let err = new FileSystemManagerFailImpl(1300002); options.fail?.(err) options.complete?.(err) }) @@ -720,7 +721,7 @@ class AndroidFileSystemManager implements FileSystemManager { let filePath = UTSAndroid.convert2AbsFullPath(dirPath) let isSandyBox = isSandyBoxPath(filePath, true) if (!isSandyBox) { - throw new UniError(UniErrorSubject, 1300013, msgPrefix + UniErrors.get(1300013)!) + throw new UniError(FileSystemManagerUniErrorSubject, 1300013, msgPrefix + FileSystemManagerUniErrors.get(1300013)!) } let targetFile = new File(filePath) @@ -728,7 +729,7 @@ class AndroidFileSystemManager implements FileSystemManager { /** * 文件不存在,或者不是文件夹,异常 */ - throw new UniError(UniErrorSubject, 1300002, msgPrefix + UniErrors.get(1300002)!) + throw new UniError(FileSystemManagerUniErrorSubject, 1300002, msgPrefix + FileSystemManagerUniErrors.get(1300002)!) } return UTSArray.fromNative(targetFile.list()!) } @@ -741,7 +742,7 @@ class AndroidFileSystemManager implements FileSystemManager { let isSandyBox = isSandyBoxPath(filePath, true) if (!isSandyBox) { currentDispatcher.async(function (_) { - let err = new UniError(UniErrorSubject, 1300013, UniErrors.get(1300013)! + ":" + options.dirPath); + let err = new FileSystemManagerFailImpl(1300013); options.fail?.(err) options.complete?.(err) }) @@ -754,7 +755,7 @@ class AndroidFileSystemManager implements FileSystemManager { * 文件不存在,或者不是文件夹,异常 */ currentDispatcher.async(function (_) { - let err = new UniError(UniErrorSubject, 1300002, UniErrors.get(1300002)! + ":" + options.dirPath); + let err = new FileSystemManagerFailImpl(1300002); options.fail?.(err) options.complete?.(err) }) @@ -777,14 +778,14 @@ class AndroidFileSystemManager implements FileSystemManager { let targetFile = new File(filePath) let isSandyBox = isSandyBoxPath(filePath, false) if (!isSandyBox) { - throw new UniError(UniErrorSubject, 1300013, msgPrefix + UniErrors.get(1300013)!) + throw new UniError(FileSystemManagerUniErrorSubject, 1300013, msgPrefix + FileSystemManagerUniErrors.get(1300013)!) } if (!targetFile.exists() || !targetFile.isDirectory()) { /** * 文件不存在 或者 文件是不是文件夹 */ - throw new UniError(UniErrorSubject, 1300002, msgPrefix + UniErrors.get(1300002)!) + throw new UniError(FileSystemManagerUniErrorSubject, 1300002, msgPrefix + FileSystemManagerUniErrors.get(1300002)!) } @@ -793,13 +794,13 @@ class AndroidFileSystemManager implements FileSystemManager { let childList = targetFile.list() if (childList != null && childList.size > 0) { // 存在子目录 - throw new UniError(UniErrorSubject, 1300066, msgPrefix + UniErrors.get(1300066)!) + throw new UniError(FileSystemManagerUniErrorSubject, 1300066, msgPrefix + FileSystemManagerUniErrors.get(1300066)!) } } else { let delRet = targetFile.deleteRecursively() if (!delRet) { // 调用系统api 失败 - throw new UniError(UniErrorSubject, 1300201, msgPrefix + UniErrors.get(1300201)!) + throw new UniError(FileSystemManagerUniErrorSubject, 1300201, msgPrefix + FileSystemManagerUniErrors.get(1300201)!) } } } @@ -807,31 +808,31 @@ class AndroidFileSystemManager implements FileSystemManager { public mkdirSync(dirPath : string, recursive : boolean) : void { let msgPrefix = "mkdirSync:fail " if (dirPath.isEmpty()) { - throw new UniError(UniErrorSubject, 1300066, msgPrefix + UniErrors.get(1300066)!) + throw new UniError(FileSystemManagerUniErrorSubject, 1300066, msgPrefix + FileSystemManagerUniErrors.get(1300066)!) } let filePath = UTSAndroid.convert2AbsFullPath(dirPath) let isSandyBox = isSandyBoxPath(filePath, false) if (!isSandyBox) { - throw new UniError(UniErrorSubject, 1300013, msgPrefix + UniErrors.get(1300013)!) + throw new UniError(FileSystemManagerUniErrorSubject, 1300013, msgPrefix + FileSystemManagerUniErrors.get(1300013)!) } let targetFile = new File(filePath) if (targetFile.exists()) { /** * 文件已经存在,则无法继续创建 */ - throw new UniError(UniErrorSubject, 1301005, msgPrefix + UniErrors.get(1301005)!) + throw new UniError(FileSystemManagerUniErrorSubject, 1301005, msgPrefix + FileSystemManagerUniErrors.get(1301005)!) } if (!recursive) { // 没有设置递归创建 if (targetFile.getParentFile() == null || !targetFile.getParentFile()!.exists()) { - throw new UniError(UniErrorSubject, 1300002, msgPrefix + UniErrors.get(1300002)!) + throw new UniError(FileSystemManagerUniErrorSubject, 1300002, msgPrefix + FileSystemManagerUniErrors.get(1300002)!) } else { // 父文件夹存在,则继续创建 let mkRet = targetFile.mkdir() if (!mkRet) { // 调用系统api 失败 - throw new UniError(UniErrorSubject, 1300201, msgPrefix + UniErrors.get(1300201)!) + throw new UniError(FileSystemManagerUniErrorSubject, 1300201, msgPrefix + FileSystemManagerUniErrors.get(1300201)!) } } } else { @@ -839,7 +840,7 @@ class AndroidFileSystemManager implements FileSystemManager { let mkRet = targetFile.mkdirs() if (!mkRet) { // 调用系统api 失败 - throw new UniError(UniErrorSubject, 1300201, msgPrefix + UniErrors.get(1300201)!) + throw new UniError(FileSystemManagerUniErrorSubject, 1300201, msgPrefix + FileSystemManagerUniErrors.get(1300201)!) } } } @@ -855,7 +856,7 @@ class AndroidFileSystemManager implements FileSystemManager { let isSandyBox = isSandyBoxPath(filePath, false) if (!isSandyBox) { currentDispatcher.async(function (_) { - let err = new UniError(UniErrorSubject, 1300013, UniErrors.get(1300013)! + ":" + options.dirPath); + let err = new FileSystemManagerFailImpl(1300013); options.fail?.(err) options.complete?.(err) }) @@ -867,7 +868,7 @@ class AndroidFileSystemManager implements FileSystemManager { * 文件不存在 或者 文件是不是文件夹 */ currentDispatcher.async(function (_) { - let err = new UniError(UniErrorSubject, 1300002, UniErrors.get(1300002)! + ":" + options.dirPath); + let err = new FileSystemManagerFailImpl(1300002); options.fail?.(err) options.complete?.(err) }) @@ -881,7 +882,7 @@ class AndroidFileSystemManager implements FileSystemManager { if (childList != null && childList.size > 0) { // 存在子目录 currentDispatcher.async(function (_) { - let err = new UniError(UniErrorSubject, 1300066, UniErrors.get(1300066)! + ":" + options.dirPath); + let err = new FileSystemManagerFailImpl(1300066); options.fail?.(err) options.complete?.(err) }) @@ -893,7 +894,7 @@ class AndroidFileSystemManager implements FileSystemManager { if (!delRet) { // 调用系统api 失败 currentDispatcher.async(function (_) { - let err = new UniError(UniErrorSubject, 1300201, UniErrors.get(1300201)! + ":" + options.dirPath); + let err = new FileSystemManagerFailImpl(1300201); options.fail?.(err) options.complete?.(err) }) @@ -922,7 +923,7 @@ class AndroidFileSystemManager implements FileSystemManager { if (options.dirPath.isEmpty()) { currentDispatcher.async(function (_) { - let err = new UniError(UniErrorSubject, 1300066, UniErrors.get(1300066)!); + let err = new FileSystemManagerFailImpl(1300066); options.fail?.(err) options.complete?.(err) }) @@ -933,7 +934,7 @@ class AndroidFileSystemManager implements FileSystemManager { let isSandyBox = isSandyBoxPath(filePath, false) if (!isSandyBox) { currentDispatcher.async(function (_) { - let err = new UniError(UniErrorSubject, 1300013, UniErrors.get(1300013)! + ":" + options.dirPath); + let err = new FileSystemManagerFailImpl(1300013); options.fail?.(err) options.complete?.(err) }) @@ -946,7 +947,7 @@ class AndroidFileSystemManager implements FileSystemManager { * 文件已经存在,则无法继续创建 */ currentDispatcher.async(function (_) { - let err = new UniError(UniErrorSubject, 1301005, UniErrors.get(1301005)! + ":" + options.dirPath); + let err = new FileSystemManagerFailImpl(1301005); options.fail?.(err) options.complete?.(err) }) @@ -957,7 +958,7 @@ class AndroidFileSystemManager implements FileSystemManager { // 没有设置递归创建 if (targetFile.getParentFile() == null || !targetFile.getParentFile()!.exists()) { currentDispatcher.async(function (_) { - let err = new UniError(UniErrorSubject, 1300002, UniErrors.get(1300002)! + ":" + options.dirPath); + let err = new FileSystemManagerFailImpl(1300002); options.fail?.(err) options.complete?.(err) }) @@ -968,7 +969,7 @@ class AndroidFileSystemManager implements FileSystemManager { if (!mkRet) { // 调用系统api 失败 currentDispatcher.async(function (_) { - let err = new UniError(UniErrorSubject, 1300201, UniErrors.get(1300201)! + ":" + options.dirPath); + let err = new FileSystemManagerFailImpl(1300201); options.fail?.(err) options.complete?.(err) }) @@ -982,7 +983,7 @@ class AndroidFileSystemManager implements FileSystemManager { if (!mkRet) { // 调用系统api 失败 currentDispatcher.async(function (_) { - let err = new UniError(UniErrorSubject, 1300201, UniErrors.get(1300201)! + ":" + options.dirPath); + let err = new FileSystemManagerFailImpl(1300201); options.fail?.(err) options.complete?.(err) }) @@ -1010,19 +1011,19 @@ class AndroidFileSystemManager implements FileSystemManager { let temFilePath = UTSAndroid.convert2AbsFullPath(filePath) let isSandyBox = isSandyBoxPath(temFilePath, false) if (!isSandyBox) { - throw new UniError(UniErrorSubject, 1300013, msgPrefix + UniErrors.get(1300013)!) + throw new UniError(FileSystemManagerUniErrorSubject, 1300013, msgPrefix + FileSystemManagerUniErrors.get(1300013)!) } let targetFile = new File(temFilePath) if (!targetFile.exists()) { - throw new UniError(UniErrorSubject, 1300002, msgPrefix + UniErrors.get(1300002)!) + throw new UniError(FileSystemManagerUniErrorSubject, 1300002, msgPrefix + FileSystemManagerUniErrors.get(1300002)!) } // 文件存在,则进行删除操作 let delRet = targetFile.delete() if (!delRet) { // 调用系统api 删除失败 - throw new UniError(UniErrorSubject, 1300201, msgPrefix + UniErrors.get(1300201)!) + throw new UniError(FileSystemManagerUniErrorSubject, 1300201, msgPrefix + FileSystemManagerUniErrors.get(1300201)!) } } @@ -1040,7 +1041,7 @@ class AndroidFileSystemManager implements FileSystemManager { let isSandyBox = isSandyBoxPath(filePath, false) if (!isSandyBox) { currentDispatcher.async(function (_) { - let err = new UniError(UniErrorSubject, 1300013, UniErrors.get(1300013)! + ":" + options.filePath); + let err = new FileSystemManagerFailImpl(1300013); options.fail?.(err) options.complete?.(err) }) @@ -1050,7 +1051,7 @@ class AndroidFileSystemManager implements FileSystemManager { let targetFile = new File(filePath) if (!targetFile.exists()) { currentDispatcher.async(function (_) { - let err = new UniError(UniErrorSubject, 1300002, UniErrors.get(1300002)! + ":" + options.filePath); + let err = new FileSystemManagerFailImpl(1300002); options.fail?.(err) options.complete?.(err) }) @@ -1062,7 +1063,7 @@ class AndroidFileSystemManager implements FileSystemManager { if (!delRet) { // 调用系统api 删除失败 currentDispatcher.async(function (_) { - let err = new UniError(UniErrorSubject, 1300201, UniErrors.get(1300201)! + ":" + options.filePath); + let err = new FileSystemManagerFailImpl(1300201); options.fail?.(err) options.complete?.(err) }) @@ -1091,7 +1092,7 @@ class AndroidFileSystemManager implements FileSystemManager { tempEncoding = "utf-8" } if (tempEncoding.toLowerCase() != 'base64' && tempEncoding.toLowerCase() != 'utf-8' && tempEncoding.toLowerCase() != 'ascii') { - throw new UniError(UniErrorSubject, 1200002, msgPrefix + UniErrors.get(1200002)!) + throw new UniError(FileSystemManagerUniErrorSubject, 1200002, msgPrefix + FileSystemManagerUniErrors.get(1200002)!) } let tempFilePath = UTSAndroid.convert2AbsFullPath(filePath) if (tempFilePath.startsWith("/android_asset/")) { @@ -1103,7 +1104,7 @@ class AndroidFileSystemManager implements FileSystemManager { byteArray = new ByteArray(byteLen) assetStream.read(byteArray); } catch (e : Exception) { - throw new UniError(UniErrorSubject, 1300201, msgPrefix + UniErrors.get(1300201)! + ":" + filePath) + throw new UniError(FileSystemManagerUniErrorSubject, 1300201, msgPrefix + FileSystemManagerUniErrors.get(1300201)! + ":" + filePath) } if (tempEncoding.toLowerCase() == 'base64') { @@ -1129,18 +1130,18 @@ class AndroidFileSystemManager implements FileSystemManager { let targetFile = new File(tempFilePath) if (!targetFile.exists()) { - throw new UniError(UniErrorSubject, 1300002, msgPrefix + UniErrors.get(1300002)! + ":" + filePath); + throw new UniError(FileSystemManagerUniErrorSubject, 1300002, msgPrefix + FileSystemManagerUniErrors.get(1300002)! + ":" + filePath); } if (targetFile.isDirectory()) { - throw new UniError(UniErrorSubject, 1301003, msgPrefix + UniErrors.get(1301003)! + ":" + filePath); + throw new UniError(FileSystemManagerUniErrorSubject, 1301003, msgPrefix + FileSystemManagerUniErrors.get(1301003)! + ":" + filePath); } /** * 文件超过100M,会超过应用内存 */ if (targetFile.length() > 100 * 1024 * 1024) { - throw new UniError(UniErrorSubject, 1300202, msgPrefix + UniErrors.get(1300202)! + ":" + filePath); + throw new UniError(FileSystemManagerUniErrorSubject, 1300202, msgPrefix + FileSystemManagerUniErrors.get(1300202)! + ":" + filePath); } if (tempEncoding.toLowerCase() == 'base64') { @@ -1166,7 +1167,7 @@ class AndroidFileSystemManager implements FileSystemManager { // 判断type 是否合法 if (options.encoding.toLowerCase() != 'base64' && options.encoding.toLowerCase() != 'utf-8' && options.encoding.toLowerCase() != 'ascii') { - let err = new UniError(UniErrorSubject, 1200002, UniErrors.get(1200002)!); + let err = new FileSystemManagerFailImpl(1200002); options.fail?.(err) options.complete?.(err) return @@ -1199,7 +1200,7 @@ class AndroidFileSystemManager implements FileSystemManager { if (exceptionInfo != null) { currentDispatcher.async(function (_) { - let err = new UniError(UniErrorSubject, 1300201, UniErrors.get(1300201)! + ":" + exceptionInfo.message); + let err = new FileSystemManagerFailImpl(1300201); options.fail?.(err) options.complete?.(err) }) @@ -1237,7 +1238,7 @@ class AndroidFileSystemManager implements FileSystemManager { let isSandyBox = isSandyBoxPath(filePath, true) if (!isSandyBox) { currentDispatcher.async(function (_) { - let err = new UniError(UniErrorSubject, 1300013, UniErrors.get(1300013)! + ":" + options.filePath); + let err = new FileSystemManagerFailImpl(1300013); options.fail?.(err) options.complete?.(err) }) @@ -1247,7 +1248,7 @@ class AndroidFileSystemManager implements FileSystemManager { let targetFile = new File(filePath) if (!targetFile.exists()) { currentDispatcher.async(function (_) { - let err = new UniError(UniErrorSubject, 1300002, UniErrors.get(1300002)! + ":" + options.filePath); + let err = new FileSystemManagerFailImpl(1300002); options.fail?.(err) options.complete?.(err) }) @@ -1256,7 +1257,7 @@ class AndroidFileSystemManager implements FileSystemManager { if (targetFile.isDirectory()) { currentDispatcher.async(function (_) { - let err = new UniError(UniErrorSubject, 1301003, UniErrors.get(1301003)!); + let err = new FileSystemManagerFailImpl(1301003); options.fail?.(err) options.complete?.(err) }) @@ -1268,7 +1269,7 @@ class AndroidFileSystemManager implements FileSystemManager { */ if (targetFile.length() > 100 * 1024 * 1024) { currentDispatcher.async(function (_) { - let err = new UniError(UniErrorSubject, 1300202, UniErrors.get(1300202)!); + let err = new FileSystemManagerFailImpl(1300202); options.fail?.(err) options.complete?.(err) }) @@ -1311,7 +1312,7 @@ class AndroidFileSystemManager implements FileSystemManager { let msgPrefix = "writeFileSync:fail " let tempEncoding = encoding if (tempEncoding.toLowerCase() != 'base64' && tempEncoding.toLowerCase() != 'utf-8' && tempEncoding.toLowerCase() != 'ascii') { - throw new UniError(UniErrorSubject, 1200002, msgPrefix + UniErrors.get(1200002)!) + throw new UniError(FileSystemManagerUniErrorSubject, 1200002, msgPrefix + FileSystemManagerUniErrors.get(1200002)!) } // 判断type 是否合法 @@ -1319,13 +1320,13 @@ class AndroidFileSystemManager implements FileSystemManager { let isSandyBox = isSandyBoxPath(tempFilePath, false) if (!isSandyBox) { - throw new UniError(UniErrorSubject, 1300013, msgPrefix + UniErrors.get(1300013)!) + throw new UniError(FileSystemManagerUniErrorSubject, 1300013, msgPrefix + FileSystemManagerUniErrors.get(1300013)!) } let nextFile = new File(tempFilePath) if (nextFile.exists() && nextFile.isDirectory()) { - throw new UniError(UniErrorSubject, 1301003, msgPrefix + UniErrors.get(1301003)!) + throw new UniError(FileSystemManagerUniErrorSubject, 1301003, msgPrefix + FileSystemManagerUniErrors.get(1301003)!) } /** @@ -1363,7 +1364,7 @@ class AndroidFileSystemManager implements FileSystemManager { public writeFile(options : WriteFileOptions) { if (options.encoding.toLowerCase() != 'base64' && options.encoding.toLowerCase() != 'utf-8' && options.encoding.toLowerCase() != 'ascii') { - let err = new UniError(UniErrorSubject, 1200002, UniErrors.get(1200002)!); + let err = new FileSystemManagerFailImpl(1200002); options.fail?.(err) options.complete?.(err) return @@ -1374,7 +1375,7 @@ class AndroidFileSystemManager implements FileSystemManager { let isSandyBox = isSandyBoxPath(filePath, false) if (!isSandyBox) { - let err = new UniError(UniErrorSubject, 1300013, UniErrors.get(1300013)! + ":" + options.filePath); + let err = new FileSystemManagerFailImpl(1300013); options.fail?.(err) options.complete?.(err) return @@ -1384,7 +1385,7 @@ class AndroidFileSystemManager implements FileSystemManager { if (nextFile.exists() && nextFile.isDirectory()) { // 出错了,目标文件已存在,并且是个目录 - let err = new UniError(UniErrorSubject, 1301003, UniErrors.get(1301003)!); + let err = new FileSystemManagerFailImpl(1301003); options.fail?.(err) options.complete?.(err) return @@ -1439,20 +1440,20 @@ class AndroidFileSystemManager implements FileSystemManager { let msgPrefix = "appendFileSync:fail " let tempEncoding = encoding if (tempEncoding.toLowerCase() != 'base64' && tempEncoding.toLowerCase() != 'utf-8' && tempEncoding.toLowerCase() != 'ascii') { - throw new UniError(UniErrorSubject, 1200002, msgPrefix + UniErrors.get(1200002)!) + throw new UniError(FileSystemManagerUniErrorSubject, 1200002, msgPrefix + FileSystemManagerUniErrors.get(1200002)!) } // 判断type 是否合法 let tempFilePath = UTSAndroid.convert2AbsFullPath(filePath) let isSandyBox = isSandyBoxPath(tempFilePath, false) if (!isSandyBox) { - throw new UniError(UniErrorSubject, 1300013, msgPrefix + UniErrors.get(1300013)!) + throw new UniError(FileSystemManagerUniErrorSubject, 1300013, msgPrefix + FileSystemManagerUniErrors.get(1300013)!) } let nextFile = new File(tempFilePath) if (!nextFile.exists()) { - throw new UniError(UniErrorSubject, 1300002, msgPrefix + UniErrors.get(1300002)!) + throw new UniError(FileSystemManagerUniErrorSubject, 1300002, msgPrefix + FileSystemManagerUniErrors.get(1300002)!) } else if (nextFile.isDirectory()) { // 出错了,目标文件已存在,并且是个目录 - throw new UniError(UniErrorSubject, 1301003, msgPrefix + UniErrors.get(1301003)!) + throw new UniError(FileSystemManagerUniErrorSubject, 1301003, msgPrefix + FileSystemManagerUniErrors.get(1301003)!) } // 写入文本,根据不同的编码内容写入不同的数据 if (tempEncoding.toLowerCase() == 'ascii') { @@ -1477,7 +1478,7 @@ class AndroidFileSystemManager implements FileSystemManager { public appendFile(options : AppendFileOptions) { if (options.encoding.toLowerCase() != 'base64' && options.encoding.toLowerCase() != 'utf-8' && options.encoding.toLowerCase() != 'ascii') { - let err = new UniError(UniErrorSubject, 1200002, UniErrors.get(1200002)!); + let err = new FileSystemManagerFailImpl(1200002); options.fail?.(err) options.complete?.(err) return @@ -1488,7 +1489,7 @@ class AndroidFileSystemManager implements FileSystemManager { let isSandyBox = isSandyBoxPath(filePath, false) if (!isSandyBox) { - let err = new UniError(UniErrorSubject, 1300013, UniErrors.get(1300013)! + ":" + options.filePath); + let err = new FileSystemManagerFailImpl(1300013); options.fail?.(err) options.complete?.(err) return @@ -1498,13 +1499,13 @@ class AndroidFileSystemManager implements FileSystemManager { if (!nextFile.exists()) { - let err = new UniError(UniErrorSubject, 1300002, UniErrors.get(1300002)!); + let err = new FileSystemManagerFailImpl(1300002); options.fail?.(err) options.complete?.(err) return } else if (nextFile.isDirectory()) { // 出错了,目标文件已存在,并且是个目录 - let err = new UniError(UniErrorSubject, 1301003, UniErrors.get(1301003)!); + let err = new FileSystemManagerFailImpl(1301003); options.fail?.(err) options.complete?.(err) return @@ -1556,7 +1557,7 @@ class AndroidFileSystemManager implements FileSystemManager { && optFlag != 'w+' && optFlag != 'wx' && optFlag != 'wx+') { - let err = new UniError(UniErrorSubject, 1302003, UniErrors.get(1302003)!); + let err = new FileSystemManagerFailImpl(1302003); options.fail?.(err) options.complete?.(err) return @@ -1566,7 +1567,7 @@ class AndroidFileSystemManager implements FileSystemManager { let isSandyBox = isSandyBoxPath(filePath, false) if (!isSandyBox) { - let err = new UniError(UniErrorSubject, 1300013, UniErrors.get(1300013)! + ":" + options.filePath); + let err = new FileSystemManagerFailImpl(1300013); options.fail?.(err) options.complete?.(err) return @@ -1589,14 +1590,14 @@ class AndroidFileSystemManager implements FileSystemManager { && optFlag != 'w+' && optFlag != 'wx' && optFlag != 'wx+') { - throw new UniError(UniErrorSubject, 1302003, msgPrefix + UniErrors.get(1302003)!) + throw new UniError(FileSystemManagerUniErrorSubject, 1302003, msgPrefix + FileSystemManagerUniErrors.get(1302003)!) } let filePath = UTSAndroid.convert2AbsFullPath(options.filePath) let isSandyBox = isSandyBoxPath(filePath, false) if (!isSandyBox) { - throw new UniError(UniErrorSubject, 1300013, msgPrefix + UniErrors.get(1300013)!) + throw new UniError(FileSystemManagerUniErrorSubject, 1300013, msgPrefix + FileSystemManagerUniErrors.get(1300013)!) } return this.fileDesUtil.openSync(options, new File(filePath)) } @@ -1610,7 +1611,7 @@ class AndroidFileSystemManager implements FileSystemManager { if (!isSandyBox) { currentDispatcher.async(function (_) { - let err = new UniError(UniErrorSubject, 1300013, UniErrors.get(1300013)! + ":" + options.tempFilePath); + let err = new FileSystemManagerFailImpl(1300013); options.fail?.(err) options.complete?.(err) }, null) @@ -1622,7 +1623,7 @@ class AndroidFileSystemManager implements FileSystemManager { * 文件不存在 */ currentDispatcher.async(function (_) { - let err = new UniError(UniErrorSubject, 1300002, UniErrors.get(1300002)! + ":" + options.tempFilePath); + let err = new FileSystemManagerFailImpl(1300002); options.fail?.(err) options.complete?.(err) }, null) @@ -1637,7 +1638,7 @@ class AndroidFileSystemManager implements FileSystemManager { isSandyBox = isSandyBoxPath(newFilePath, false) if (!isSandyBox) { currentDispatcher.async(function (_) { - let err = new UniError(UniErrorSubject, 1300013, UniErrors.get(1300013)! + ":" + options.filePath); + let err = new FileSystemManagerFailImpl(1300013); options.fail?.(err) options.complete?.(err) }, null) @@ -1650,7 +1651,7 @@ class AndroidFileSystemManager implements FileSystemManager { * 父文件不存在 */ currentDispatcher.async(function (_) { - let err = new UniError(UniErrorSubject, 1300002, UniErrors.get(1300002)! + ":" + options.filePath); + let err = new FileSystemManagerFailImpl(1300002); options.fail?.(err) options.complete?.(err) }, null) @@ -1661,7 +1662,7 @@ class AndroidFileSystemManager implements FileSystemManager { if (!copyRetFile.exists()) { // 调用系统api 失败 currentDispatcher.async(function (_) { - let err = new UniError(UniErrorSubject, 1300201, UniErrors.get(1300201)!); + let err = new FileSystemManagerFailImpl(1300201); options.fail?.(err) options.complete?.(err) }, null) @@ -1686,14 +1687,14 @@ class AndroidFileSystemManager implements FileSystemManager { let isSandyBox = isSandyBoxPath(tfPath, true) if (!isSandyBox) { - throw new UniError(UniErrorSubject, 1300013, msgPrefix + UniErrors.get(1300013)!) + throw new UniError(FileSystemManagerUniErrorSubject, 1300013, msgPrefix + FileSystemManagerUniErrors.get(1300013)!) } let targetFile = new File(tfPath) if (!targetFile.exists()) { /** * 文件不存在 */ - throw new UniError(UniErrorSubject, 1300002, msgPrefix + UniErrors.get(1300002)!) + throw new UniError(FileSystemManagerUniErrorSubject, 1300002, msgPrefix + FileSystemManagerUniErrors.get(1300002)!) } let fp = filePath if (fp == null) { @@ -1703,7 +1704,7 @@ class AndroidFileSystemManager implements FileSystemManager { let newFilePath = UTSAndroid.convert2AbsFullPath(fp + targetFile.getName()) isSandyBox = isSandyBoxPath(newFilePath, false) if (!isSandyBox) { - throw new UniError(UniErrorSubject, 1300013, msgPrefix + UniErrors.get(1300013)!) + throw new UniError(FileSystemManagerUniErrorSubject, 1300013, msgPrefix + FileSystemManagerUniErrors.get(1300013)!) } let newFile = new File(newFilePath) console.log(newFile.getPath()) @@ -1711,13 +1712,13 @@ class AndroidFileSystemManager implements FileSystemManager { /** * 父文件不存在 */ - throw new UniError(UniErrorSubject, 1300002, msgPrefix + UniErrors.get(1300002)!) + throw new UniError(FileSystemManagerUniErrorSubject, 1300002, msgPrefix + FileSystemManagerUniErrors.get(1300002)!) } let copyRetFile = targetFile.copyTo(newFile, true) if (!copyRetFile.exists()) { // 调用系统api 失败 - throw new UniError(UniErrorSubject, 1300201, msgPrefix + UniErrors.get(1300201)!) + throw new UniError(FileSystemManagerUniErrorSubject, 1300201, msgPrefix + FileSystemManagerUniErrors.get(1300201)!) } targetFile.delete() return newFilePath @@ -1726,56 +1727,73 @@ class AndroidFileSystemManager implements FileSystemManager { let msgPrefix = "unzip:fail " // 检查来源文件 let zipFilePath = UTSAndroid.convert2AbsFullPath(options.zipFilePath) - let isSandyBox = isSandyBoxPath(zipFilePath, true) + let currentDispatcher = UTSAndroid.getDispatcher("main") UTSAndroid.getDispatcher('io').async(function (_) { - if (!isSandyBox) { - currentDispatcher.async(function (_) { - let err = new UniError(UniErrorSubject, 1300013, UniErrors.get(1300013)! + ":" + options.zipFilePath); - options.fail?.(err) - options.complete?.(err) - }, null) - return - } - let zipFile = new File(zipFilePath) - if (!zipFile.exists()) { - /** - * 文件不存在 - */ - currentDispatcher.async(function (_) { - let err = new UniError(UniErrorSubject, 1300002, UniErrors.get(1300002)! + ":" + options.zipFilePath); - options.fail?.(err) - options.complete?.(err) - }, null) - return - } - + let is:InputStream; let targetPath = UTSAndroid.convert2AbsFullPath(options.targetPath) - isSandyBox = isSandyBoxPath(targetPath, true) - let targetFile = new File(targetPath) - if (!isSandyBox) { - currentDispatcher.async(function (_) { - let err = new UniError(UniErrorSubject, 1300013, UniErrors.get(1300013)! + ":" + options.zipFilePath); - options.fail?.(err) - options.complete?.(err) - }, null) - return - - } - if (!targetFile.exists() || !targetFile.isDirectory()) { - currentDispatcher.async(function (_) { - let err = new UniError(UniErrorSubject, 1300002, UniErrors.get(1300002)! + ":" + options.zipFilePath); - options.fail?.(err) - options.complete?.(err) - }, null) - return + if (zipFilePath.startsWith("/android_asset/")) { + try { + let assetName = zipFilePath.substring("/android_asset/".length) + is = UTSAndroid.getAppContext()!.getResources().getAssets().open(assetName); + } catch (e : Exception) { + /** + * 文件不存在 + */ + currentDispatcher.async(function (_) { + let err = new FileSystemManagerFailImpl(1300002); + options.fail?.(err) + options.complete?.(err) + }, null) + return + } + } else { + let isSandyBox = isSandyBoxPath(zipFilePath, true) + if (!isSandyBox) { + currentDispatcher.async(function (_) { + let err = new FileSystemManagerFailImpl(1300013); + options.fail?.(err) + options.complete?.(err) + }, null) + return + } + let zipFile = new File(zipFilePath) + if (!zipFile.exists()) { + /** + * 文件不存在 + */ + currentDispatcher.async(function (_) { + let err = new FileSystemManagerFailImpl(1300002); + options.fail?.(err) + options.complete?.(err) + }, null) + return + } + + isSandyBox = isSandyBoxPath(targetPath, true) + let targetFile = new File(targetPath) + if (!isSandyBox) { + currentDispatcher.async(function (_) { + let err = new FileSystemManagerFailImpl(1300013); + options.fail?.(err) + options.complete?.(err) + }, null) + return + + } + if (!targetFile.exists() || !targetFile.isDirectory()) { + currentDispatcher.async(function (_) { + let err = new FileSystemManagerFailImpl(1300002); + options.fail?.(err) + options.complete?.(err) + }, null) + return + } + is = new FileInputStream(zipFile); } - - + try { - let is = new FileInputStream(zipFile); let zis = new ZipInputStream(new BufferedInputStream(is)); - console.log(zipFile.getPath()) let buffer = new ByteArray(1024) let count : number = 0; let ze = zis.getNextEntry() @@ -1819,7 +1837,7 @@ class AndroidFileSystemManager implements FileSystemManager { } catch (e : Exception) { console.log(e.message) currentDispatcher.async(function (_) { - let err = new UniError(UniErrorSubject, 1300201, UniErrors.get(1300201)! + ":" + options.zipFilePath); + let err = new FileSystemManagerFailImpl(1300201); options.fail?.(err) options.complete?.(err) }, null) @@ -1841,7 +1859,7 @@ class AndroidFileSystemManager implements FileSystemManager { * 文件不存在,或者不是文件夹,异常 */ currentDispatcher.async(function (_) { - let err = new UniError(UniErrorSubject, 1300002, UniErrors.get(1300002)! + ":" + filePath); + let err = new FileSystemManagerFailImpl(1300002); options.fail?.(err) options.complete?.(err) }, null) @@ -1882,7 +1900,7 @@ class AndroidFileSystemManager implements FileSystemManager { * 文件不存在,或者是文件夹,异常 */ currentDispatcher.async(function (_) { - let err = new UniError(UniErrorSubject, 1300002, UniErrors.get(1300002)! + ":" + filePath); + let err = new FileSystemManagerFailImpl(1300002); options.fail?.(err) options.complete?.(err) }, null) @@ -1918,7 +1936,7 @@ class AndroidFileSystemManager implements FileSystemManager { /** * 文件不存在,或者是文件夹,异常 */ - throw new UniError(UniErrorSubject, 1300002, msgPrefix + UniErrors.get(1300002)!) + throw new UniError(FileSystemManagerUniErrorSubject, 1300002, msgPrefix + FileSystemManagerUniErrors.get(1300002)!) } let content = targetFile.readText() @@ -1931,38 +1949,58 @@ class AndroidFileSystemManager implements FileSystemManager { readCompressedFile(options : ReadCompressedFileOptions) { let currentDispatcher = UTSAndroid.getDispatcher("main") UTSAndroid.getDispatcher('io').async(function (_) { - let filePath = UTSAndroid.convert2AbsFullPath(options.filePath) - - let targetFile = new File(filePath) - if (!targetFile.exists() || targetFile.isDirectory()) { - /** - * 文件不存在,或者是文件夹,异常 - */ - currentDispatcher.async(function (_) { - let err = new UniError(UniErrorSubject, 1300002, UniErrors.get(1300002)! + ":" + filePath); - options.fail?.(err) - options.complete?.(err) - }, null) - return - } - if (options.compressionAlgorithm != 'br') { - currentDispatcher.async(function (_) { - let err = new UniError(UniErrorSubject, 1301111, UniErrors.get(1301111)! + ":" + filePath); - options.fail?.(err) - options.complete?.(err) - }, null) - return - } let success : ReadCompressedFileResult = { data: "" } + let is:InputStream + let filePath = UTSAndroid.convert2AbsFullPath(options.filePath) + if (filePath.startsWith("/android_asset/")) { + try { + let assetName = filePath.substring("/android_asset/".length) + is = UTSAndroid.getAppContext()!.getResources().getAssets().open(assetName); + + } catch (e : Exception) { + /** + * 文件不存在,或者是文件夹,异常 + */ + currentDispatcher.async(function (_) { + let err = new FileSystemManagerFailImpl(1300002); + options.fail?.(err) + options.complete?.(err) + }, null) + return + } + } else { + let targetFile = new File(filePath) + if (!targetFile.exists() || targetFile.isDirectory()) { + /** + * 文件不存在,或者是文件夹,异常 + */ + currentDispatcher.async(function (_) { + let err = new FileSystemManagerFailImpl(1300002); + options.fail?.(err) + options.complete?.(err) + }, null) + return + } + if (options.compressionAlgorithm != 'br') { + currentDispatcher.async(function (_) { + let err = new FileSystemManagerFailImpl(1301111); + options.fail?.(err) + options.complete?.(err) + }, null) + return + } + is = new FileInputStream(targetFile) + + } try { - let brInput = new BrotliInputStream(new FileInputStream(targetFile)) + let brInput = new BrotliInputStream(is) success.data = new String(brInput.readBytes()) brInput.close() } catch (e : Exception) { currentDispatcher.async(function (_) { - let err = new UniError(UniErrorSubject, 1300201, UniErrors.get(1300201)! + ":" + filePath); + let err = new FileSystemManagerFailImpl(1300201); options.fail?.(err) options.complete?.(err) }, null) @@ -1978,23 +2016,36 @@ class AndroidFileSystemManager implements FileSystemManager { readCompressedFileSync(filePath : string, compressionAlgorithm : string) : string { let msgPrefix = "readCompressedFileSync:fail " let tempFilePath = UTSAndroid.convert2AbsFullPath(filePath) - let targetFile = new File(tempFilePath) - if (!targetFile.exists() || targetFile.isDirectory()) { - /** - * 文件不存在,或者是文件夹,异常 - */ - throw new UniError(UniErrorSubject, 1300002, msgPrefix + UniErrors.get(1300002)!) - } - if (compressionAlgorithm != 'br') { - throw new UniError(UniErrorSubject, 1301111, msgPrefix + UniErrors.get(1301111)!) + let is : InputStream + if (tempFilePath.startsWith("/android_asset/")) { + try { + let assetName = tempFilePath.substring("/android_asset/".length) + is = UTSAndroid.getAppContext()!.getResources().getAssets().open(assetName); + + } catch (e : Exception) { + throw new UniError(FileSystemManagerUniErrorSubject, 1300002, msgPrefix + FileSystemManagerUniErrors.get(1300002)!) + } + } else { + let targetFile = new File(tempFilePath) + if (!targetFile.exists() || targetFile.isDirectory()) { + /** + * 文件不存在,或者是文件夹,异常 + */ + throw new UniError(FileSystemManagerUniErrorSubject, 1300002, msgPrefix + FileSystemManagerUniErrors.get(1300002)!) + } + if (compressionAlgorithm != 'br') { + throw new UniError(FileSystemManagerUniErrorSubject, 1301111, msgPrefix + FileSystemManagerUniErrors.get(1301111)!) + } + is = new FileInputStream(targetFile) } let data : string + try { - let brInput = new BrotliInputStream(new FileInputStream(targetFile)) + let brInput = new BrotliInputStream(is) data = new String(brInput.readBytes()) brInput.close() } catch (e : Exception) { - throw new UniError(UniErrorSubject, 1300201, msgPrefix + UniErrors.get(1300201)!) + throw new UniError(FileSystemManagerUniErrorSubject, 1300201, msgPrefix + FileSystemManagerUniErrors.get(1300201)!) } return data } @@ -2010,7 +2061,7 @@ class AndroidFileSystemManager implements FileSystemManager { * 文件不存在,或者是文件夹,异常 */ currentDispatcher.async(function (_) { - let err = new UniError(UniErrorSubject, 1300002, UniErrors.get(1300002)! + ":" + filePath); + let err = new FileSystemManagerFailImpl(1300002); options.fail?.(err) options.complete?.(err) }, null) @@ -2030,7 +2081,7 @@ class AndroidFileSystemManager implements FileSystemManager { public write(options : WriteOptions) { console.log(JSON.stringify(options)) if (options.encoding.toLowerCase() != 'base64' && options.encoding.toLowerCase() != 'utf-8' && options.encoding.toLowerCase() != 'ascii') { - let err = new UniError(UniErrorSubject, 1200002, UniErrors.get(1200002)!); + let err = new FileSystemManagerFailImpl(1200002); options.fail?.(err) options.complete?.(err) return @@ -2042,7 +2093,7 @@ class AndroidFileSystemManager implements FileSystemManager { let fd = ParcelFileDescriptor.fromFd(options.fd.toInt()) if (fd == null) { - let err = new UniError(UniErrorSubject, 1300009, UniErrors.get(1300009)!); + let err = new FileSystemManagerFailImpl(1300009); options.fail?.(err) options.complete?.(err) return @@ -2089,11 +2140,11 @@ class AndroidFileSystemManager implements FileSystemManager { public writeSync(options : WriteSyncOptions) : WriteResult { let msgPrefix = "writeSync:fail " if (options.encoding.toLowerCase() != 'base64' && options.encoding.toLowerCase() != 'utf-8' && options.encoding.toLowerCase() != 'ascii') { - throw new UniError(UniErrorSubject, 1200002, msgPrefix + UniErrors.get(1200002)!) + throw new UniError(FileSystemManagerUniErrorSubject, 1200002, msgPrefix + FileSystemManagerUniErrors.get(1200002)!) } let fd = ParcelFileDescriptor.fromFd(options.fd.toInt()) if (fd == null) { - throw new UniError(UniErrorSubject, 1300009, msgPrefix + UniErrors.get(1300009)!) + throw new UniError(FileSystemManagerUniErrorSubject, 1300009, msgPrefix + FileSystemManagerUniErrors.get(1300009)!) } try { let outStream = new FileOutputStream(fd.getFileDescriptor()) @@ -2125,7 +2176,7 @@ class AndroidFileSystemManager implements FileSystemManager { fileChannel.write(buffer, 0) } } catch (e) { - throw new UniError(UniErrorSubject, 1300201, msgPrefix + UniErrors.get(1300201)!) + throw new UniError(FileSystemManagerUniErrorSubject, 1300201, msgPrefix + FileSystemManagerUniErrors.get(1300201)!) } let ret : WriteResult = { bytesWritten: options.data.length @@ -2147,7 +2198,7 @@ class AndroidFileSystemManager implements FileSystemManager { options.success?.(success) options.complete?.(success) } catch (e) { - let err = new UniError(UniErrorSubject, 1300009, UniErrors.get(1300009)!); + let err = new FileSystemManagerFailImpl(1300009); options.fail?.(err) options.complete?.(err) } @@ -2162,7 +2213,7 @@ class AndroidFileSystemManager implements FileSystemManager { this.fileDesUtil.openMap.delete(options.fd) } } catch (e) { - throw new UniError(UniErrorSubject, 1300009, msgPrefix + UniErrors.get(1300009)!) + throw new UniError(FileSystemManagerUniErrorSubject, 1300009, msgPrefix + FileSystemManagerUniErrors.get(1300009)!) } } public fstat(options : FStatOptions) { @@ -2171,7 +2222,7 @@ class AndroidFileSystemManager implements FileSystemManager { currentDispatcher.async(function (_) { if (!this.fileDesUtil.openMap.has(options.fd)) { currentDispatcher.async(function (_) { - let err = new UniError(UniErrorSubject, 1300009, UniErrors.get(1300009)! + ":" + options.fd); + let err = new FileSystemManagerFailImpl(1300009); options.fail?.(err) options.complete?.(err) }, null) @@ -2188,7 +2239,7 @@ class AndroidFileSystemManager implements FileSystemManager { public fstatSync(options : FStatSyncOptions) : Stats { let msgPrefix = "ftruncateSync:fail " if (!this.fileDesUtil.openMap.has(options.fd)) { - throw new UniError(UniErrorSubject, 1300009, msgPrefix + UniErrors.get(1300009)!) + throw new UniError(FileSystemManagerUniErrorSubject, 1300009, msgPrefix + FileSystemManagerUniErrors.get(1300009)!) } return wrapStats(this.fileDesUtil.openMap.get(options.fd)!) } @@ -2197,7 +2248,7 @@ class AndroidFileSystemManager implements FileSystemManager { UTSAndroid.getDispatcher('io').async(function (_) { if (!this.fileDesUtil.openMap.has(options.fd)) { currentDispatcher.async(function (_) { - let err = new UniError(UniErrorSubject, 1300009, UniErrors.get(1300009)! + ":" + options.fd); + let err = new FileSystemManagerFailImpl(1300009); options.fail?.(err) options.complete?.(err) }, null) @@ -2222,7 +2273,7 @@ class AndroidFileSystemManager implements FileSystemManager { public ftruncateSync(options : FTruncateFileSyncOptions) { let msgPrefix = "ftruncateSync:fail " if (!this.fileDesUtil.openMap.has(options.fd)) { - throw new UniError(UniErrorSubject, 1300009, msgPrefix + UniErrors.get(1300009)!) + throw new UniError(FileSystemManagerUniErrorSubject, 1300009, msgPrefix + FileSystemManagerUniErrors.get(1300009)!) } let targetFile = this.fileDesUtil.openMap.get(options.fd) let content = targetFile!.readText() @@ -2235,14 +2286,14 @@ class AndroidFileSystemManager implements FileSystemManager { public readZipEntry(options : ReadZipEntryOptions) { let targetPath = uni.env.CACHE_PATH + "/" + Base64.encodeToString(options.filePath.toByteArray(), Base64.NO_WRAP) targetPath = UTSAndroid.convert2AbsFullPath(targetPath) - console.log("readZipEntry", targetPath) let file : File = new File(targetPath) if (!file.exists()) { file.mkdirs() } + let target = this - let zipOptions : UnzipFileOptions = { + let zipOptions : UnzipFileOptions = {//todo 需要去掉 zipFilePath: options.filePath, targetPath: targetPath, success: (_) => { @@ -2254,7 +2305,6 @@ class AndroidFileSystemManager implements FileSystemManager { filterEntries?.forEach((item) => { let fileItem = new File(targetPath + "/" + item.path) - console.log("readZipEntry", file.getPath()) if (!fileItem.exists() || fileItem.isDirectory()) { let zipFileItem : ZipFileItem = { errMsg: 'no such file' @@ -2313,8 +2363,8 @@ class AndroidFileSystemManager implements FileSystemManager { targetFile.delete() }) }, - fail: (res : UniError) => { - let err = new UniError(UniErrorSubject, res.errCode, res.errMsg); + fail: (res) => { + let err = new FileSystemManagerFailImpl(res.errCode); options.fail?.(err) options.complete?.(err) } diff --git a/uni_modules/uni-fileSystemManager/utssdk/app-js/index.uts b/uni_modules/uni-fileSystemManager/utssdk/app-js/index.uts index 4afebccd908db6eb7bd34f79bf44d2b4b913a9c1..ce098f5895a2e2f32a3ec9d0487a9c9b28e8a544 100644 --- a/uni_modules/uni-fileSystemManager/utssdk/app-js/index.uts +++ b/uni_modules/uni-fileSystemManager/utssdk/app-js/index.uts @@ -1,8 +1,7 @@ import { WriteFileOptions, ReadFileOptions, MkDirOptions, RmDirOptions, UnLinkOptions, ReadDirOptions, AccessOptions, RenameOptions, GetFileInfoOptions, CopyFileOptions, StatOptions } from "../interface.uts" import { ReadFileSuccessResult, FileManagerSuccessResult, ReadDirSuccessResult, GetFileInfoSuccessResult, StatSuccessResult, FileStats, Stats } from "../interface.uts" import { GetFileSystemManager, FileSystemManager } from "../interface.uts" -import { UniErrorSubject, UniErrors } from "../unierror.uts" -export { Stats,FileStats } from '../interface.uts' +import { FileSystemManagerFailImpl, FileSystemManagerUniErrorSubject, FileSystemManagerUniErrors } from "../unierror.uts" class InnerStats implements Stats { /** @@ -93,7 +92,7 @@ class JsFileSystemManager implements FileSystemManager { options.complete?.(ret) }, function (code) { - let err = new UniError(UniErrorSubject, code, UniErrors.get(code)! + ":" + options.path); + let err = new FileSystemManagerFailImpl(code) options.fail?.(err) options.complete?.(err) }) @@ -103,7 +102,7 @@ class JsFileSystemManager implements FileSystemManager { if(options.digestAlgorithm == null || options.digestAlgorithm == undefined){ options.digestAlgorithm = "md5" } else if (options.digestAlgorithm!.toLowerCase() != 'md5' && options.digestAlgorithm!.toLowerCase() != 'sha1') { - let err = new UniError(UniErrorSubject, 1300022, UniErrors.get(1300022)! + ":invalid digestAlgorithm " + options.digestAlgorithm); + let err = new FileSystemManagerFailImpl(1300022); options.fail?.(err) options.complete?.(err) return @@ -117,7 +116,7 @@ class JsFileSystemManager implements FileSystemManager { options.complete?.(ret) }, function (code) { - let err = new UniError(UniErrorSubject, code, UniErrors.get(code)! + ":" + options.filePath); + let err = new FileSystemManagerFailImpl(code); options.fail?.(err) options.complete?.(err) }) @@ -136,7 +135,7 @@ class JsFileSystemManager implements FileSystemManager { options.complete?.(ret) }, function (code) { - let err = new UniError(UniErrorSubject, code, UniErrors.get(code)!); + let err = new FileSystemManagerFailImpl(code); options.fail?.(err) options.complete?.(err) }) @@ -155,7 +154,7 @@ class JsFileSystemManager implements FileSystemManager { options.complete?.(ret) }, function (code) { - let err = new UniError(UniErrorSubject, code, UniErrors.get(code)!); + let err = new FileSystemManagerFailImpl(code); options.fail?.(err) options.complete?.(err) }) @@ -173,7 +172,7 @@ class JsFileSystemManager implements FileSystemManager { options.complete?.(ret) }, function (code) { - let err = new UniError(UniErrorSubject, code, UniErrors.get(code)! + ":" + options.path); + let err = new FileSystemManagerFailImpl(code); options.fail?.(err) options.complete?.(err) }) @@ -191,7 +190,7 @@ class JsFileSystemManager implements FileSystemManager { options.complete?.(ret) }, function (code) { - let err = new UniError(UniErrorSubject, code, UniErrors.get(code)! + ":" + options.dirPath); + let err = new FileSystemManagerFailImpl(code); options.fail?.(err) options.complete?.(err) }) @@ -214,7 +213,7 @@ class JsFileSystemManager implements FileSystemManager { options.complete?.(ret) }, function (code) { - let err = new UniError(UniErrorSubject, code, UniErrors.get(code)! + ":" + options.dirPath); + let err = new FileSystemManagerFailImpl(code); options.fail?.(err) options.complete?.(err) }) @@ -229,7 +228,7 @@ class JsFileSystemManager implements FileSystemManager { options.complete?.(ret) }, function (code) { - let err = new UniError(UniErrorSubject, code, UniErrors.get(code)! + ":" + options.dirPath); + let err = new FileSystemManagerFailImpl(code); options.fail?.(err) options.complete?.(err) }) @@ -248,7 +247,7 @@ class JsFileSystemManager implements FileSystemManager { options.complete?.(ret) }, function (code) { - let err = new UniError(UniErrorSubject, code, UniErrors.get(code)! + ":" + options.filePath); + let err = new FileSystemManagerFailImpl(code); options.fail?.(err) options.complete?.(err) }) @@ -266,7 +265,7 @@ class JsFileSystemManager implements FileSystemManager { options.complete?.(ret) }, function (code) { - let err = new UniError(UniErrorSubject, code, UniErrors.get(code)! + ":" + options.filePath); + let err = new FileSystemManagerFailImpl(code); options.fail?.(err) options.complete?.(err) }) @@ -286,7 +285,7 @@ class JsFileSystemManager implements FileSystemManager { options.complete?.(ret) }, function (code) { - let err = new UniError(UniErrorSubject, code, UniErrors.get(code)! + ":" + options.filePath); + let err = new FileSystemManagerFailImpl(code); options.fail?.(err) options.complete?.(err) }) diff --git a/uni_modules/uni-fileSystemManager/utssdk/interface.uts b/uni_modules/uni-fileSystemManager/utssdk/interface.uts index 99da5c0effb36687fc3e1744ff9a2c311fed93bb..49fe5d00ba371c9548c799c8ef1a02ecd0a63ee1 100644 --- a/uni_modules/uni-fileSystemManager/utssdk/interface.uts +++ b/uni_modules/uni-fileSystemManager/utssdk/interface.uts @@ -21,7 +21,7 @@ export type FileManagerSuccessCallback = (res : FileManagerSuccessResult) => voi /** * 通用的错误返回结果回调 */ -export type FileManagerFailCallback = (res : UniError) => void +export type FileManagerFailCallback = (res : FileSystemManagerFail) => void /** * 通用的结束返回结果回调 */ @@ -39,7 +39,7 @@ export type ReadFileOptions = { */ encoding : "base64" | "utf-8", /** - * 文件路径,支持相对地址和绝对地址 + * 文件路径,支持相对地址和绝对地址,app-android平台支持代码包文件目录 */ filePath : string.URIString, /** @@ -269,7 +269,7 @@ export type ReadDirOptions = { export type AccessOptions = { /** - * 要删除的目录路径 (本地路径) + * 要判断是否存在的文件/目录路径 (本地路径) */ path : string.URIString, @@ -553,7 +553,7 @@ export type ReadCompressedFileResult = { export type ReadCompressedFileCallback = (res : ReadCompressedFileResult) => void export type ReadCompressedFileOptions = { /** - * 要读取的文件的路径 (本地用户文件或代码包文件) + * 要读取的文件的路径 (本地用户文件或代码包文件),app-android平台支持代码包文件目录 */ filePath : string.URIString, /** @@ -779,7 +779,7 @@ export type ZipFileItem = { export type ReadZipEntryCallback = (res : EntriesResult) => void export type ReadZipEntryOptions = { /** - * 要读取的压缩包的路径 (本地路径) + * 要读取的压缩包的路径 (本地路径),app-android平台支持代码包文件目录 */ filePath : string.URIString, /** @@ -829,6 +829,8 @@ export interface FileSystemManager { readFile(options : ReadFileOptions) : void; /** * FileSystemManager.readFile 的同步版本参数 + * @param filePath 文件路径,支持相对地址和绝对地址,app-android平台支持代码包文件目录 + * @param encoding base64 / utf-8 * @uniPlatform { * "app": { * "android": { @@ -873,6 +875,9 @@ export interface FileSystemManager { writeFile(options : WriteFileOptions) : void; /** * FileSystemManager.writeFile 的同步版本 + * @param filePath 文件路径,只支持绝对地址 + * @param data 写入的文本内容 + * @param encoding 指定写入文件的字符编码,支持:ascii base64 utf-8 * @uniPlatform { * "app": { * "android": { @@ -917,6 +922,7 @@ export interface FileSystemManager { unlink(options : UnLinkOptions) : void; /** * FileSystemManager.unlink 的同步版本 + * @param filePath 文件路径,只支持绝对地址 * @uniPlatform { * "app": { * "android": { @@ -961,6 +967,8 @@ export interface FileSystemManager { mkdir(options : MkDirOptions) : void; /** * FileSystemManager.mkdir 的同步版本 + * @param dirPath 创建的目录路径 (本地路径) + * @param recursive 是否在递归创建该目录的上级目录后再创建该目录。如果对应的上级目录已经存在,则不创建该上级目录。如 dirPath 为 a/b/c/d 且 recursive 为 true,将创建 a 目录,再在 a 目录下创建 b 目录,以此类推直至创建 a/b/c 目录下的 d 目录。 * @uniPlatform { * "app": { * "android": { @@ -1005,6 +1013,8 @@ export interface FileSystemManager { rmdir(options : RmDirOptions) : void; /** * FileSystemManager.rmdir 的同步版本 + * @param dirPath 要删除的目录路径 (本地路径) + * @param recursive 是否递归删除目录。如果为 true,则删除该目录和该目录下的所有子目录以及文件。 * @uniPlatform { * "app": { * "android": { @@ -1049,6 +1059,7 @@ export interface FileSystemManager { readdir(options : ReadDirOptions) : void; /** * FileSystemManager.readdir 的同步版本 + * @param dirPath 要读取的目录路径 (本地路径) * @uniPlatform { * "app": { * "android": { @@ -1093,6 +1104,7 @@ export interface FileSystemManager { access(options : AccessOptions) : void; /** * FileSystemManager.access 的同步版本 + * @param path 要判断是否存在的文件/目录路径 (本地路径) * @uniPlatform { * "app": { * "android": { @@ -1137,6 +1149,8 @@ export interface FileSystemManager { rename(options : RenameOptions) : void; /** * FileSystemManager.rename 的同步版本 + * @param oldPath 源文件路径,支持本地路径 + * @param newPath 新文件路径,支持本地路径 * @uniPlatform { * "app": { * "android": { @@ -1181,6 +1195,8 @@ export interface FileSystemManager { copyFile(options : CopyFileOptions) : void; /** * FileSystemManager.copyFile 的同步版本 + * @param srcPath 源文件路径,支持本地路径 + * @param destPath 新文件路径,支持本地路径 * @uniPlatform { * "app": { * "android": { @@ -1247,6 +1263,8 @@ export interface FileSystemManager { stat(options : StatOptions) : void; /** * FileSystemManager.stat 的同步版本 + * @param path 文件/目录路径 (本地路径) + * @param recursive 是否递归获取目录下的每个文件的 Stats 信息 * @uniPlatform { * "app": { * "android": { @@ -1291,6 +1309,9 @@ export interface FileSystemManager { appendFile(options : AppendFileOptions) : void; /** * FileSystemManager.appendFile 的同步版本 + * @param filePath 要追加内容的文件路径 (本地路径) + * @param data 要追加的文本 + * @param encoding 指定写入文件的字符编码支持:ascii base64 utf-8 * @uniPlatform { * "app": { * "android": { @@ -1335,6 +1356,8 @@ export interface FileSystemManager { saveFile(options : SaveFileOptions) : void; /** * FileSystemManager.saveFile 的同步版本 + * @param tempFilePath 临时存储文件路径 (本地路径) + * @param filePath 要存储的文件路径 (本地路径) * @uniPlatform { * "app": { * "android": { @@ -1445,6 +1468,8 @@ export interface FileSystemManager { truncate(options : TruncateFileOptions) : void; /** * 对文件内容进行截断操作 (truncate 的同步版本) + * @param filePath 要截断的文件路径 (本地路径) + * @param length 截断位置,默认0。如果 length 小于文件长度(字节),则只有前面 length 个字节会保留在文件中,其余内容会被删除;如果 length 大于文件长度,不做处理 * @uniPlatform { * "app": { * "android": { @@ -1489,6 +1514,8 @@ export interface FileSystemManager { readCompressedFile(options : ReadCompressedFileOptions) : void; /** * 同步读取指定压缩类型的本地文件内容 + * @param filePath 要读取的文件的路径 (本地用户文件或代码包文件),app-android平台支持代码包文件目录 + * @param compressionAlgorithm 文件压缩类型,目前仅支持 'br'。 * @uniPlatform { * "app": { * "android": { @@ -1618,7 +1645,7 @@ export interface FileSystemManager { * } * } */ - close(options : CloseOptions); + close(options : CloseOptions) : void; /** * 同步关闭文件 * @uniPlatform { @@ -1781,4 +1808,26 @@ export interface Uni { * @uniVueVersion 2,3 //支持的vue版本 */ getFileSystemManager() : FileSystemManager -} \ No newline at end of file +} + +/** + * 错误码 + * - 1200002 类型错误。仅支持 base64 / utf-8 + * - 1300002 未找到文件 + * - 1300013 无权限 + * - 1300021 是目录 + * - 1300022 参数无效 + * - 1300066 目录非空 + * - 1301003 对目录的非法操作 + * - 1301005 文件已存在 + * - 1300201 系统错误 + * - 1300202 超出文件存储限制的最大尺寸 + * - 1301111 brotli解压失败 + * - 1302003 标志无效 + * - 1300009 文件描述符错误 + */ +export type FileSystemManagerErrorCode = 1200002 | 1300002 | 1300013 | 1300021 | 1300022 | 1300066 | 1301003 | 1301005 | 1300201 | 1300202 | 1301111 | 1302003 | 1300009; +export type FileSystemManagerFail = IFileSystemManagerFail; +export interface IFileSystemManagerFail extends IUniError { + errCode : FileSystemManagerErrorCode +}; diff --git a/uni_modules/uni-fileSystemManager/utssdk/unierror.uts b/uni_modules/uni-fileSystemManager/utssdk/unierror.uts index 625585070237f1df3be368c5189d89b41de26ae8..bcca4b630b33fa4c030038c1842c3b431dbfa328 100644 --- a/uni_modules/uni-fileSystemManager/utssdk/unierror.uts +++ b/uni_modules/uni-fileSystemManager/utssdk/unierror.uts @@ -1,13 +1,15 @@ +import { FileSystemManagerErrorCode,IFileSystemManagerFail } from "./interface.uts" + /** * 错误主题 */ -export const UniErrorSubject = 'uni-fileSystemManager'; +export const FileSystemManagerUniErrorSubject = 'uni-fileSystemManager'; /** * 错误码 * @UniError */ -export const UniErrors : Map = new Map([ +export const FileSystemManagerUniErrors : Map = new Map([ [1200002, 'type error. only support base64 / utf-8'], [1300002, 'no such file or directory'], @@ -22,4 +24,12 @@ export const UniErrors : Map = new Map([ [1301111, 'brotli decompress fail'], [1302003, 'invalid flag'], [1300009, 'bad file descriptor'] -]); \ No newline at end of file +]); +export class FileSystemManagerFailImpl extends UniError implements IFileSystemManagerFail { + constructor(errCode : FileSystemManagerErrorCode) { + super(); + this.errSubject = FileSystemManagerUniErrorSubject; + this.errCode = errCode; + this.errMsg = FileSystemManagerUniErrors.get(errCode) ?? ""; + } +} \ No newline at end of file diff --git a/uni_modules/uni-getAppAuthorizeSetting/utssdk/interface.uts b/uni_modules/uni-getAppAuthorizeSetting/utssdk/interface.uts index 02a6757bf63f0c20a4cdb9aba75ed5b02d86b9d2..a61e361cfa468c444dbc9f5f58a810684bbfe802 100644 --- a/uni_modules/uni-getAppAuthorizeSetting/utssdk/interface.uts +++ b/uni_modules/uni-getAppAuthorizeSetting/utssdk/interface.uts @@ -41,7 +41,8 @@ export type GetAppAuthorizeSettingResult = { * - authorized: 已经获得授权,无需再次请求授权 * - denied: 请求授权被拒绝,无法再次请求授权;(此情况需要引导用户打开系统设置,在设置页中打开权限) * - not determined: 尚未请求授权,会在App下一次调用系统相应权限时请求;(仅 iOS 会出现。此种情况下引导用户打开系统设置,不展示开关) - * @type 'authorized' | 'denied' | 'not determined' + * - config error: 当前应用没有配置相册权限描述 + * @type 'authorized' | 'denied' | 'not determined' | 'config error' * @uniPlatform * { * "app": { @@ -58,13 +59,13 @@ export type GetAppAuthorizeSettingResult = { * } * } */ - albumAuthorized?: 'authorized' | 'denied' | 'not determined' | null, + albumAuthorized?: 'authorized' | 'denied' | 'not determined' | 'config error' | null, /** * 允许 App 使用蓝牙的开关(仅 iOS 支持) * - authorized: 已经获得授权,无需再次请求授权 * - denied: 请求授权被拒绝,无法再次请求授权;(此情况需要引导用户打开系统设置,在设置页中打开权限) * - not determined: 尚未请求授权,会在App下一次调用系统相应权限时请求;(仅 iOS 会出现。此种情况下引导用户打开系统设置,不展示开关) - * - config error: Android平台没有该值;iOS平台:表示没有在 `manifest.json -> App模块配置` 中配置 `BlueTooth(低功耗蓝牙)` 模块 + * - config error: Android平台没有该值;iOS平台:当前应用没有配置蓝牙权限描述 * @type 'authorized' | 'denied' | 'not determined' | 'config error' * @uniPlatform * { @@ -88,8 +89,23 @@ export type GetAppAuthorizeSettingResult = { * - authorized: 已经获得授权,无需再次请求授权 * - denied: 请求授权被拒绝,无法再次请求授权;(此情况需要引导用户打开系统设置,在设置页中打开权限) * - not determined: 尚未请求授权,会在App下一次调用系统相应权限时请求;(仅 iOS 会出现。此种情况下引导用户打开系统设置,不展示开关) - * - config error: Android平台:表示没有配置 `android.permission.CAMERA` 权限,[权限配置详情](https://uniapp.dcloud.net.cn/tutorial/app-nativeresource-android.html#permissions);iOS平台没有该值 + * - config error: Android平台:表示没有配置 `android.permission.CAMERA` 权限,[权限配置详情](https://uniapp.dcloud.net.cn/tutorial/app-nativeresource-android.html#permissions);iOS平台:当前应用没有配置相机权限描述 * @type 'authorized' | 'denied' | 'not determined' | 'config error' + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "4.4", + * "uniVer": "√", + * "unixVer": "3.9" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * } + * } */ cameraAuthorized: 'authorized' | 'denied' | 'not determined' | 'config error', /** @@ -97,16 +113,46 @@ export type GetAppAuthorizeSettingResult = { * - authorized: 已经获得授权,无需再次请求授权 * - denied: 请求授权被拒绝,无法再次请求授权;(此情况需要引导用户打开系统设置,在设置页中打开权限) * - not determined: 尚未请求授权,会在App下一次调用系统相应权限时请求;(仅 iOS 会出现。此种情况下引导用户打开系统设置,不展示开关) - * - config error: Android平台:表示没有配置 `android.permission.ACCESS_COARSE_LOCATION` 权限,[权限配置详情](https://uniapp.dcloud.net.cn/tutorial/app-nativeresource-android.html#permissions);iOS平台:表示没有在 `manifest.json -> App模块配置` 中配置 `Geolocation(定位)` 模块 + * - config error: Android平台:表示没有配置 `android.permission.ACCESS_COARSE_LOCATION` 权限,[权限配置详情](https://uniapp.dcloud.net.cn/tutorial/app-nativeresource-android.html#permissions);iOS平台:当前应用没有配置定位权限描述 * @type 'authorized' | 'denied' | 'not determined' | 'config error' + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "4.4", + * "uniVer": "√", + * "unixVer": "3.9" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * } + * } */ locationAuthorized: 'authorized' | 'denied' | 'not determined' | 'config error', /** * 定位准确度。 * - reduced: 模糊定位 * - full: 精准定位 - * - unsupported: 不支持(包括用户拒绝定位权限和没有在 `manifest.json -> App模块配置` 中配置 `Geolocation(定位)` 模块) + * - unsupported: 不支持(包括用户拒绝定位权限和没有包含定位权限描述) * @type 'reduced' | 'full' | 'unsupported' + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "4.4", + * "uniVer": "√", + * "unixVer": "3.9" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * } + * } */ locationAccuracy?: 'reduced' | 'full' | 'unsupported' | null, /** @@ -134,8 +180,23 @@ export type GetAppAuthorizeSettingResult = { * - authorized: 已经获得授权,无需再次请求授权 * - denied: 请求授权被拒绝,无法再次请求授权;(此情况需要引导用户打开系统设置,在设置页中打开权限) * - not determined: 尚未请求授权,会在App下一次调用系统相应权限时请求;(仅 iOS 会出现。此种情况下引导用户打开系统设置,不展示开关) - * - config error: Android平台:表示没有配置 `android.permission.RECORD_AUDIO` 权限,[权限配置详情](https://uniapp.dcloud.net.cn/tutorial/app-nativeresource-android.html#permissions);iOS平台没有该值 + * - config error: Android平台:表示没有配置 `android.permission.RECORD_AUDIO` 权限,[权限配置详情](https://uniapp.dcloud.net.cn/tutorial/app-nativeresource-android.html#permissions);iOS平台:当前应用没有配置麦克风权限描述 * @type 'authorized' | 'denied' | 'not determined' | 'config error' + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "4.4", + * "uniVer": "√", + * "unixVer": "3.9" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * } + * } */ microphoneAuthorized: 'authorized' | 'denied' | 'not determined' | 'config error', /** @@ -143,8 +204,23 @@ export type GetAppAuthorizeSettingResult = { * - authorized: 已经获得授权,无需再次请求授权 * - denied: 请求授权被拒绝,无法再次请求授权;(此情况需要引导用户打开系统设置,在设置页中打开权限) * - not determined: 尚未请求授权,会在App下一次调用系统相应权限时请求;(仅 iOS 会出现。此种情况下引导用户打开系统设置,不展示开关) - * - config error: Android平台没有该值;iOS平台:表示没有在 `manifest.json -> App模块配置` 中配置 `Push(推送)` 模块 + * - config error: Android平台没有该值;iOS平台:没有包含推送权限描述 * @type 'authorized' | 'denied' | 'not determined' | 'config error' + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "4.4", + * "uniVer": "√", + * "unixVer": "3.9" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * } + * } */ notificationAuthorized: 'authorized' | 'denied' | 'not determined' | 'config error', /** @@ -152,7 +228,7 @@ export type GetAppAuthorizeSettingResult = { * - authorized: 已经获得授权,无需再次请求授权 * - denied: 请求授权被拒绝,无法再次请求授权;(此情况需要引导用户打开系统设置,在设置页中打开权限) * - not determined: 尚未请求授权,会在App下一次调用系统相应权限时请求;(仅 iOS 会出现。此种情况下引导用户打开系统设置,不展示开关) - * - config error: 没有在 `manifest.json -> App模块配置` 中配置 `Push(推送)` 模块 + * - config error: 当前应用没有配置推送权限描述 * @type 'authorized' | 'denied' | 'not determined' | 'config error' * @uniPlatform * { @@ -176,7 +252,7 @@ export type GetAppAuthorizeSettingResult = { * - authorized: 已经获得授权,无需再次请求授权 * - denied: 请求授权被拒绝,无法再次请求授权;(此情况需要引导用户打开系统设置,在设置页中打开权限) * - not determined: 尚未请求授权,会在App下一次调用系统相应权限时请求;(仅 iOS 会出现。此种情况下引导用户打开系统设置,不展示开关) - * - config error: 没有在 `manifest.json -> App模块配置` 中配置 `Push(推送)` 模块 + * - config error: 当前应用没有配置推送权限描述 * @type 'authorized' | 'denied' | 'not determined' | 'config error' * @uniPlatform * { @@ -200,7 +276,7 @@ export type GetAppAuthorizeSettingResult = { * - authorized: 已经获得授权,无需再次请求授权 * - denied: 请求授权被拒绝,无法再次请求授权;(此情况需要引导用户打开系统设置,在设置页中打开权限) * - not determined: 尚未请求授权,会在App下一次调用系统相应权限时请求;(仅 iOS 会出现。此种情况下引导用户打开系统设置,不展示开关) - * - config error: 没有在 `manifest.json -> App模块配置` 中配置 `Push(推送)` 模块 + * - config error: 当前应用没有配置推送权限描述 * @type 'authorized' | 'denied' | 'not determined' | 'config error' * @uniPlatform * { diff --git a/uni_modules/uni-getAppBaseInfo/utssdk/app-android/index.uts b/uni_modules/uni-getAppBaseInfo/utssdk/app-android/index.uts index 8c2a05350a4cad510ab9a00ca07763d2c4acf757..353f27fa689576991955015ae09749e7ef77fc1a 100644 --- a/uni_modules/uni-getAppBaseInfo/utssdk/app-android/index.uts +++ b/uni_modules/uni-getAppBaseInfo/utssdk/app-android/index.uts @@ -39,7 +39,8 @@ export const getAppBaseInfo : GetAppBaseInfo = (config : GetAppBaseInfoOptions | "uniCompilerVersionCode", "uniRuntimeVersionCode", "packageName", - "signature" + "signature", + "appTheme", ]; filter = defaultFilter; } @@ -134,6 +135,10 @@ function getBaseInfo(filterArray : Array) : GetAppBaseInfoResult { if (filterArray.indexOf("signature") != -1) { result.signature = AppBaseInfoDeviceUtil.getAppSignatureSHA1(activity); + } + + if (filterArray.indexOf("appTheme") != -1) { + result.appTheme = UTSAndroid.getAppTheme(); } return result; diff --git a/uni_modules/uni-getAppBaseInfo/utssdk/app-ios/index.uts b/uni_modules/uni-getAppBaseInfo/utssdk/app-ios/index.uts index 754a24927b61e8fb9f94b21a6b8ab63c0d7581c4..39ca62b7dbcbfc4852a35c9cc640be54a2b9397c 100644 --- a/uni_modules/uni-getAppBaseInfo/utssdk/app-ios/index.uts +++ b/uni_modules/uni-getAppBaseInfo/utssdk/app-ios/index.uts @@ -35,7 +35,8 @@ export const getAppBaseInfo : GetAppBaseInfo = (config : GetAppBaseInfoOptions | "uniPlatform", "uniRuntimeVersion", "uniCompilerVersionCode", - "uniRuntimeVersionCode" + "uniRuntimeVersionCode", + "appTheme", ]; filter = defaultFilter; } @@ -115,6 +116,10 @@ function getBaseInfo(filterArray : Array) : GetAppBaseInfoResult { if (filterArray.indexOf("uniRuntimeVersionCode") != -1) { result.uniRuntimeVersionCode = AppBaseInfoConvertVersionCode(UTSiOS.getRuntimeVersion()); + } + + if (filterArray.indexOf("appTheme") != -1) { + result.appTheme = UTSiOS.getAppTheme(); } return result; diff --git a/uni_modules/uni-getAppBaseInfo/utssdk/interface.uts b/uni_modules/uni-getAppBaseInfo/utssdk/interface.uts index 2d027a69173e39ea206f1163107eb04a82576fa4..50f7da905a10fc743677fe32ca86e253d3094ec0 100644 --- a/uni_modules/uni-getAppBaseInfo/utssdk/interface.uts +++ b/uni_modules/uni-getAppBaseInfo/utssdk/interface.uts @@ -8,31 +8,171 @@ export type GetAppBaseInfoOptions = { export type GetAppBaseInfoResult = { /** * manifest.json 中应用appid,即DCloud appid。 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } */ appId?: string, /** * `manifest.json` 中应用名称。 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } */ appName?: string, /** * `manifest.json` 中应用版本名称。 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } */ appVersion?: string, /** * `manifest.json` 中应用版本名号。 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } */ appVersionCode?: string, /** * 应用设置的语言en、zh-Hans、zh-Hant、fr、es + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } */ appLanguage?: string, /** * 应用设置的语言 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } */ language?: string, /** * 引擎版本号。已废弃,仅为了向下兼容保留 * @deprecated 已废弃,仅为了向下兼容保留 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "x", + * "unixVer": "x" + * } + * } */ version?: string, /** @@ -205,12 +345,52 @@ export type GetAppBaseInfoResult = { hostTheme?: string, /** * 是否uni-app x + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "x", + * "unixVer": "4.18" + * } + * } */ isUniAppX ?: boolean, /** * uni 编译器版本 * @deprecated 已废弃,仅为了向下兼容保留 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "x", + * "unixVer": "x" + * } + * } */ uniCompileVersion ?: string, /** @@ -231,23 +411,83 @@ export type GetAppBaseInfoResult = { * } * }, * "web": { - * "uniVer": "√", - * "unixVer": "4.0" + * "uniVer": "x", + * "unixVer": "4.18" * } * } */ uniCompilerVersion ?: string, /** * uni-app 运行平台。 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } */ uniPlatform ?: 'app' | 'web' | 'mp-weixin' | 'mp-alipay' | 'mp-baidu' | 'mp-toutiao' | 'mp-lark' | 'mp-qq' | 'mp-kuaishou' | 'mp-jd' | 'mp-360' | 'quickapp-webview' | 'quickapp-webview-union' | 'quickapp-webview-huawei', /** * uni 运行时版本 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "x", + * "unixVer": "4.18" + * } + * } */ uniRuntimeVersion ?: string, /** * uni 编译器版本号 * @deprecated 已废弃,仅为了向下兼容保留 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "x", + * "unixVer": "x" + * } + * } */ uniCompileVersionCode?: number, /** @@ -268,14 +508,34 @@ export type GetAppBaseInfoResult = { * } * }, * "web": { - * "uniVer": "√", - * "unixVer": "4.0" + * "uniVer": "x", + * "unixVer": "4.18" * } * } */ uniCompilerVersionCode?: number, /** * uni 运行时版本号 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "x", + * "unixVer": "x" + * } + * } */ uniRuntimeVersionCode?: number, /** @@ -351,6 +611,30 @@ export type GetAppBaseInfoResult = { * } */ signature?: string, + /** + * 当前App的主题 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "x", + * "unixVer": "4.18" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "x", + * "unixVer": "4.18" + * } + * }, + * "web": { + * "uniVer": "x", + * "unixVer": "x" + * } + * } + */ + appTheme?: 'light' | 'dark' | 'auto' | null, } /** @@ -381,10 +665,10 @@ export interface Uni { * "unixVer": "4.11" * } * }, - * "web": { - * "uniVer": "√", - * "unixVer": "4.0" - * } + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } * } * @example ```typescript diff --git a/uni_modules/uni-getDeviceInfo/utssdk/app-android/device/DeviceUtil.uts b/uni_modules/uni-getDeviceInfo/utssdk/app-android/device/DeviceUtil.uts index f490a1475803e0b9e6cf270977e86cd0a345b331..02a4a647e3ecee8eff64f86a9cefdedf5d74a679 100644 --- a/uni_modules/uni-getDeviceInfo/utssdk/app-android/device/DeviceUtil.uts +++ b/uni_modules/uni-getDeviceInfo/utssdk/app-android/device/DeviceUtil.uts @@ -215,6 +215,15 @@ export class DeviceUtil { public static getOaid(): string { return UTSAndroid.getOAID(); } + + public static getRomName():string{ + DeviceUtil.setCustomInfo(Build.MANUFACTURER); + return DeviceUtil.customOS ?? ""; + } + public static getRomVersion():string{ + DeviceUtil.setCustomInfo(Build.MANUFACTURER); + return DeviceUtil.customOSVersion ?? ""; + } /** diff --git a/uni_modules/uni-getDeviceInfo/utssdk/app-android/index.uts b/uni_modules/uni-getDeviceInfo/utssdk/app-android/index.uts index a91acc5dc565b623d8ced1e7b7f05b435bbbac19..1c1449854aa9ec0d3f67c9b8d8425eb8da6af984 100644 --- a/uni_modules/uni-getDeviceInfo/utssdk/app-android/index.uts +++ b/uni_modules/uni-getDeviceInfo/utssdk/app-android/index.uts @@ -24,7 +24,14 @@ export const getDeviceInfo : GetDeviceInfo = (config : GetDeviceInfoOptions | nu "platform", "isRoot", "isSimulator", - "isUSBDebugging" + "isUSBDebugging", + "osName", + "osVersion", + "osLanguage", + "osTheme", + "osAndroidAPILevel", + "romName", + "romVersion" ]; filter = defaultFilter; } @@ -56,7 +63,7 @@ function getBaseInfo(filterArray : Array) : GetDeviceInfoResult { result.deviceId = DeviceUtil.getDeviceID(activity); } if (filterArray.indexOf("devicePixelRatio") != -1) { - result.devicePixelRatio = DeviceUtil.getScaledDensity(activity) + ""; + result.devicePixelRatio = DeviceUtil.getScaledDensity(activity); } if (filterArray.indexOf("system") != -1) { result.system = "Android " + Build.VERSION.RELEASE; @@ -72,6 +79,28 @@ function getBaseInfo(filterArray : Array) : GetDeviceInfoResult { } if (filterArray.indexOf("isUSBDebugging") != -1) { result.isUSBDebugging = DeviceUtil.listeningForADB(); + } + + if (filterArray.indexOf("osName") != -1) { + result.osName = "android"; + } + if (filterArray.indexOf("osVersion") != -1) { + result.osVersion = Build.VERSION.RELEASE; + } + if (filterArray.indexOf("osLanguage") != -1) { + result.osLanguage = UTSAndroid.getLanguageInfo(activity)["osLanguage"].toString(); + } + if (filterArray.indexOf("osTheme") != -1) { + result.osTheme = UTSAndroid.getOsTheme(); + } + if (filterArray.indexOf("osAndroidAPILevel") != -1) { + result.osAndroidAPILevel = Build.VERSION.SDK_INT; + } + if (filterArray.indexOf("romName") != -1) { + result.romName = DeviceUtil.getRomName(); + } + if (filterArray.indexOf("romVersion") != -1) { + result.romVersion = DeviceUtil.getRomVersion(); } return result; } \ No newline at end of file diff --git a/uni_modules/uni-getDeviceInfo/utssdk/app-ios/device/DeviceUtil.uts b/uni_modules/uni-getDeviceInfo/utssdk/app-ios/device/DeviceUtil.uts index 8872959dcfd2ee81bde78030e229e013caf3ca6a..a6dbd65e2d342d15a63d7a4fe88078c98310a78d 100644 --- a/uni_modules/uni-getDeviceInfo/utssdk/app-ios/device/DeviceUtil.uts +++ b/uni_modules/uni-getDeviceInfo/utssdk/app-ios/device/DeviceUtil.uts @@ -28,15 +28,6 @@ export class DeviceUtil { return orientation; } - public static getScreenScale(): string { - return UIScreen.main.scale.description; - } - - - public static getIdfa(): string { - return UTSiOS.getGgbs() - } - public static hasRootPrivilege(): boolean { return UTSiOS.isRoot() } diff --git a/uni_modules/uni-getDeviceInfo/utssdk/app-ios/index.uts b/uni_modules/uni-getDeviceInfo/utssdk/app-ios/index.uts index 703e9ae31f518f0362d278dd2fd049e0b8034534..36c344ffd02cdcd24bc1b51d2da88d0671d61450 100644 --- a/uni_modules/uni-getDeviceInfo/utssdk/app-ios/index.uts +++ b/uni_modules/uni-getDeviceInfo/utssdk/app-ios/index.uts @@ -3,6 +3,7 @@ import { UTSiOS } from "DCloudUTSFoundation"; import { DeviceUtil } from './device/DeviceUtil.uts'; import { GetDeviceInfo, GetDeviceInfoOptions, GetDeviceInfoResult } from '../interface.uts' +import { UIScreen , UIDevice ,UIApplication } from 'UIKit'; export const getDeviceInfo : GetDeviceInfo = (config : GetDeviceInfoOptions | null) : GetDeviceInfoResult => { let filter : Array = []; @@ -24,7 +25,13 @@ export const getDeviceInfo : GetDeviceInfo = (config : GetDeviceInfoOptions | nu "system", "platform", "isRoot", - "isSimulator" + "isSimulator", + "osName", + "osVersion", + "osLanguage", + "osTheme", + "romName", + "romVersion" ]; filter = defaultFilter; } @@ -57,7 +64,7 @@ function getBaseInfo(filterArray : Array) : GetDeviceInfoResult { result.deviceOrientation = DeviceUtil.getOrientation(); } if (filterArray.indexOf("devicePixelRatio") != -1) { - result.devicePixelRatio = DeviceUtil.getScreenScale(); + result.devicePixelRatio = Number.from(UIScreen.main.scale); } if (filterArray.indexOf("system") != -1) { result.system = String(format = "iOS %@", osVersion); @@ -70,6 +77,25 @@ function getBaseInfo(filterArray : Array) : GetDeviceInfoResult { } if (filterArray.indexOf("isSimulator") != -1) { result.isSimulator = UTSiOS.isSimulator(); + } + + if (filterArray.indexOf("osName") != -1) { + result.osName = "ios"; + } + if (filterArray.indexOf("osVersion") != -1) { + result.osVersion = UIDevice.current.systemVersion; + } + if (filterArray.indexOf("osLanguage") != -1) { + result.osLanguage = UTSiOS.getOsLanguage(); + } + if (filterArray.indexOf("osTheme") != -1) { + result.osTheme = UTSiOS.getOsTheme(); + } + if (filterArray.indexOf("romName") != -1) { + result.romName = "ios" + } + if (filterArray.indexOf("romVersion") != -1) { + result.romVersion = UIDevice.current.systemVersion; } return result; diff --git a/uni_modules/uni-getDeviceInfo/utssdk/interface.uts b/uni_modules/uni-getDeviceInfo/utssdk/interface.uts index 0e669e5cfe81cbe42e0097dd5b20583149ff12aa..63b82c6a977613e4a3a7a0d4a07ece52060a0b36 100644 --- a/uni_modules/uni-getDeviceInfo/utssdk/interface.uts +++ b/uni_modules/uni-getDeviceInfo/utssdk/interface.uts @@ -1,121 +1,536 @@ -export type GetDeviceInfoOptions = { - /** - * @description 过滤字段的字符串数组,假如要获取指定字段,传入此数组。 - */ - filter: Array -} - -export type GetDeviceInfoResult = { - /** - * 设备品牌 - */ - brand?: string - /** - * 设备品牌 - */ - deviceBrand?: string, - /** - * 设备 id 。由 uni-app 框架生成并存储,清空 Storage 会导致改变 - */ - deviceId?: string, - /** - * 设备型号 - */ - model?: string, - /** - * 设备型号 - */ - deviceModel?: string, - /** - * 设备类型phone、pad、pc - */ - deviceType?: string, - /** - * 设备方向 竖屏 portrait、横屏 landscape - */ - deviceOrientation?: string, - /** - * 设备像素比 - */ - devicePixelRatio?: string, - /** - * 操作系统及版本 - */ - system?: string, - /** - * 客户端平台 - */ - platform?: string, - /** - * 是否root - */ - isRoot?: boolean, - /** - * 是否是模拟器 - */ - isSimulator?: boolean, - /** - * adb是否开启 - * - * @uniPlatform - * { - * "app": { - * "android": { - * "osVer": "5.0", - * "uniVer": "x", - * "unixVer": "√" - * }, - * "ios": { - * "osVer": "x", - * "uniVer": "x", - * "unixVer": "x" - * } - * } - * } - */ - isUSBDebugging?: boolean, -} - - -/** - * @param [options=包含所有字段的过滤对象] 过滤的字段对象, 不传参数默认为获取全部字段。 - */ -export type GetDeviceInfo = (options?: GetDeviceInfoOptions | null) => GetDeviceInfoResult; - - -export interface Uni { - /** - * GetDeviceInfo(Object object) - * @description - * 获取设备信息 - * @param {GetDeviceInfoOptions} options [options=包含所有字段的过滤对象] 过滤的字段对象, 不传参数默认为获取全部字段。 - * @return {object} - * @tutorial https://uniapp.dcloud.net.cn/api/system/getDeviceInfo.html - * @uniPlatform - * { - * "app": { - * "android": { - * "osVer": "5.0", - * "uniVer": "√", - * "unixVer": "3.9+" - * }, - * "ios": { - * "osVer": "12.0", - * "uniVer": "√", - * "unixVer": "4.11" - * } - * }, - * "web": { - * "uniVer": "√", - * "unixVer": "4.0" - * } - * } - * @example - ```typescript - uni.getDeviceInfo({ - filter:[] - }) - ``` - */ - getDeviceInfo(options?: GetDeviceInfoOptions | null): GetDeviceInfoResult; -} +export type GetDeviceInfoOptions = { + /** + * @description 过滤字段的字符串数组,假如要获取指定字段,传入此数组。 + */ + filter: Array + } + + export type GetDeviceInfoResult = { + /** + * 设备品牌 + * @deprecated 已废弃,仅为了向下兼容保留 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "x", + * "unixVer": "x" + * } + * } + */ + brand?: string + /** + * 设备品牌 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "x", + * "unixVer": "x" + * } + * } + */ + deviceBrand?: string, + /** + * 设备 id 。由 uni-app 框架生成并存储,清空 Storage 会导致改变 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } + */ + deviceId?: string, + /** + * 设备型号 + * @deprecated 已废弃,仅为了向下兼容保留 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } + */ + model?: string, + /** + * 设备型号 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } + */ + deviceModel?: string, + /** + * 设备类型phone、pad、pc + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } + */ + deviceType?: 'phone' | 'pad' | 'tv' | 'watch' | 'pc' | 'undefined' | 'car' | 'vr' | 'appliance', + /** + * 设备方向 竖屏 portrait、横屏 landscape + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } + */ + deviceOrientation?: string, + /** + * 设备像素比 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } + */ + devicePixelRatio?: number, + /** + * 操作系统及版本 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } + */ + system?: string, + /** + * 客户端平台 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } + */ + platform?: 'ios' | 'android' | 'mac' | 'windows' | 'linux', + /** + * 是否root。iOS 为是否越狱 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "x", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "x", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "x", + * "unixVer": "x" + * } + * } + */ + isRoot?: boolean, + /** + * 是否是模拟器 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "x", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "x", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "x", + * "unixVer": "x" + * } + * } + */ + isSimulator?: boolean, + /** + * adb是否开启 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "x", + * "unixVer": "√" + * }, + * "ios": { + * "osVer": "x", + * "uniVer": "x", + * "unixVer": "x" + * } + * }, + * "web": { + * "uniVer": "x", + * "unixVer": "x" + * } + * } + */ + isUSBDebugging?: boolean, + /** + * 系统名称 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "x", + * "unixVer": "4.18" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "x", + * "unixVer": "4.18" + * } + * }, + * "web": { + * "uniVer": "x", + * "unixVer": "4.18" + * } + * } + */ + osName?: 'ios' | 'android' | 'macos' | 'windows' | 'linux' | null, + /** + * 操作系统版本。如 ios 版本,andriod 版本 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "x", + * "unixVer": "4.18" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "x", + * "unixVer": "4.18" + * } + * }, + * "web": { + * "uniVer": "x", + * "unixVer": "4.18" + * } + * } + */ + osVersion?: string | null, + /** + * 操作系统语言 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "x", + * "unixVer": "4.18" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "x", + * "unixVer": "4.18" + * } + * }, + * "web": { + * "uniVer": "x", + * "unixVer": "x" + * } + * } + */ + osLanguage?: string | null, + /** + * 操作系统主题 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "x", + * "unixVer": "4.18" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "x", + * "unixVer": "4.18" + * } + * }, + * "web": { + * "uniVer": "x", + * "unixVer": "x" + * } + * } + */ + osTheme?: 'light' | 'dark' | null, + /** + * Android 系统API库的版本。 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "x", + * "unixVer": "4.18" + * }, + * "ios": { + * "osVer": "x", + * "uniVer": "x", + * "unixVer": "x" + * } + * }, + * "web": { + * "uniVer": "x", + * "unixVer": "x" + * } + * } + */ + osAndroidAPILevel?: number | null, + /** + * rom 名称。Android 部分机型获取不到值。iOS 恒为 `ios` + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "x", + * "unixVer": "4.18" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "x", + * "unixVer": "4.18" + * } + * }, + * "web": { + * "uniVer": "x", + * "unixVer": "x" + * } + * } + */ + romName?: string | null, + /** + * rom 版本号。Android 部分机型获取不到值。iOS 为操作系统版本号(同 `osVersion`)。 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "x", + * "unixVer": "4.18" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "x", + * "unixVer": "4.18" + * } + * }, + * "web": { + * "uniVer": "x", + * "unixVer": "x" + * } + * } + */ + romVersion?: string | null, + } + + + /** + * @param [options=包含所有字段的过滤对象] 过滤的字段对象, 不传参数默认为获取全部字段。 + */ + export type GetDeviceInfo = (options?: GetDeviceInfoOptions | null) => GetDeviceInfoResult; + + + export interface Uni { + /** + * GetDeviceInfo(Object object) + * @description + * 获取设备信息 + * @param {GetDeviceInfoOptions} options [options=包含所有字段的过滤对象] 过滤的字段对象, 不传参数默认为获取全部字段。 + * @return {object} + * @tutorial https://uniapp.dcloud.net.cn/api/system/getDeviceInfo.html + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } + * @example + ```typescript + uni.getDeviceInfo({ + filter:[] + }) + ``` + */ + getDeviceInfo(options?: GetDeviceInfoOptions | null): GetDeviceInfoResult; + } + \ No newline at end of file diff --git a/uni_modules/uni-getLocation-system/utssdk/interface.uts b/uni_modules/uni-getLocation-system/utssdk/interface.uts index c3b7659baa70b4986df0e112a4876264c82451f1..fb831cf199e1448fa8b142a5b43cf8e7a3315081 100644 --- a/uni_modules/uni-getLocation-system/utssdk/interface.uts +++ b/uni_modules/uni-getLocation-system/utssdk/interface.uts @@ -22,16 +22,16 @@ export interface Uni { * "unixVer": "3.9.0" * }, * "ios": { - * "osVer": "x", - * "uniVer": "x", - * "unixVer": "x" + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" * } * }, * "web": { * "uniVer": "√", * "unixVer": "4.0" * } - * }9999 + * } * */ getLocation(options: GetLocationOptions):void; @@ -112,7 +112,7 @@ export type GetLocationOptions = { * 默认为 wgs84 返回 gps 坐标,gcj02 返回可用于uni.openLocation的坐标,web端需配置定位 SDK 信息才可支持 gcj02 * @defaultValue wgs84 */ - type?: "wgs84" | "gcj02" | "gps" | null, + type?: "wgs84" | "gcj02" | null, /** * 传入 true 会返回高度信息,由于获取高度需要较高精确度,会减慢接口返回速度 * @type boolean diff --git a/uni_modules/uni-getLocation-tencent/changelog.md b/uni_modules/uni-getLocation-tencent/changelog.md index e016b093be5a8e8848f780c89f2c6c99017078fd..8ae5bcdae0d1ed2fa17f8f9b852b24da1487a015 100644 --- a/uni_modules/uni-getLocation-tencent/changelog.md +++ b/uni_modules/uni-getLocation-tencent/changelog.md @@ -1,3 +1,5 @@ +## 1.1(2024-06-20) +支持iOS平台 ## 1.0.1(2023-10-23) 更新android自定义基座操作步骤 ## 1.0.0(2023-09-11) diff --git a/uni_modules/uni-getLocation-tencent/package.json b/uni_modules/uni-getLocation-tencent/package.json index 1a9c44bdc549338bebc17d7ee13a2259ecc0e6ed..c29537d751abd1f4cb5f09ba049288e22940dffd 100644 --- a/uni_modules/uni-getLocation-tencent/package.json +++ b/uni_modules/uni-getLocation-tencent/package.json @@ -1,14 +1,15 @@ { "id": "uni-getLocation-tencent", "displayName": "uni-getLocation-tencent", - "version": "1.0.1", + "version": "1.1", "description": "基于腾讯定位服务,实现uni.getLocation 获取定位功能", "keywords": [ - "uni-getLocation-tencent" + "uni.getLocation", + "tencent" ], "repository": "", "engines": { - "HBuilderX": "^3.8.12" + "HBuilderX": "^4.0" }, "dcloudext": { "type": "uts", @@ -41,7 +42,8 @@ "platforms": { "cloud": { "tcb": "y", - "aliyun": "y" + "aliyun": "y", + "alipay": "n" }, "client": { "Vue": { @@ -50,10 +52,10 @@ }, "App": { "app-android": { - "minVersion": "19" + "minVersion": "21" }, "app-ios": { - "minVersion": "9" + "minVersion": "12" } }, "H5-mobile": { diff --git a/uni_modules/uni-getLocation-tencent/readme.md b/uni_modules/uni-getLocation-tencent/readme.md index 87169df0fed3ff45650ae2487e6cac8c75c972bc..bfcd8d393936fd2a4db225b98f224a39dea99250 100644 --- a/uni_modules/uni-getLocation-tencent/readme.md +++ b/uni_modules/uni-getLocation-tencent/readme.md @@ -1,44 +1,90 @@ # uts-tencentgeolocation腾讯定位插件使用文档 +## API使用 + +参考[uni.getLocation](https://doc.dcloud.net.cn/uni-app-x/api/get-location.html) + ## Android 平台 1. 申请腾讯地图key [申请网址](https://lbs.qq.com/mobile/androidMapSDK/developerGuide/getKey) -2. 配置key到插件中 +2. 配置key到项目 + +在项目根目录下添加 AndroidManifest.xml 文件,详情参考:[Android原生应用清单文件](https://uniapp.dcloud.net.cn/tutorial/app-nativeresource-android.html#%E5%BA%94%E7%94%A8%E6%B8%85%E5%8D%95%E6%96%87%E4%BB%B6-androidmanifest-xml)。将申请的 key 配置到项目 AndroidManifest.xml 的 application 节点中,如下: +```xml + + + + + + -修改项目根目录下 AndroidManifest.xml -`` + + + +``` 3. 制作自定义基座运行后生效 +提交云端打包制作自定义基座后,再在HBuilderX中真机运行。 ## iOS 平台 -1.申请腾讯地图key +1. 申请腾讯地图key [申请网址](https://lbs.qq.com/mobile/androidMapSDK/developerGuide/getKey) -2.配置key到插件中 +2. 配置key到插件中 -将申请的key配置到插件目录下 app-ios -> info.plist 中 TencentLBSAPIKey 对应的值 +在项目根目录下添加 Info.plist 文件,详情参考:[iOS原生应用配置文件](https://uniapp.dcloud.net.cn/tutorial/app-nativeresource-ios.html#infoplist)。将申请的 key 配置到项目 Info.plist 的 TencentLBSAPIKey 键值中,如下: +```xml + + + + + TencentLBSAPIKey + 您申请的Key + + +``` +3. 配置访问位置权限描述信息 +在项目根目录下 Info.plist 文件中添加以下权限描述信息: ```xml -TencentLBSAPIKey -您申请的Key + + + + + NSLocationAlwaysUsageDescription + 后台运行期访问位置信息的许可描述 + NSLocationWhenInUseUsageDescription + 运行期访问位置信息的许可描述 + NSLocationAlwaysAndWhenInUseUsageDescription + 访问位置信息的许可描述 + + ``` -3.配置访问位置权限描述信息 +> 许可描述信息需根据应用实际业务情况准确描述,否则可能无法通过 AppStore 上架审核 +> uni-app 项目也可以在 manifest.json 的 "App权限配置" 可视化界面的 "iOS隐私信息访问的许可描述" 下配置 + +3. 制作自定义基座运行后生效 +提交云端打包制作自定义基座后,再在HBuilderX中真机运行。 + +## 注意事项 + +### 隐私合规问题 +此插件使用了腾讯位置服务SDK,调用定位API会采集个人隐私信息,在业务中请确保最终用户已经同意了App的隐私协议后再调用定位API,否则会因为隐私合规问题无法上架应用市场。 -选中工程中的 manifest.json -> App权限配置 -> iOS隐私信息访问的许可描述,分别配置下列权限描述信息 +App的隐私政策中需披露使用的三方SDK相关情况: -- NSLocationAlwaysUsageDescription -- NSLocationWhenInUseUsageDescription -- NSLocationAlwaysAndWhenInUseUsageDescription +- Android平台腾讯位置服务SDK [合规说明](https://lbs.qq.com/mobile/androidLocationSDK/androidLBSInfo) +- iOS平台腾讯位置服务SDK [合规说明](https://lbs.qq.com/mobile/iosLocationSDK/iosLBSInfo) -4.制作自定义基座运行后生效 ## 相关开发文档 - [UTS 语法](https://uniapp.dcloud.net.cn/tutorial/syntax-uts.html) -- [UTS 原生插件](https://uniapp.dcloud.net.cn/plugin/uts-plugin.html) +- [UTS 插件开发文档](https://doc.dcloud.net.cn/uni-app-x/plugin/uts-plugin.html) diff --git a/uni_modules/uni-getLocation-tencent/utssdk/app-android/config.json b/uni_modules/uni-getLocation-tencent/utssdk/app-android/config.json index f7f9ab61cde5d32e0947692c782bf94458af5ea1..c4cc614767ed0821f8b4a52c1c62ee69556cd2a6 100644 --- a/uni_modules/uni-getLocation-tencent/utssdk/app-android/config.json +++ b/uni_modules/uni-getLocation-tencent/utssdk/app-android/config.json @@ -2,6 +2,6 @@ "dependencies": [ "com.tencent.map.geolocation:TencentLocationSdk-openplatform:7.3.0" ], - "minSdkVersion": "19" + "minSdkVersion": "21" } diff --git a/uni_modules/uni-getLocation-tencent/utssdk/app-ios/Frameworks/TencentLBS.framework/Headers/TencentLBS.h b/uni_modules/uni-getLocation-tencent/utssdk/app-ios/Frameworks/TencentLBS.framework/Headers/TencentLBS.h new file mode 100644 index 0000000000000000000000000000000000000000..874d4f9eb7dc32530762ec83aecf8308902273a0 --- /dev/null +++ b/uni_modules/uni-getLocation-tencent/utssdk/app-ios/Frameworks/TencentLBS.framework/Headers/TencentLBS.h @@ -0,0 +1,21 @@ +// +// TencentLBS.h +// TencentLBS +// +// Created by mirantslu on 16/4/19. +// Copyright © 2016年 Tencent. All rights reserved. +// + +#import + +//! Project version number for TencentLBS. +FOUNDATION_EXPORT double TencentLBSVersionNumber; + +//! Project version string for TencentLBS. +FOUNDATION_EXPORT const unsigned char TencentLBSVersionString[]; + +// In this header, you should import all the public headers of your framework using statements like #import + +#import +#import +#import diff --git a/uni_modules/uni-getLocation-tencent/utssdk/app-ios/Frameworks/TencentLBS.framework/Headers/TencentLBSLocation.h b/uni_modules/uni-getLocation-tencent/utssdk/app-ios/Frameworks/TencentLBS.framework/Headers/TencentLBSLocation.h new file mode 100644 index 0000000000000000000000000000000000000000..b4263ecf7e0d89eabb1b680548b29fb3c0a49501 --- /dev/null +++ b/uni_modules/uni-getLocation-tencent/utssdk/app-ios/Frameworks/TencentLBS.framework/Headers/TencentLBSLocation.h @@ -0,0 +1,166 @@ +// +// TencentLBSLocation.h +// TencentLBS +// +// Created by mirantslu on 16/4/19. +// Copyright © 2016年 Tencent. All rights reserved. +// + +#import +#import + +NS_ASSUME_NONNULL_BEGIN + +#define TENCENTLBS_DEBUG 0 + +typedef NS_ENUM(NSInteger, TencentLBSDRProvider) { + TencentLBSDRProviderError = -2, //!< 错误,可能未开启dr + TencentLBSDRProviderUnkown = -1, //!< 定位结果来源未知 + TencentLBSDRProviderFusion = 0, //!< 定位结果来源融合的结果 + TencentLBSDRProviderGPS = 1, //!< 定位结果来源GPS + TencentLBSDRProviderNetWork = 2, //!< 定位结果来源网络 +}; + +@interface TencentLBSPoi : NSObject + +@property (nonatomic, copy) NSString *uid; //!< 当前POI的uid +@property (nonatomic, copy) NSString *name; //!< 当前POI的名称 +@property (nonatomic, copy) NSString *address; //!< 当前POI的地址 +@property (nonatomic, copy) NSString *catalog; //!< 当前POI的类别 +@property (nonatomic, assign) double longitude; //!< 当前POI的经度 +@property (nonatomic, assign) double latitude; //!< 当前POI的纬度 +@property (nonatomic, assign) double distance; //!< 当前POI与当前位置的距离 + +@end + +@interface TencentLBSLocation : NSObject + +/** + * 返回当前位置的CLLocation信息 + */ +@property (nonatomic, strong) CLLocation *location; + +/** + * 返回当前位置的行政区划, 0-表示中国大陆、港、澳, 1-表示其他 + */ +@property (nonatomic, assign) NSInteger areaStat; + +/** + * 返回室内定位楼宇Id + */ +@property (nonatomic, copy, nullable) NSString *buildingId; + +/** + * 返回室内定位楼层 + */ +@property (nonatomic, copy, nullable) NSString *buildingFloor; + +/** + * 返回室内定位类型,0表示普通定位结果,1表示蓝牙室内定位结果 + */ +@property (nonatomic, assign) NSInteger indoorLocationType; + +/** + * + */ +@property (nonatomic, assign) TencentLBSDRProvider drProvider; + +/** + * 返回当前位置的名称, + * 仅当TencentLBSRequestLevel为TencentLBSRequestLevelName或TencentLBSRequestLevelAdminName或TencentLBSRequestLevelPoi有返回值,否则为空 + */ +@property (nonatomic, copy, nullable) NSString *name; + +/** + * 返回当前位置的地址 + * 仅当TencentLBSRequestLevel为TencentLBSRequestLevelName或TencentLBSRequestLevelAdminName有返回值,否则为空 + */ +@property (nonatomic, copy, nullable) NSString *address; + +/** + * 返回国家编码,例如中国为156 + * 注意:该接口涉及到WebService API,请参考https://lbs.qq.com/service/webService/webServiceGuide/webServiceOverview中的配额限制说明, + * 并将申请的有效key通过TencentLBSLocationManager的- (void)setDataWithValue: forKey:方法设置,其中key为固定值@"ReGeoCodingnKey",例如[tencentLocationManager setDataWithValue:@"您申请的key(务必正确)" forKey:@"ReGeoCodingnKey"];,否则将返回默认值0 + */ +@property (nonatomic, assign) NSInteger nationCode; + +/** + * 返回当前位置的城市编码 + * 仅当TencentLBSRequestLevel为TencentLBSRequestLevelAdminName或TencentLBSRequestLevelPoi有返回值,否则为空 + */ +@property (nonatomic, copy, nullable) NSString *code; + +/** + * 返回当前位置的国家 + * 仅当TencentLBSRequestLevel为TencentLBSRequestLevelAdminName或TencentLBSRequestLevelPoi有返回值,否则为空 + */ +@property (nonatomic, copy, nullable) NSString *nation; + +/** + * 返回当前位置的省份 + * 仅当TencentLBSRequestLevel为TencentLBSRequestLevelAdminName或TencentLBSRequestLevelPoi有返回值,否则为空 + */ +@property (nonatomic, copy, nullable) NSString *province; + +/** + * 返回当前位置的城市固话编码. + * 仅当TencentLBSRequestLevel为TencentLBSRequestLevelAdminName或TencentLBSRequestLevelPoi有返回值,否则为空 + */ +@property (nonatomic, copy, nullable) NSString *cityPhoneCode; + +/** + * 返回当前位置的城市 + * 仅当TencentLBSRequestLevel为TencentLBSRequestLevelAdminName或TencentLBSRequestLevelPoi有返回值,否则为空 + */ +@property (nonatomic, copy, nullable) NSString *city; + +/** + * 返回当前位置的区县 + * 仅当TencentLBSRequestLevel为TencentLBSRequestLevelAdminName或TencentLBSRequestLevelPoi有返回值,否则为空 + */ +@property (nonatomic, copy, nullable) NSString *district; + +/** + * 返回当前位置的乡镇 + * 仅当TencentLBSRequestLevel为TencentLBSRequestLevelAdminName或TencentLBSRequestLevelPoi有返回值,否则为空 + */ +@property (nonatomic, copy, nullable) NSString *town; + +/** + * 返回当前位置的村 + * 仅当TencentLBSRequestLevel为TencentLBSRequestLevelAdminName或TencentLBSRequestLevelPoi有返回值,否则为空 + */ +@property (nonatomic, copy, nullable) NSString *village; + +/** + * 返回当前位置的街道 + * 仅当TencentLBSRequestLevel为TencentLBSRequestLevelAdminName或TencentLBSRequestLevelPoi有返回值,否则为空 + */ +@property (nonatomic, copy, nullable) NSString *street; + +/** + * 返回当前位置的街道编码 + * 仅当TencentLBSRequestLevel为TencentLBSRequestLevelAdminName或TencentLBSRequestLevelPoi有返回值,否则为空 + */ +@property (nonatomic, copy, nullable) NSString *street_no; + +/** + * 返回当前位置周围的POI + * 仅当TencentLBSRequestLevel为TencentLBSRequestLevelPoi有返回值,否则为空 + */ +@property (nonatomic, strong, nullable) NSArray *poiList; + +/** + * 返回两个位置之间的横向距离 + * @param location + */ +- (double)distanceFromLocation:(const TencentLBSLocation *)location; + +// 测试使用 +#if TENCENTLBS_DEBUG +@property (nonatomic, copy, nullable) NSString *halleyTime; +#endif + +@end + +NS_ASSUME_NONNULL_END diff --git a/uni_modules/uni-getLocation-tencent/utssdk/app-ios/Frameworks/TencentLBS.framework/Headers/TencentLBSLocationManager.h b/uni_modules/uni-getLocation-tencent/utssdk/app-ios/Frameworks/TencentLBS.framework/Headers/TencentLBSLocationManager.h new file mode 100644 index 0000000000000000000000000000000000000000..e94a380dd70174a0f3d76613ac49cda22a0494ed --- /dev/null +++ b/uni_modules/uni-getLocation-tencent/utssdk/app-ios/Frameworks/TencentLBS.framework/Headers/TencentLBSLocationManager.h @@ -0,0 +1,374 @@ +// +// TencentLBSLocationManager.h +// TencentLBS +// +// Created by mirantslu on 16/4/19. +// Copyright © 2016年 Tencent. All rights reserved. +// + +#import +#import +#import "TencentLBSLocation.h" + +NS_ASSUME_NONNULL_BEGIN + +typedef NS_ENUM(NSUInteger, TencentLBSRequestLevel) { + TencentLBSRequestLevelGeo = 0, + TencentLBSRequestLevelName = 1, + TencentLBSRequestLevelAdminName = 3, + TencentLBSRequestLevelPoi = 4, +}; + +typedef NS_ENUM(NSUInteger, TencentLBSLocationCoordinateType) { + TencentLBSLocationCoordinateTypeGCJ02 = 0, //!< 火星坐标,即国测局坐标 + TencentLBSLocationCoordinateTypeWGS84 = 1, //!< 地球坐标,注:如果是海外,无论设置的是火星坐标还是地球坐标,返回的都是地球坐标 +}; + +typedef NS_ENUM(NSUInteger, TencentLBSLocationError) { + TencentLBSLocationErrorUnknown = 0, //!< 错误码,表示目前位置未知,但是会一直尝试获取 + TencentLBSLocationErrorDenied = 1, //!< 错误码,表示定位权限被禁止 + TencentLBSLocationErrorNetwork = 2, //!< 错误码,表示网络错误 + TencentLBSLocationErrorHeadingFailure = 3, //!< 错误码,表示朝向无法确认 + TencentLBSLocationErrorOther = 4, //!< 错误码,表示未知错误 +}; + +typedef NS_ENUM(NSInteger, TencentLBSDRStartCode) { + TencentLBSDRStartCodeSuccess = 0, //!< 启动成功 + TencentLBSDRStartCodeNotSupport = -1, //!< 传感器有缺失或没有GPS芯片 + TencentLBSDRStartCodeHasStarted = -2, //!< 已经启动 + TencentLBSDRStartCodeSensorFailed = -3, //!< 传感器启动失败 + TencentLBSDRStartCodeGpsFailed = -4, //!< GPS启动失败 + TencentLBSDRStartCodePermissionFailed = -5, //!< 没有位置权限 + TencentLBSDRStartCodeUnkown = -6, //!< 未知 +}; +typedef NS_ENUM(NSInteger, TencentLBSDRStartMotionType) { + TencentLBSDRStartMotionTypeWalk = 2, //!< 步行 + TencentLBSDRStartMotionTypeBike = 3, //!< 骑行 +}; + +typedef NS_ENUM(NSInteger, TencentLBSAccuracyAuthorization) { + // This application has the user's permission to receive accurate location information. + TencentLBSAccuracyAuthorizationFullAccuracy, + + // The user has chosen to grant this application access to location information with reduced accuracy. + // Region monitoring and beacon ranging are not available to the application. Other CoreLocation APIs + // are available with reduced accuracy. + + // Location estimates will have a horizontalAccuracy on the order of about 5km. To achieve the + // reduction in accuracy, CoreLocation will snap location estimates to a nearby point which represents + // the region the device is in. Furthermore, CoreLocation will reduce the rate at which location + // estimates are produced. Applications should be prepared to receive locations that are up to 20 + // minutes old. + TencentLBSAccuracyAuthorizationReducedAccuracy, +}; + +/** + * TencentLBSLocatingCompletionBlock 单次定位返回Block + * + * @param location 位置信息 + * @param error 错误信息 参考 TencentLBSLocationError + */ +typedef void (^TencentLBSLocatingCompletionBlock)(TencentLBSLocation * _Nullable location, NSError * _Nullable error); + +@protocol TencentLBSLocationManagerDelegate; + +@interface TencentLBSLocationManager : NSObject +/** + * 当前位置管理器定位精度的授权状态 + */ +@property(nonatomic, readonly)TencentLBSAccuracyAuthorization accuracyAuthorization; +/** + * 当前位置管理器定位权限的授权状态 + */ +@property(nonatomic, readonly)CLAuthorizationStatus authorizationStatus; + +/** + * API Key, 在使用定位SDK服务之前需要先绑定key。 + */ +@property (nonatomic, copy) NSString* apiKey; + + +/** + * 实现了 TencentLBSLocationManagerDelegate 协议的类指针。 + */ +@property (nonatomic, weak) id delegate; + +/** + * 设定定位的最小更新距离。默认为 kCLDistanceFilterNone。 + */ +@property (nonatomic, assign) CLLocationDistance distanceFilter; + +/** + * 设定定位精度。默认为 kCLLocationAccuracyBest 。 + */ +@property (nonatomic, assign) CLLocationAccuracy desiredAccuracy; + +/** + * 指定定位是否会被系统自动暂停。默认为 YES 。 + */ +@property (nonatomic, assign) BOOL pausesLocationUpdatesAutomatically; + +/** + * 是否允许后台定位。默认为 NO。 + * iOS 9.0 以上用户需要设置该选项并且在info.list里面Background Modes 中的 Location updates 处于选中状态才可以使用后台定位权限。iOS 9.0之前可以直接申请总是使用的权限来获得后台定位。 + * + * 设置为 YES 的时候必须保证 Background Modes 中的 Location updates 处于选中状态,否则会抛出异常。 + */ +@property (nonatomic, assign) BOOL allowsBackgroundLocationUpdates; + +/** + * 用户的活动类型 + * + * 设置用户的活动类型。默认值为 CLActivityTypeOther + */ +@property (nonatomic, assign) CLActivityType activityType; + +/** + * 设置当朝向改变时,每隔多少度调用一次 + * 只有当设备方向的改变值超过该属性值时才激发delegate的方法。 + */ +@property(nonatomic, assign) CLLocationDegrees headingFilter; + +/** + * 设置设备当前的朝向 + */ +@property(nonatomic, assign) CLDeviceOrientation headingOrientation; + +/** + * 连续定位的逆地理信息请求的Level。默认为TencentLBSRequestLevelGeo + */ +@property (nonatomic, assign) TencentLBSRequestLevel requestLevel; + +/** + * 返回的TencentLBSLocation的location字段的坐标类型。默认为TencentLBSLocationCoordinateTypeGCJ02。 + * + * 在一次定位过程中,只允许设置一次,不允许重复设置 + */ +@property (nonatomic, assign) TencentLBSLocationCoordinateType coordinateType; + +/** + * 指定POI的更新间隔。 默认是10s + */ +@property(nonatomic, assign) NSInteger poiUpdateInterval; +#pragma mark - +/** + * accuracyAuthorization + * + * Discussion: + * Return the current TencentLBSAccuracyAuthorization of the calling application. + */ ++ (TencentLBSAccuracyAuthorization)accuracyAuthorization; + +/** + * 设置用户是否同意隐私协议政策 + *

调用其他接口前必须首先调用此接口进行用户是否同意隐私政策的设置,传入YES后才能正常使用定位功能,否则TencentLBSLocationManager初始化不成功,返回nil,定位功能均无法使用

+ * @param isAgree 是否同意隐私政策 + */ ++ (void)setUserAgreePrivacy:(BOOL) isAgree; + +/** + * 获取用户是否同意隐私政策协议 + *

设置用户隐私后,可通过该接口判断用户隐私状态

+ * @return isAgreePrivacy 是否同意隐私政策 + */ ++ (BOOL)getUserAgreePrivacy; + +#pragma mark - + +- (void)requestWhenInUseAuthorization; + +- (void)requestAlwaysAuthorization; + +/** + * 当前属于模糊定位状态时,通过该接口请求暂时的完全定位精度的权限 + * @param purposeKey 需要在info.plist中配置NSLocationTemporaryUsageDescriptionDictionary key值和对应的申请该权限的描述理由 + * @param completion 在弹框让用户选择后的用户的反馈,如果用户授予该权限,block中的参数为nil,如果未授予,block中的参数将为PurposeKey对于的key的描述(如PurposeKey=TemporaryPurposKey_1) + */ +- (void)requestTemporaryFullAccuracyAuthorizationWithPurposeKey:(NSString *)purposeKey + completion:(void (^)(NSError *))completion; +/** + * 当前属于模糊定位状态时,通过该接口请求暂时的完全定位精度的权限 + * @param purposeKey 需要在info.plist中配置NSLocationTemporaryUsageDescriptionDictionary key值和对应的申请该权限的描述理由 + */ +- (void)requestTemporaryFullAccuracyAuthorizationWithPurposeKey:(NSString *)purposeKey; + + +#pragma mark - +/** + * 获取定位SDK的版本 + */ ++(NSString *)getLBSSDKVersion; + +/** + * 获取定位SDK的构建日期 + */ ++(NSString *)getLBSSDKbuild; + + +#pragma mark - + +/** + * 向SDK内部设置数据,以满足定制的需求 + * @param value + * @param key + */ +- (void)setDataWithValue:(NSString *)value forKey:(NSString *)key; + +/** + * 单次定位 + * + * 该方法为下面方法的一层封装。 + * level默认是TencentLBSRequestLevelPoi + * timeout默认是10s + */ +- (BOOL)requestLocationWithCompletionBlock:(TencentLBSLocatingCompletionBlock)completionBlock; + +/** + * 单次定位 + * + * 注意:不能连续调用该接口,需在上一次返回之后才能再次发起调用。该接口兼容iOS 7.0及以上,因iOS 9.0系统提供单次定位能力,故在9.0以上会调用系统单次定位接口,9.0之前SDK完成封装。可以通过调用cancelRequestLocation来取消。 + * + * @param level 可以根据此参数来对应的获取POI信息 + * @param timeout 表示获取POI的超时时间。 + * @param completionBlock 单次定位完成后的Block + */ +- (BOOL)requestLocationWithRequestLevel:(TencentLBSRequestLevel)level + locationTimeout:(NSTimeInterval)timeout + completionBlock:(TencentLBSLocatingCompletionBlock)completionBlock; + +/** + * 取消单次定位 + **/ +- (void)cancelRequestLocation; + +/** + * 开始连续定位 + */ +- (void)startUpdatingLocation; + +/** + * 停止连续定位 + */ +- (void)stopUpdatingLocation; + +/** + * 开启更新定位朝向 + */ +- (void)startUpdatingHeading; + +/** + * 结束更新定位朝向 + */ +- (void)stopUpdatingHeading; + +/** + * 停止展示定位朝向校准提示 + */ +- (void)dismissHeadingCalibrationDisplay; + +#pragma mark - PDR 对外接口 +/** + * 主动获取DR实时融合位置,调用startDrEngine:成功后才可能有值,业务可根据自己的频率主动获取 + * @return DR融合后的定位结果 + */ +-(TencentLBSLocation *)getPosition; + +/** + * 启动DR引擎。引擎会自动获取传感器和GPS数据,并进行位置计算。 + * 启动后DR引擎会主动开启CLLocationManager startUpdatingLocation。 + * + * 注意:请确保调用之前已获取位置权限(使用期间或者始终允许) + * + * @param type 运动类型 目前支持,参考TencentLBSDRStartMotionType + * @return 返回码,参考TencentLBSDRStartCode + */ +-(TencentLBSDRStartCode)startDrEngine:(TencentLBSDRStartMotionType)type; + +/** + * 停止DR引擎。内部有极短时间延迟,若在此期间调用TencentLBSLocationManager startDrEngine:可能导致启动不成功。 + */ +-(void)terminateDrEngine; + +/** + * 是否支持DR引擎 + * @return + */ +-(BOOL)isSupport; + +#pragma mark - test used +// 测试使用 +#if TENCENTLBS_DEBUG ++ (void)upLoadData; ++ (NSData *)getLocationLog; ++ (void)newLocationLog; +#endif + +@end + + +#pragma mark - TencentLBSLocationManagerDelegate + +/** + * TencentLBSLocationManagerDelegate + * 定义了发生错误时的错误回调方法,连续定位的回调方法等。 + */ +@protocol TencentLBSLocationManagerDelegate +@optional + +/** + * 当定位发生错误时,会调用代理的此方法 + * + * @param manager 定位 TencentLBSLocationManager 类 + * @param error 返回的错误,参考 TencentLBSLocationError + */ +- (void)tencentLBSLocationManager:(TencentLBSLocationManager *)manager + didFailWithError:(NSError *)error; + +/** + * 连续定位回调函数 + * + * @param manager 定位 TencentLBSLocationManager 类 + * @param location 定位结果 + */ +- (void)tencentLBSLocationManager:(TencentLBSLocationManager *)manager + didUpdateLocation:(TencentLBSLocation *)location; + +/** + * 定位权限状态改变时回调函数 + * @deprecated 在iOS 14及以上废弃,由tencentLBSDidChangeAuthorization:代替 + * @param manager 定位 TencentLBSLocationManager 类 + * @param status 定位权限状态 + */ +- (void)tencentLBSLocationManager:(TencentLBSLocationManager *)manager + didChangeAuthorizationStatus:(CLAuthorizationStatus)status; + +/** + * 定位权限状态改变时回调函数 + * @param manager 定位 TencentLBSLocationManager 类,由此访问authorizationStatus,accuracyAuthorization + */ +- (void)tencentLBSDidChangeAuthorization:(TencentLBSLocationManager *)manager; + +/** + * 定位朝向改变时回调函数 + * + * @param manager 定位 TencentLBSLocationManager 类 + * @param newHeading 新的定位朝向 + */ +- (void)tencentLBSLocationManager:(TencentLBSLocationManager *)manager + didUpdateHeading:(CLHeading *)newHeading; + +/** + * 是否展示定位朝向校准提示的回调函数 + * + * @param manager 定位 TencentLBSLocationManager 类 + */ +- (BOOL)tencentLBSLocationManagerShouldDisplayHeadingCalibration:(TencentLBSLocationManager *)manager; + +/** + * 只是内部调试使用,外部不应实现该接口 + */ +- (void)tencentLBSLocationManager:(TencentLBSLocationManager *)manager didThrowLocation:(TencentLBSLocation *)location; + +@end + +NS_ASSUME_NONNULL_END diff --git a/uni_modules/uni-getLocation-tencent/utssdk/app-ios/Frameworks/TencentLBS.framework/Headers/TencentLBSLocationUtils.h b/uni_modules/uni-getLocation-tencent/utssdk/app-ios/Frameworks/TencentLBS.framework/Headers/TencentLBSLocationUtils.h new file mode 100644 index 0000000000000000000000000000000000000000..61d838b23729cdd6a8bee35a5e1e0aaf56180455 --- /dev/null +++ b/uni_modules/uni-getLocation-tencent/utssdk/app-ios/Frameworks/TencentLBS.framework/Headers/TencentLBSLocationUtils.h @@ -0,0 +1,55 @@ +// +// TencentLBSLocationUtils.h +// TencentLBS +// +// Created by mirantslu on 16/8/11. +// Copyright © 2016年 Tencent. All rights reserved. +// + +#import +#import + +@class TencentLBSLocation; + +NS_ASSUME_NONNULL_BEGIN + +@interface TencentLBSLocationUtils : NSObject +/** + * 计算两个坐标点的距离 + */ ++ (double)distanceBetweenTwoCoordinate2D:(const CLLocationCoordinate2D *)coordinate coordinateTwo:(const CLLocationCoordinate2D *)coordinate2; +/** + * 计算两个location的距离 + */ ++ (double)distanceBetweenTwoCLLocations:(const CLLocation *)location locationTwo:(const CLLocation *)location2; + +/** + * 计算两个TencentLBSLocation的距离 + */ ++ (double)distanceBetweenTwoTencentLBSLocations:(const TencentLBSLocation *)location locationTwo:(const TencentLBSLocation *)location2; + +/** + * 判断经纬度是否在国内 + * + */ ++ (BOOL) isInRegionWithLatitude:(double)latitude longitude:(double)longitude; + +/** + * wgs84坐标转成gcj02坐标 + */ ++ (CLLocationCoordinate2D)WGS84TOGCJ02:(CLLocationCoordinate2D)coordinate; + +@end + +@interface TencentLBSServiceManager : NSObject + +/** + * 设置ID,如QQ号,微信号或是其他的登录账号,可用在发布前联调使用 + */ +@property (atomic, copy) NSString *deviceID; + ++ (instancetype)sharedInsance; + +@end + +NS_ASSUME_NONNULL_END diff --git a/uni_modules/uni-getLocation-tencent/utssdk/app-ios/Frameworks/TencentLBS.framework/Info.plist b/uni_modules/uni-getLocation-tencent/utssdk/app-ios/Frameworks/TencentLBS.framework/Info.plist new file mode 100644 index 0000000000000000000000000000000000000000..3272071972e9722e88e33dcc59123acdd59853ce Binary files /dev/null and b/uni_modules/uni-getLocation-tencent/utssdk/app-ios/Frameworks/TencentLBS.framework/Info.plist differ diff --git a/uni_modules/uni-getLocation-tencent/utssdk/app-ios/Frameworks/TencentLBS.framework/Modules/module.modulemap b/uni_modules/uni-getLocation-tencent/utssdk/app-ios/Frameworks/TencentLBS.framework/Modules/module.modulemap new file mode 100644 index 0000000000000000000000000000000000000000..98a2c8be9e247ed644acf89ae102761c78b3dac7 --- /dev/null +++ b/uni_modules/uni-getLocation-tencent/utssdk/app-ios/Frameworks/TencentLBS.framework/Modules/module.modulemap @@ -0,0 +1,6 @@ +framework module TencentLBS { + umbrella header "TencentLBS.h" + + export * + module * { export * } +} diff --git a/uni_modules/uni-getLocation-tencent/utssdk/app-ios/Frameworks/TencentLBS.framework/TencentLBS b/uni_modules/uni-getLocation-tencent/utssdk/app-ios/Frameworks/TencentLBS.framework/TencentLBS new file mode 100644 index 0000000000000000000000000000000000000000..41e00e17a701bccbf638b6890856b849dd9c30b4 Binary files /dev/null and b/uni_modules/uni-getLocation-tencent/utssdk/app-ios/Frameworks/TencentLBS.framework/TencentLBS differ diff --git a/uni_modules/uni-getLocation-tencent/utssdk/app-ios/Frameworks/TencentLBS.framework/_CodeSignature/CodeDirectory b/uni_modules/uni-getLocation-tencent/utssdk/app-ios/Frameworks/TencentLBS.framework/_CodeSignature/CodeDirectory new file mode 100644 index 0000000000000000000000000000000000000000..faa399a40e895258432ed51106d9295f1daf7c4b Binary files /dev/null and b/uni_modules/uni-getLocation-tencent/utssdk/app-ios/Frameworks/TencentLBS.framework/_CodeSignature/CodeDirectory differ diff --git a/uni_modules/uni-getLocation-tencent/utssdk/app-ios/Frameworks/TencentLBS.framework/_CodeSignature/CodeRequirements b/uni_modules/uni-getLocation-tencent/utssdk/app-ios/Frameworks/TencentLBS.framework/_CodeSignature/CodeRequirements new file mode 100644 index 0000000000000000000000000000000000000000..dd335c9b978c1c584b9a66275524e4be358ec3f5 Binary files /dev/null and b/uni_modules/uni-getLocation-tencent/utssdk/app-ios/Frameworks/TencentLBS.framework/_CodeSignature/CodeRequirements differ diff --git a/uni_modules/uni-getLocation-tencent/utssdk/app-ios/Frameworks/TencentLBS.framework/_CodeSignature/CodeRequirements-1 b/uni_modules/uni-getLocation-tencent/utssdk/app-ios/Frameworks/TencentLBS.framework/_CodeSignature/CodeRequirements-1 new file mode 100644 index 0000000000000000000000000000000000000000..8ed917cbafd3184a4d9e1bdf7b1619a40a8e1c23 Binary files /dev/null and b/uni_modules/uni-getLocation-tencent/utssdk/app-ios/Frameworks/TencentLBS.framework/_CodeSignature/CodeRequirements-1 differ diff --git a/uni_modules/uni-getLocation-tencent/utssdk/app-ios/Frameworks/TencentLBS.framework/_CodeSignature/CodeResources b/uni_modules/uni-getLocation-tencent/utssdk/app-ios/Frameworks/TencentLBS.framework/_CodeSignature/CodeResources new file mode 100644 index 0000000000000000000000000000000000000000..a9d7c4e4bc5d915b07943e3e9ca0de7906979e36 --- /dev/null +++ b/uni_modules/uni-getLocation-tencent/utssdk/app-ios/Frameworks/TencentLBS.framework/_CodeSignature/CodeResources @@ -0,0 +1,177 @@ + + + + + files + + Headers/TencentLBS.h + + hPC0/pGd4xrqNOXCT59Bc4EZx1o= + + Headers/TencentLBSLocation.h + + NTNAtRb6zd+vtrq8nFcrm/TvTno= + + Headers/TencentLBSLocationManager.h + + CqufUOM9qpXc8PkBQcTH7nFlxHU= + + Headers/TencentLBSLocationUtils.h + + ctiCEOKB25KPpldhCiCitDpWjsc= + + Info.plist + + dF6t7k2l2ACuPcw4w8e+8pX3Ds8= + + Modules/module.modulemap + + jS4bVEIZ8y6+mkDDypFhD0RkQVg= + + + files2 + + Headers/TencentLBS.h + + hash + + hPC0/pGd4xrqNOXCT59Bc4EZx1o= + + hash2 + + rXSLg9Gmqf/qi8hc0spd2V99ElDyGiIgDgvN30bahIQ= + + + Headers/TencentLBSLocation.h + + hash + + NTNAtRb6zd+vtrq8nFcrm/TvTno= + + hash2 + + LmWBqRV/iCuLqRmuUPDGqTOz3n2XBrAIRkPpulu9Dms= + + + Headers/TencentLBSLocationManager.h + + hash + + CqufUOM9qpXc8PkBQcTH7nFlxHU= + + hash2 + + ozYu6o4odbCMlj5n6GijSLmHlND06j8bgS/wHNmwwkI= + + + Headers/TencentLBSLocationUtils.h + + hash + + ctiCEOKB25KPpldhCiCitDpWjsc= + + hash2 + + clmnufMVF2VLg4uOOY70pixlfbrZK20rr/iOxOF4+E4= + + + Modules/module.modulemap + + hash + + jS4bVEIZ8y6+mkDDypFhD0RkQVg= + + hash2 + + j/3Yn2sASML4eiVUc877N1Qdw84cRUiapBx3Gc88OUI= + + + + rules + + ^.* + + ^.*\.lproj/ + + optional + + weight + 1000 + + ^.*\.lproj/locversion.plist$ + + omit + + weight + 1100 + + ^Base\.lproj/ + + weight + 1010 + + ^version.plist$ + + + rules2 + + .*\.dSYM($|/) + + weight + 11 + + ^(.*/)?\.DS_Store$ + + omit + + weight + 2000 + + ^.* + + ^.*\.lproj/ + + optional + + weight + 1000 + + ^.*\.lproj/locversion.plist$ + + omit + + weight + 1100 + + ^Base\.lproj/ + + weight + 1010 + + ^Info\.plist$ + + omit + + weight + 20 + + ^PkgInfo$ + + omit + + weight + 20 + + ^embedded\.provisionprofile$ + + weight + 20 + + ^version\.plist$ + + weight + 20 + + + + diff --git a/uni_modules/uni-getLocation-tencent/utssdk/app-ios/Frameworks/TencentLBS.framework/_CodeSignature/CodeSignature b/uni_modules/uni-getLocation-tencent/utssdk/app-ios/Frameworks/TencentLBS.framework/_CodeSignature/CodeSignature new file mode 100644 index 0000000000000000000000000000000000000000..ff8a8f10cb05d203edd065618f8897ec7cf67ada Binary files /dev/null and b/uni_modules/uni-getLocation-tencent/utssdk/app-ios/Frameworks/TencentLBS.framework/_CodeSignature/CodeSignature differ diff --git a/uni_modules/uni-getLocation-tencent/utssdk/app-ios/config.json b/uni_modules/uni-getLocation-tencent/utssdk/app-ios/config.json index 721b81e0240705a87ec0761aa9eb6f4e188769cb..2cd4fcd4741fb1ee6b181b77ddf9862615161bc4 100644 --- a/uni_modules/uni-getLocation-tencent/utssdk/app-ios/config.json +++ b/uni_modules/uni-getLocation-tencent/utssdk/app-ios/config.json @@ -1,3 +1,5 @@ { - "deploymentTarget": "9" + "frameworks": [ + "libz.1.2.5.tbd" + ],"deploymentTarget": "12" } \ No newline at end of file diff --git a/uni_modules/uni-getLocation-tencent/utssdk/app-ios/index.uts b/uni_modules/uni-getLocation-tencent/utssdk/app-ios/index.uts new file mode 100644 index 0000000000000000000000000000000000000000..4388d367917caf602e3f3f6b37cffc1c16476eec --- /dev/null +++ b/uni_modules/uni-getLocation-tencent/utssdk/app-ios/index.uts @@ -0,0 +1,213 @@ +import { CLLocationManager, CLAuthorizationStatus } from "CoreLocation" +import { TencentLBSLocationManager, TencentLBSLocation, TencentLBSRequestLevel, TencentLBSLocationManagerDelegate } from "TencentLBS" +import { NSError, Bundle } from "Foundation" +import { GetLocationOptions, GetLocationSuccess } from "../interface.uts" + +/** + * 判断当前是否是自定义基座 + */ +export function checkHasIntegration() : boolean { + // todo + return true +} + +/** + * 定位 LBSLocation 类,封装定位相关方法 + */ +class LBSLocation implements TencentLBSLocationManagerDelegate { + + // 定义 locationManager 属性,类型为 TencentLBSLocationManager + locationManager! : TencentLBSLocationManager + + locationOptions ?: GetLocationOptions + + // 初始化 locationManager 方法 + configLocationManager() : boolean { + + if (this.locationManager == null) { + // 从 info.plist 中读取 apiKey + const apiKey = Bundle.main.infoDictionary?.["TencentLBSAPIKey"] + + // infoDictionary 获取的值类型为 any? + if (apiKey == null) { + // 如果 apiKey 为 null 返回 false + console.log("apiKey 未配置") + return false + } + // 调用API前需要设置同意用户隐私协议 + TencentLBSLocationManager.setUserAgreePrivacy(true) + // 初始化 locationManager 实例对象 + this.locationManager = new TencentLBSLocationManager() + // 设置 apiKey (因为 apiKey 是 any?类型,需要转成 string 类型赋值) + this.locationManager.apiKey = apiKey! as string; + this.locationManager.delegate = this + } + + return true + } + + // 请求定位权限 + requestPremission() { + if (this.configLocationManager()) { + const status = CLLocationManager.authorizationStatus() + // 如果未获取过定位权限,则发起权限请求 + if (status == CLAuthorizationStatus.notDetermined) { + this.locationManager.requestWhenInUseAuthorization() + } else if (status == CLAuthorizationStatus.denied || status == CLAuthorizationStatus.restricted) { + let ret = new UniError("uni-getLocation-tencent", -30, "permission missed."); + this.locationOptions?.fail?.(ret) + this.locationOptions?.complete?.(ret) + } + } + } + + // 获取单次位置信息 + getLocation(locationOptions : GetLocationOptions) : boolean { + + // 初始化 locationManager + if (!this.configLocationManager()) { + // 初始化失败返回 false + return false + } + + this.locationOptions = locationOptions + + const status = CLLocationManager.authorizationStatus() + if (status == CLAuthorizationStatus.authorizedAlways || status == CLAuthorizationStatus.authorizedWhenInUse) { + // 是否需要返回逆地理编码 + let requestLevel = TencentLBSRequestLevel.geo + if (locationOptions.geocode) { + requestLevel = TencentLBSRequestLevel.name + } + + // 请求单次定位信息 + this.locationManager.requestLocation(with = requestLevel, locationTimeout = 10, completionBlock = (location ?: TencentLBSLocation, err ?: NSError) : void => { + if (location != null) { + // 判断 address 是否有值 + var address = "" + if (location!.address != null) { + address = location!.address! + } + + let response : GetLocationSuccess = { + latitude: Number(location!.location.coordinate.latitude), + longitude: Number(location!.location.coordinate.longitude), + speed: Number(location!.location.speed), + altitude: Number(location!.location.altitude), + accuracy: Number(location!.location.horizontalAccuracy), + verticalAccuracy: Number(location!.location.verticalAccuracy), + horizontalAccuracy: Number(location!.location.horizontalAccuracy), + address: address + } + + locationOptions.success?.(response) + locationOptions.complete?.(response); + } else { + let ret = new UniError("uni-getLocation-tencent", -10, err!.localizedDescription); + locationOptions.fail?.(ret) + locationOptions.complete?.(ret) + } + }) + } else { + this.requestPremission() + } + return true + } + + // 监听位置变化 + watchPosition(locationOptions : GetLocationOptions) { + // 初始化 locationManager + if (!this.configLocationManager()) { + return + } + if (locationOptions.geocode) { + this.locationManager.requestLevel = TencentLBSRequestLevel.name + } else { + this.locationManager.requestLevel = TencentLBSRequestLevel.geo + } + this.locationOptions = locationOptions + this.locationManager.startUpdatingLocation() + } + + // 清除监听 + clearWatch() { + // 初始化 locationManager + if (!this.configLocationManager()) { + return + } + this.locationManager.stopUpdatingLocation() + } + + // 实现定位出错的 delegate 方法 + + tencentLBSDidChangeAuthorization(manager : TencentLBSLocationManager) { + const status = CLLocationManager.authorizationStatus() + if (status == CLAuthorizationStatus.denied || status == CLAuthorizationStatus.restricted) { + let ret = new UniError("uni-getLocation-tencent", -30, "permission missed."); + this.locationOptions?.fail?.(ret) + this.locationOptions?.complete?.(ret) + } else if (status == CLAuthorizationStatus.authorizedAlways || status == CLAuthorizationStatus.authorizedWhenInUse) { + this.getLocation(this.locationOptions!) + } + } + + tencentLBSLocationManager(manager : TencentLBSLocationManager, @argumentLabel("didFailWithError") error : NSError) { + let ret = new UniError("uni-getLocation-tencent", -10, error.localizedDescription); + this.locationOptions?.fail?.(ret) + this.locationOptions?.complete?.(ret) + } + + // 实现位置更新的 delegate 方法 + tencentLBSLocationManager(manager : TencentLBSLocationManager, @argumentLabel("didUpdate") location : TencentLBSLocation) { + + // 判断 address 是否有值 + var address = "" + if (location.address != null) { + address = location.address! + } + + let response : GetLocationSuccess = { + latitude: Number(location.location.coordinate.latitude), + longitude: Number(location.location.coordinate.longitude), + speed: Number(location.location.speed), + altitude: Number(location.location.altitude), + accuracy: Number(location.location.horizontalAccuracy), + verticalAccuracy: Number(location.location.verticalAccuracy), + horizontalAccuracy: Number(location.location.horizontalAccuracy), + address: address + } + this.locationOptions?.success?.(response) + this.locationOptions?.complete?.(response) + } + +} + +const LBSLocationTool : LBSLocation = new LBSLocation() + +/** + * 请求定位权限方法 + */ +export function requestPremission() { + LBSLocationTool.requestPremission() +} + +/* + * 获取位置信息方法(单次定位) + */ +export function getLocation(locationOptions : GetLocationOptions) : boolean { + return LBSLocationTool.getLocation(locationOptions) +} + +/** + * 持续监听位置变化 + */ +export function watchPosition(locationOptions : GetLocationOptions) { + LBSLocationTool.watchPosition(locationOptions) +} + +/** + * 关闭监听位置变化 + */ +export function clearWatch() { + LBSLocationTool.clearWatch() +} diff --git a/uni_modules/uni-getLocation-tencent/utssdk/app-ios/info.plist b/uni_modules/uni-getLocation-tencent/utssdk/app-ios/info.plist new file mode 100644 index 0000000000000000000000000000000000000000..3e3295273bbc8dc2e05565a6492871d6e103ee69 --- /dev/null +++ b/uni_modules/uni-getLocation-tencent/utssdk/app-ios/info.plist @@ -0,0 +1,23 @@ + + + + + TencentLBSAPIKey + WZCBZ-OLPCU-TJJVJ-4LZTE-SSG5O-6JFEM + NSLocationAlwaysAndWhenInUseUsageDescription + 允许使用定位权限吗 + NSLocationAlwaysUsageDescription + 允许一直使用定位权限 + NSLocationWhenInUseUsageDescription + 允许仅在app运行期间使用定位权限 + NSLocationTemporaryUsageDescriptionDictionary + + key1111 + 获取准确的位置信息 + + UIBackgroundModes + + location + + + diff --git a/uni_modules/uni-getNetworkType/utssdk/interface.uts b/uni_modules/uni-getNetworkType/utssdk/interface.uts index d96b8169d3cb5ccb5ef43a0917ad7b5a84490546..f14e452e210b7d0f60f52cf04459d16bd1db42ad 100644 --- a/uni_modules/uni-getNetworkType/utssdk/interface.uts +++ b/uni_modules/uni-getNetworkType/utssdk/interface.uts @@ -15,9 +15,9 @@ export interface Uni { * "unixVer": "3.9+" * }, * "ios": { - * "osVer": "9.0", + * "osVer": "12.0", * "uniVer": "√", - * "unixVer": "4.06" + * "unixVer": "4.11" * } * }, * "web": { diff --git a/uni_modules/uni-getPerformance/utssdk/interface.uts b/uni_modules/uni-getPerformance/utssdk/interface.uts index c43d064beadbf63527e7350bf95cc85b0d124333..a2ccf57b511240e41eeb078d12e3d93c85a24027 100644 --- a/uni_modules/uni-getPerformance/utssdk/interface.uts +++ b/uni_modules/uni-getPerformance/utssdk/interface.uts @@ -131,12 +131,12 @@ export interface Uni { * "app": { * "android": { * "osVer": "5.0", - * "uniVer": "√", + * "uniVer": "x", * "unixVer": "3.91" * }, * "ios": { - * "osVer": "10.0", - * "uniVer": "√", + * "osVer": "12.0", + * "uniVer": "x", * "unixVer": "x" * } * }, @@ -153,5 +153,5 @@ export interface Uni { * } * } */ - getPerformance: Performance + getPerformance: GetPerformance } diff --git a/uni_modules/uni-getProvider/utssdk/app-android/index.uts b/uni_modules/uni-getProvider/utssdk/app-android/index.uts index cf34d7daa671f4fb2215194a7c92664ffefcdbb6..abfa078065aabcc6267d0b2d32db36e4c77edb2d 100644 --- a/uni_modules/uni-getProvider/utssdk/app-android/index.uts +++ b/uni_modules/uni-getProvider/utssdk/app-android/index.uts @@ -9,13 +9,16 @@ export const getProvider : GetProvider = (options: GetProviderOptions) : void => options.fail?.(uniError); } } else { - const provider = UTSAndroid.getExtApiProviders(options.service) + const providers = UTSAndroid.getProviders(options.service) // TODO // const providers: any[] = [] if (options.success != null) { const result = { service: options.service, - provider, + provider: providers.map((provider): string => { + return provider.id + }), + providers, errMsg: 'GetProvider:ok' } as GetProviderSuccess; options.success?.(result); diff --git a/uni_modules/uni-getProvider/utssdk/app-ios/index.uts b/uni_modules/uni-getProvider/utssdk/app-ios/index.uts index c48f8a23a8c840bf8955387169a5477c62fe138c..10906e2e754bd8d204fa65dccd5cd01bf8742b28 100644 --- a/uni_modules/uni-getProvider/utssdk/app-ios/index.uts +++ b/uni_modules/uni-getProvider/utssdk/app-ios/index.uts @@ -10,11 +10,14 @@ export const getProvider : GetProvider = (options: GetProviderOptions) : void => options.fail?.(uniError); } } else { - const provider = UTSiOS.getExtApiProviders(options.service) + const providers = UTSiOS.getProviders(options.service) if (options.success != null) { const result = { service: options.service, - provider, + provider: providers.map((provider): string => { + return provider.id + }), + providers, errMsg: 'GetProvider:ok' } as GetProviderSuccess; options.success?.(result); diff --git a/uni_modules/uni-getProvider/utssdk/interface.uts b/uni_modules/uni-getProvider/utssdk/interface.uts index c49ce7471db0e5ab961eae6d647f495a7a5953b0..8d8f7c6dae97af3bee0e2ed77d9a9d6db820a1f6 100644 --- a/uni_modules/uni-getProvider/utssdk/interface.uts +++ b/uni_modules/uni-getProvider/utssdk/interface.uts @@ -1,84 +1,98 @@ export type GetProviderSuccess = { - /** - * 服务类型 - * - oauth: 授权登录 - * - share: 分享 - * - payment: 支付 - * - push: 推送 - * - location: 定位 - * @type 'oauth' | 'share' | 'payment' | 'push' | 'location' - */ - service: 'oauth' | 'share' | 'payment' | 'push' | 'location', - /** - * 得到的服务供应商 - * @type PlusShareShareService['id'][] | PlusPushClientInfo['id'][] | PlusOauthAuthService['id'][] | PlusPaymentPaymentChannel['id'][] - */ - provider: string[], - /** - * 描述信息 - */ - errMsg: string + /** + * 服务类型 + * - payment: 支付 + * @type 'payment' + */ + service : 'payment', + /** + * 得到的服务供应商 + * @type PlusShareShareService['id'][] | PlusPushClientInfo['id'][] | PlusOauthAuthService['id'][] | PlusPaymentPaymentChannel['id'][] + */ + provider : string[], + /** + * 得到的服务供应商服务对象 + * @uniPlatform { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "4.18" + * }, + * "ios": { + * "osVer": "9.0", + * "uniVer": "√", + * "unixVer": "4.18" + * } + * }, + * "web": { + * "uniVer": "x", + * "unixVer": "x" + * } + * } + */ + providers : UniProvider[], + /** + * 错误信息 + */ + errMsg : string }; -export type GetProviderSuccessCallback = (result: GetProviderSuccess) => void; +export type GetProviderSuccessCallback = (result : GetProviderSuccess) => void; export type GetProviderFail = UniError; -export type GetProviderFailCallback = (result: GetProviderFail) => void; +export type GetProviderFailCallback = (result : GetProviderFail) => void; export type GetProviderComplete = any; -export type GetProviderCompleteCallback = (result: GetProviderComplete) => void; +export type GetProviderCompleteCallback = (result : GetProviderComplete) => void; export type GetProviderOptions = { - /** - * 服务类型,可取值“oauth”、“share”、“payment”、“push”、“location” - * - oauth: 授权登录 - * - share: 分享 - * - payment: 支付 - * - push: 推送 - * - location: 定位 - * @type 'oauth' | 'share' | 'payment' | 'push' | 'location' - */ - service: 'oauth' | 'share' | 'payment' | 'push' | 'location', - /** - * 接口调用成功的回调 - */ - success?: GetProviderSuccessCallback | null, - /** - * 接口调用失败的回调函数 - */ - fail?: GetProviderFailCallback | null, - /** - * 接口调用结束的回调函数(调用成功、失败都会执行) - */ - complete?: GetProviderCompleteCallback | null + /** + * 服务类型,可取值“payment” + * - payment: 支付 (Alipay、Wxpay) + * @type 'payment' + */ + service : 'payment', + /** + * 接口调用成功的回调 + */ + success ?: GetProviderSuccessCallback | null, + /** + * 接口调用失败的回调函数 + */ + fail ?: GetProviderFailCallback | null, + /** + * 接口调用结束的回调函数(调用成功、失败都会执行) + */ + complete ?: GetProviderCompleteCallback | null }; -export type GetProvider = (options: GetProviderOptions) => void; +export type GetProvider = (options : GetProviderOptions) => void; export interface Uni { - /** - * 获取服务供应商 - * @param {GetProviderOptions} options - * @return {void} - * @tutorial https://doc.dcloud.net.cn/uni-app-x/api/get-provider.html - * @uniPlatform { - * "app": { - * "android": { - * "osVer": "5.0", - * "uniVer": "√", - * "unixVer": "4.11" - * }, - * "ios": { - * "osVer": "9.0", - * "uniVer": "√", - * "unixVer": "x" - * } - * }, - * "web": { - * "uniVer": "√", - * "unixVer": "4.05" - * } - * } - * @example - ```typescript - uni.getProvider({service: ''}) - ``` - */ - getProvider(options: GetProviderOptions) : void; + /** + * 获取服务供应商 + * @param {GetProviderOptions} options + * @return {void} + * @tutorial https://doc.dcloud.net.cn/uni-app-x/api/get-provider.html + * @uniPlatform { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "4.11" + * }, + * "ios": { + * "osVer": "9.0", + * "uniVer": "√", + * "unixVer": "4.18" + * } + * }, + * "web": { + * "uniVer": "x", + * "unixVer": "x" + * } + * } + * @example + ```typescript + uni.getProvider({service: ''}) + ``` + */ + getProvider(options : GetProviderOptions) : void; } diff --git a/uni_modules/uni-getSystemInfo/utssdk/app-android/index.uts b/uni_modules/uni-getSystemInfo/utssdk/app-android/index.uts index b0f7d90d239e468f4acf5430cb0261416090e720..20b0eaf02583d2551ef3ae66c9462f680df47d67 100644 --- a/uni_modules/uni-getSystemInfo/utssdk/app-android/index.uts +++ b/uni_modules/uni-getSystemInfo/utssdk/app-android/index.uts @@ -77,6 +77,7 @@ export const getSystemInfoSync : GetSystemInfoSync = function () : GetSystemInfo height: windowHeight - safeAreaInsets.top - safeAreaInsets.bottom } const osAndroidAPILevel = Build.VERSION.SDK_INT; + const appTheme = UTSAndroid.getAppTheme(); const result = { SDKVersion: "", @@ -125,6 +126,7 @@ export const getSystemInfoSync : GetSystemInfoSync = function () : GetSystemInfo safeAreaInsets: safeAreaInsets, safeArea: safeArea, osAndroidAPILevel: osAndroidAPILevel, + appTheme: appTheme, } as GetSystemInfoResult; return result; } catch (e : Exception) { diff --git a/uni_modules/uni-getSystemInfo/utssdk/app-ios/index.uts b/uni_modules/uni-getSystemInfo/utssdk/app-ios/index.uts index 6c05edcde9531a5e1ae9d5e85cb2ef2111d3a1bf..13ec1c13ede11abaf1688eb6e3ba5412668524b9 100644 --- a/uni_modules/uni-getSystemInfo/utssdk/app-ios/index.uts +++ b/uni_modules/uni-getSystemInfo/utssdk/app-ios/index.uts @@ -16,12 +16,6 @@ export const getSystemInfoSync : GetSystemInfoSync = function () : GetSystemInfo const osVersion = UIDevice.current.systemVersion - let osTheme = 'light' - if(UTSiOS.available("iOS 13, *")){ - let currentTraitCollection = UIApplication.shared.keyWindow?.traitCollection - osTheme = currentTraitCollection?.userInterfaceStyle == UIUserInterfaceStyle.dark ? "dark" : "light" - } - let deviceOrientation = 'portrait' const orient = UIApplication.shared.statusBarOrientation; if (orient == UIInterfaceOrientation.landscapeLeft || orient == UIInterfaceOrientation.landscapeRight) { @@ -50,7 +44,7 @@ export const getSystemInfoSync : GetSystemInfoSync = function () : GetSystemInfo osName: 'ios', osVersion: osVersion, osLanguage: UTSiOS.getOsLanguage(), - osTheme: osTheme, + osTheme: UTSiOS.getOsTheme(), pixelRatio: windowInfo.pixelRatio, platform: 'ios', screenWidth: windowInfo.screenWidth, @@ -74,6 +68,7 @@ export const getSystemInfoSync : GetSystemInfoSync = function () : GetSystemInfo windowBottom: windowInfo.windowBottom, safeAreaInsets: windowInfo.safeAreaInsets, safeArea: windowInfo.safeArea, + appTheme: UTSiOS.getAppTheme(), }; return result; } diff --git a/uni_modules/uni-getSystemInfo/utssdk/interface.uts b/uni_modules/uni-getSystemInfo/utssdk/interface.uts index 706c4ebc6d2d56b2dbd31955f1aee1f6f527eefa..f8706359e1a7cd61e18d971ef8694c749496355d 100644 --- a/uni_modules/uni-getSystemInfo/utssdk/interface.uts +++ b/uni_modules/uni-getSystemInfo/utssdk/interface.uts @@ -1,462 +1,1780 @@ -export interface Uni { - /** - * getSystemInfo() - * @description - * 异步获取系统信息 - * @param {GetSystemInfoOptions} options - * @return {void} - * @tutorial http://uniapp.dcloud.io/api/system/info?id=getsysteminfo - * @uniPlatform - * { - * "app": { - * "android": { - * "osVer": "5.0", - * "uniVer": "√", - * "unixVer": "3.9+" - * }, - * "ios": { - * "osVer": "12.0", - * "uniVer": "√", - * "unixVer": "4.11" - * } - * }, - * "web": { - * "uniVer": "√", - * "unixVer": "4.0" - * } - * } - * @example - ```typescript - uni.getSystemInfo({ - success(e) { - console.log("success :",e); - }, - complete(e) { - console.log("complete :",e); - } - }) - ``` - */ - getSystemInfo(options: GetSystemInfoOptions): void; - - /** - * getSystemInfoSync() - * @description - * 同步获取系统信息 - * @param {void} - * @return {GetSystemInfoResult} - * @tutorial http://uniapp.dcloud.io/api/system/info?id=getsysteminfosync - * @uniPlatform - * { - * "app": { - * "android": { - * "osVer": "5.0", - * "uniVer": "√", - * "unixVer": "3.9+" - * }, - * "ios": { - * "osVer": "12.0", - * "uniVer": "√", - * "unixVer": "4.11" - * } - * }, - * "web": { - * "uniVer": "√", - * "unixVer": "4.0" - * } - * } - * @example - ```typescript - uni.getSystemInfoSync() - ``` - */ - getSystemInfoSync(): GetSystemInfoResult; - - /** - * getWindowInfo() - * @description - * 同步获取窗口信息 - * @param {void} - * @return {GetWindowInfoResult} result - * @tutorial http://uniapp.dcloud.io/api/system/getWindowInfo.html - * @uniPlatform - * { - * "app": { - * "android": { - * "osVer": "5.0", - * "uniVer": "√", - * "unixVer": "3.9+" - * }, - * "ios": { - * "osVer": "12.0", - * "uniVer": "√", - * "unixVer": "4.11" - * } - * }, - * "web": { - * "uniVer": "√", - * "unixVer": "4.0" - * } - * } - * @example - ```typescript - uni.getWindowInfo() - ``` - */ - getWindowInfo(): GetWindowInfoResult; -} - -export type GetSystemInfo = (options: GetSystemInfoOptions) => void; -export type GetSystemInfoSync = () => GetSystemInfoResult; -export type GetWindowInfo = () => GetWindowInfoResult; -export type SafeArea = { - /** - * 安全区域左上角横坐标,单位为px - */ - left: number, - /** - * 安全区域右下角横坐标,单位为px - */ - right: number, - /** - * 安全区域左上角纵坐标,单位为px - */ - top: number, - /** - * 安全区域右下角纵坐标,单位为px - */ - bottom: number, - /** - * 安全区域的宽度,单位为px - */ - width: number, - /** - * 安全区域的高度,单位为px - */ - height: number -}; -export type SafeAreaInsets = { - /** - * 安全区域左侧插入位置,单位为px - */ - left: number, - /** - * 安全区域右侧插入位置,单位为px - */ - right: number, - /** - * 安全区顶部插入位置,单位为px - */ - top: number, - /** - * 安全区域底部插入位置,单位为px - */ - bottom: number -}; -export type GetSystemInfoResult = { - /** - * 客户端基础库版本 - */ - SDKVersion: string, - /** - * `manifest.json` 中应用appid。 - */ - appId: string, - /** - * 应用设置的语言。 - */ - appLanguage: string, - /** - * `manifest.json` 中应用名称。 - */ - appName: string, - /** - * `manifest.json` 中应用版本名称。 - */ - appVersion: string, - /** - * `manifest.json` 中应用版本名号。 - */ - appVersionCode: string, - /** - * 应用资源(wgt)的版本名称。 - * - * @uniPlatform - * { - * "app": { - * "android": { - * "osVer": "5.0", - * "uniVer": "√", - * "unixVer": "x" - * }, - * "ios": { - * "osVer": "12.0", - * "uniVer": "√", - * "unixVer": "x" - * } - * } - * } - */ - appWgtVersion?: string | null, - /** - * 手机品牌。 - */ - brand: string, - /** - * 浏览器名称。`App` 端是系统 webview 的名字,比如 wkwebview、chrome。小程序端为空 - */ - browserName: string, - /** - * 浏览器版本、webview 版本。 - */ - browserVersion: string, - /** - * 设备 ID - */ - deviceId: string, - /** - * 设备品牌。如:`apple`、`huawei`。 - */ - deviceBrand: string, - /** - * 设备型号 - */ - deviceModel: string, - /** - * 设备类型。 - */ - deviceType: 'phone' | 'pad' | 'tv' | 'watch' | 'pc' | 'undefined' | 'car' | 'vr' | 'appliance', - /** - * 设备像素比 - */ - devicePixelRatio: number, - /** - * 设备方向。 - * @type 'portrait' | 'landscape' - */ - deviceOrientation: 'portrait' | 'landscape', - /** - * 程序设置的语言 - */ - language: string, - /** - * 手机型号 - */ - model: string, - /** - * 系统名称 - */ - osName: 'ios' | 'android' | 'mac' | 'windows' | 'linux', - /** - * 操作系统版本。如 ios 版本,andriod 版本 - */ - osVersion: string, - /** - * 操作系统语言 - */ - osLanguage: string, - /** - * 操作系统主题 - * - * @uniPlatform - * { - * "app": { - * "android": { - * "osVer": "5.0", - * "uniVer": "√", - * "unixVer": "√" - * }, - * "ios": { - * "osVer": "12.0", - * "uniVer": "√", - * "unixVer": "4.11" - * } - * } - * } - */ - osTheme?: 'light' | 'dark' | null, - /** - * 设备像素比 - */ - pixelRatio: number, - /** - * 客户端平台 - */ - platform: 'ios' | 'android' | 'mac' | 'windows' | 'linux', - /** - * 屏幕宽度,单位为px - */ - screenWidth: number, - /** - * 屏幕高度,单位为px - */ - screenHeight: number, - /** - * 状态栏的高度,单位为px - */ - statusBarHeight: number, - /** - * 操作系统版本 - */ - system: string, - /** - * 在竖屏正方向下的安全区域 - */ - safeArea: SafeArea, - /** - * 在竖屏正方向下的安全区域插入位置 - */ - safeAreaInsets: SafeAreaInsets, - /** - * 用户标识。小程序端为空 - */ - ua: string, - /** - * uni 编译器版本。 - * @deprecated 已废弃,仅为了向下兼容保留 - */ - uniCompileVersion: string, - /** - * uni 编译器版本。 - */ - uniCompilerVersion: string, - /** - * uni-app 运行平台,与条件编译平台相同。 - */ - uniPlatform: 'app' | 'web' | 'mp-weixin' | 'mp-alipay' | 'mp-baidu' | 'mp-toutiao' | 'mp-lark' | 'mp-qq' | 'mp-kuaishou' | 'mp-jd' | 'mp-360' | 'quickapp-webview' | 'quickapp-webview-union' | 'quickapp-webview-huawei', - /** - * uni 运行时版本。 - */ - uniRuntimeVersion: string, - /** - * uni 编译器版本号。 - * @deprecated 已废弃,仅为了向下兼容保留 - */ - uniCompileVersionCode: number, - /** - * uni 编译器版本号。 - */ - uniCompilerVersionCode: number, - /** - * uni 运行时版本号。 - */ - uniRuntimeVersionCode: number, - /** - * 引擎版本号。 - * @deprecated 已废弃,仅为了向下兼容保留 - */ - version: string, - /** - * rom 名称。Android 部分机型获取不到值。iOS 恒为 `ios` - */ - romName: string, - /** - * rom 版本号。Android 部分机型获取不到值。iOS 为操作系统版本号(同 `osVersion`)。 - */ - romVersion: string, - /** - * 可使用窗口宽度,单位为px - */ - windowWidth: number, - /** - * 可使用窗口高度,单位为px - */ - windowHeight: number, - /** - * 内容区域距离顶部的距离(同CSS变量 `--window-top`),单位为px - */ - windowTop: number, - /** - * 内容区域距离底部的距离(同CSS变量 `--window-bottom`),单位为px - */ - windowBottom: number, - /** - * Android 系统API库的版本。 - * - * @uniPlatform - * { - * "app": { - * "android": { - * "osVer": "5.0", - * "uniVer": "√", - * "unixVer": "√" - * }, - * "ios": { - * "osVer": "x", - * "uniVer": "x", - * "unixVer": "x" - * } - * } - * } - */ - osAndroidAPILevel?: number | null -}; -export type GetSystemInfoSuccessCallback = (result: GetSystemInfoResult) => void; -type GetSystemInfoFail = UniError; -type GetSystemInfoFailCallback = (result: GetSystemInfoFail) => void; -export type GetSystemInfoComplete = any; -export type GetSystemInfoCompleteCallback = (result: GetSystemInfoComplete) => void; -export type GetSystemInfoOptions = { - /** - * 接口调用成功的回调函数 - * @defaultValue null - */ - success?: GetSystemInfoSuccessCallback | null, - /** - * 接口调用失败的回调函数 - * @defaultValue null - */ - fail?: GetSystemInfoFailCallback | null, - /** - * 接口调用结束的回调函数(调用成功、失败都会执行) - * @defaultValue null - */ - complete?: GetSystemInfoCompleteCallback | null -}; - -export type GetWindowInfoResult = { - /** - * 设备像素比 - */ - pixelRatio: number, - /** - * 屏幕宽度,单位为px - */ - screenWidth: number, - /** - * 屏幕高度,单位为px - */ - screenHeight: number, - /** - * 可使用窗口宽度,单位为px - */ - windowWidth: number, - /** - * 可使用窗口高度,单位为px - */ - windowHeight: number, - /** - * 状态栏的高度,单位为px - */ - statusBarHeight: number, - /** - * 内容区域距离顶部的距离(同CSS变量 `--window-top`),单位为px - */ - windowTop: number, - /** - * 内容区域距离底部的距离(同CSS变量 `--window-bottom`),单位为px - */ - windowBottom: number, - /** - * 在竖屏正方向下的安全区域 - */ - safeArea: SafeArea, - /** - * 在竖屏正方向下的安全区域插入位置 - */ - safeAreaInsets: SafeAreaInsets, - /** - * 窗口上边缘的 y 值,单位为px - */ - screenTop: number -}; +export interface Uni { + /** + * getSystemInfo() + * @description + * 异步获取系统信息 + * @param {GetSystemInfoOptions} options + * @return {void} + * @tutorial http://uniapp.dcloud.io/api/system/info?id=getsysteminfo + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } + * @example + ```typescript + uni.getSystemInfo({ + success(e) { + console.log("success :",e); + }, + complete(e) { + console.log("complete :",e); + } + }) + ``` + */ + getSystemInfo(options: GetSystemInfoOptions): void; + + /** + * getSystemInfoSync() + * @description + * 同步获取系统信息 + * @param {void} + * @return {GetSystemInfoResult} + * @tutorial http://uniapp.dcloud.io/api/system/info?id=getsysteminfosync + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } + * @example + ```typescript + uni.getSystemInfoSync() + ``` + */ + getSystemInfoSync(): GetSystemInfoResult; + + /** + * getWindowInfo() + * @description + * 同步获取窗口信息 + * @param {void} + * @return {GetWindowInfoResult} result + * @tutorial http://uniapp.dcloud.io/api/system/getWindowInfo.html + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } + * @example + ```typescript + uni.getWindowInfo() + ``` + */ + getWindowInfo(): GetWindowInfoResult; +} + +export type GetSystemInfo = (options: GetSystemInfoOptions) => void; +export type GetSystemInfoSync = () => GetSystemInfoResult; +export type GetWindowInfo = () => GetWindowInfoResult; +export type SafeArea = { + /** + * 安全区域左上角横坐标,单位为px + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } + */ + left: number, + /** + * 安全区域右下角横坐标,单位为px + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } + */ + right: number, + /** + * 安全区域左上角纵坐标,单位为px + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } + */ + top: number, + /** + * 安全区域右下角纵坐标,单位为px + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } + */ + bottom: number, + /** + * 安全区域的宽度,单位为px + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } + */ + width: number, + /** + * 安全区域的高度,单位为px + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } + */ + height: number +}; +export type SafeAreaInsets = { + /** + * 安全区域左侧插入位置(距离左边边界距离),单位为px + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } + */ + left: number, + /** + * 安全区域右侧插入位置(距离右边边界距离),单位为px + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } + */ + right: number, + /** + * 安全区顶部插入位置(距离顶部边界距离),单位为px + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } + */ + top: number, + /** + * 安全区域底部插入位置(距离底部边界距离),单位为px + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } + */ + bottom: number +}; +export type GetSystemInfoResult = { + /** + * 客户端基础库版本 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "x", + * "unixVer": "x" + * } + * } + */ + SDKVersion: string, + /** + * `manifest.json` 中应用appid。 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } + */ + appId: string, + /** + * 应用设置的语言。 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } + */ + appLanguage: string, + /** + * `manifest.json` 中应用名称。 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } + */ + appName: string, + /** + * `manifest.json` 中应用版本名称。 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } + */ + appVersion: string, + /** + * `manifest.json` 中应用版本名号。 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } + */ + appVersionCode: string, + /** + * 应用资源(wgt)的版本名称。 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "x" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "x" + * } + * }, + * "web": { + * "uniVer": "x", + * "unixVer": "x" + * } + * } + */ + appWgtVersion?: string | null, + /** + * 手机品牌。 + * @deprecated 已废弃,仅为了向下兼容保留 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "x", + * "unixVer": "x" + * } + * } + */ + brand: string, + /** + * 浏览器名称。`App` 端是系统 webview 的名字,比如 wkwebview、chrome。小程序端为空 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } + */ + browserName: string, + /** + * 浏览器版本、webview 版本。 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } + */ + browserVersion: string, + /** + * 设备 ID + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } + */ + deviceId: string, + /** + * 设备品牌。如:`apple`、`huawei`。 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } + */ + deviceBrand: string, + /** + * 设备型号 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } + */ + deviceModel: string, + /** + * 设备类型。 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } + */ + deviceType: 'phone' | 'pad' | 'tv' | 'watch' | 'pc' | 'undefined' | 'car' | 'vr' | 'appliance', + /** + * 设备像素比 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } + */ + devicePixelRatio: number, + /** + * 设备方向。 + * @type 'portrait' | 'landscape' + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } + */ + deviceOrientation: 'portrait' | 'landscape', + /** + * 程序设置的语言 + * @deprecated 已废弃,仅为了向下兼容保留 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } + */ + language: string, + /** + * 手机型号 + * @deprecated 已废弃,仅为了向下兼容保留 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } + */ + model: string, + /** + * 系统名称 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } + */ + osName: 'ios' | 'android' | 'macos' | 'windows' | 'linux', + /** + * 操作系统版本。如 ios 版本,andriod 版本 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } + */ + osVersion: string, + /** + * 操作系统语言 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } + */ + osLanguage: string, + /** + * 操作系统主题 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "√" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "x", + * "unixVer": "x" + * } + * } + */ + osTheme?: 'light' | 'dark' | null, + /** + * 设备像素比 + * @deprecated 已废弃,仅为了向下兼容保留 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } + */ + pixelRatio: number, + /** + * 客户端平台 + * @deprecated 已废弃,仅为了向下兼容保留 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } + */ + platform: 'ios' | 'android' | 'mac' | 'windows' | 'linux', + /** + * 屏幕宽度,单位为px + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } + */ + screenWidth: number, + /** + * 屏幕高度,单位为px + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } + */ + screenHeight: number, + /** + * 状态栏的高度,单位为px + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } + */ + statusBarHeight: number, + /** + * 操作系统版本 + * @deprecated 已废弃,仅为了向下兼容保留 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } + */ + system: string, + /** + * 在竖屏正方向下的安全区域 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } + */ + safeArea: SafeArea, + /** + * 在竖屏正方向下的安全区域插入位置 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } + */ + safeAreaInsets: SafeAreaInsets, + /** + * 用户标识。小程序端为空 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } + */ + ua: string, + /** + * uni 编译器版本。 + * @deprecated 已废弃,仅为了向下兼容保留 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } + */ + uniCompileVersion: string, + /** + * uni 编译器版本。 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "x", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "x", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "x", + * "unixVer": "4.18" + * } + * } + */ + uniCompilerVersion: string, + /** + * uni-app 运行平台,与条件编译平台相同。 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } + */ + uniPlatform: 'app' | 'web' | 'mp-weixin' | 'mp-alipay' | 'mp-baidu' | 'mp-toutiao' | 'mp-lark' | 'mp-qq' | 'mp-kuaishou' | 'mp-jd' | 'mp-360' | 'quickapp-webview' | 'quickapp-webview-union' | 'quickapp-webview-huawei', + /** + * uni 运行时版本。 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } + */ + uniRuntimeVersion: string, + /** + * uni 编译器版本号。 + * @deprecated 已废弃,仅为了向下兼容保留 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "x", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "x", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } + */ + uniCompileVersionCode: number, + /** + * uni 编译器版本号。 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "x", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "x", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "x", + * "unixVer": "4.18" + * } + * } + */ + uniCompilerVersionCode: number, + /** + * uni 运行时版本号。 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "x", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "x", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } + */ + uniRuntimeVersionCode: number, + /** + * 引擎版本号。 + * @deprecated 已废弃,仅为了向下兼容保留 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } + */ + version: string, + /** + * rom 名称。Android 部分机型获取不到值。iOS 恒为 `ios` + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "x", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "x", + * "unixVer": "x" + * } + * } + */ + romName: string, + /** + * rom 版本号。Android 部分机型获取不到值。iOS 为操作系统版本号(同 `osVersion`)。 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "x", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "x", + * "unixVer": "x" + * } + * } + */ + romVersion: string, + /** + * 可使用窗口宽度,单位为px + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } + */ + windowWidth: number, + /** + * 可使用窗口高度,单位为px + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } + */ + windowHeight: number, + /** + * 内容区域距离顶部的距离(同CSS变量 `--window-top`),单位为px + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } + */ + windowTop: number, + /** + * 内容区域距离底部的距离(同CSS变量 `--window-bottom`),单位为px + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } + */ + windowBottom: number, + /** + * Android 系统API库的版本。 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "√" + * }, + * "ios": { + * "osVer": "x", + * "uniVer": "x", + * "unixVer": "x" + * } + * }, + * "web": { + * "uniVer": "x", + * "unixVer": "x" + * } + * } + */ + osAndroidAPILevel?: number | null, + /** + * 当前App的主题 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "x", + * "unixVer": "4.18" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "x", + * "unixVer": "4.18" + * } + * }, + * "web": { + * "uniVer": "x", + * "unixVer": "x" + * } + * } + */ + appTheme?: 'light' | 'dark' | 'auto' | null, +}; +export type GetSystemInfoSuccessCallback = (result: GetSystemInfoResult) => void; +type GetSystemInfoFail = UniError; +type GetSystemInfoFailCallback = (result: GetSystemInfoFail) => void; +export type GetSystemInfoComplete = any; +export type GetSystemInfoCompleteCallback = (result: GetSystemInfoComplete) => void; +export type GetSystemInfoOptions = { + /** + * 接口调用成功的回调函数 + * @defaultValue null + */ + success?: GetSystemInfoSuccessCallback | null, + /** + * 接口调用失败的回调函数 + * @defaultValue null + */ + fail?: GetSystemInfoFailCallback | null, + /** + * 接口调用结束的回调函数(调用成功、失败都会执行) + * @defaultValue null + */ + complete?: GetSystemInfoCompleteCallback | null +}; + +export type GetWindowInfoResult = { + /** + * 设备像素比 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } + */ + pixelRatio: number, + /** + * 屏幕宽度,单位为px + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } + */ + screenWidth: number, + /** + * 屏幕高度,单位为px + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } + */ + screenHeight: number, + /** + * 可使用窗口宽度,单位为px + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } + */ + windowWidth: number, + /** + * 可使用窗口高度,单位为px + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * } + * } + */ + windowHeight: number, + /** + * 状态栏的高度,单位为px + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } + */ + statusBarHeight: number, + /** + * 内容区域距离顶部的距离(同CSS变量 `--window-top`),单位为px + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } + */ + windowTop: number, + /** + * 内容区域距离底部的距离(同CSS变量 `--window-bottom`),单位为px + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } + */ + windowBottom: number, + /** + * 安全区域在屏幕中的位置信息 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } + */ + safeArea: SafeArea, + /** + * 安全区域插入位置(与屏幕边界的距离)信息 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } + */ + safeAreaInsets: SafeAreaInsets, + /** + * 窗口上边缘的 y 值,单位为px + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } + */ + screenTop: number +}; diff --git a/uni_modules/uni-getSystemSetting/utssdk/interface.uts b/uni_modules/uni-getSystemSetting/utssdk/interface.uts index 718da8754c0bd50573b121dd8ab4e4fb898a605a..b6b1acd05382062667131dd7c5a8f03a37bedc6b 100644 --- a/uni_modules/uni-getSystemSetting/utssdk/interface.uts +++ b/uni_modules/uni-getSystemSetting/utssdk/interface.uts @@ -2,27 +2,123 @@ export type GetSystemSettingResult = { /** - * 蓝牙是否开启 + * 蓝牙是否开启 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * } + * } */ bluetoothEnabled?: boolean, /** - * 蓝牙的报错信息 + * 蓝牙的报错信息 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * } + * } */ bluetoothError?: string, /** - * 位置是否开启 + * 位置是否开启 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * } + * } */ locationEnabled : boolean, /** - * wifi是否开启 + * wifi是否开启 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * } + * } */ wifiEnabled?: boolean, /** - * wifi的报错信息 + * wifi的报错信息 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "x", + * "uniVer": "x", + * "unixVer": "x" + * } + * } + * } */ wifiError?: string, /** - * 设备方向 + * 设备方向 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * } + * } */ deviceOrientation : 'portrait' | 'landscape', } diff --git a/uni_modules/uni-getbatteryinfo/utssdk/index.d.ts b/uni_modules/uni-getbatteryinfo/utssdk/index.d.ts index 9f0b83c4e53a1a27957eb4b291cf3b1fc032f7d8..367327bc4b5742930361d84b66eecceb9fa48033 100644 --- a/uni_modules/uni-getbatteryinfo/utssdk/index.d.ts +++ b/uni_modules/uni-getbatteryinfo/utssdk/index.d.ts @@ -31,12 +31,13 @@ declare interface Uni { /** * 获取设备电量 * - * 文档: [https://uniapp.dcloud.net.cn/api/system/batteryInfo.html](https://uniapp.dcloud.net.cn/api/system/batteryInfo.html) + * @tutorial https://uniapp.dcloud.net.cn/api/system/batteryInfo.html */ getBatteryInfo(option?: UniNamespace.GetBatteryInfoOption): void; /** * 同步获取电池电量信息 + * @tutorial https://uniapp.dcloud.net.cn/api/system/batteryInfo.html */ getBatteryInfoSync(): UniNamespace.GetBatteryInfoSuccessCallbackResult; } diff --git a/uni_modules/uni-getbatteryinfo/utssdk/interface.uts b/uni_modules/uni-getbatteryinfo/utssdk/interface.uts index b19dc13d16e43ab04a323af4f53f59d5503ac243..1350545b3a06980b2bc169a73243cece6b18c2a9 100644 --- a/uni_modules/uni-getbatteryinfo/utssdk/interface.uts +++ b/uni_modules/uni-getbatteryinfo/utssdk/interface.uts @@ -1,107 +1,115 @@ -export type GetBatteryInfoSuccess = { - errMsg : string, - /** - * 设备电量,范围1 - 100 - */ - level : number, - /** - * 是否正在充电中 - */ - isCharging : boolean -} - -export type GetBatteryInfoOptions = { - /** - * 接口调用结束的回调函数(调用成功、失败都会执行) - */ - success ?: (res : GetBatteryInfoSuccess) => void - /** - * 接口调用失败的回调函数 - */ - fail ?: (res : UniError) => void - /** - * 接口调用成功的回调 - */ - complete ?: (res : any) => void +export type GetBatteryInfoSuccess = { + errMsg : string, + /** + * 设备电量,范围1 - 100 + */ + level : number, + /** + * 是否正在充电中 + */ + isCharging : boolean +} + +export type GetBatteryInfoOptions = { + /** + * 接口调用结束的回调函数(调用成功、失败都会执行) + */ + success ?: (res : GetBatteryInfoSuccess) => void + /** + * 接口调用失败的回调函数 + */ + fail ?: (res : UniError) => void + /** + * 接口调用成功的回调 + */ + complete ?: (res : any) => void } -export type GetBatteryInfoResult = { - /** - * 设备电量,范围1 - 100 - */ - level : number, - /** - * 是否正在充电中 - */ - isCharging : boolean +export type GetBatteryInfoResult = { + /** + * 设备电量,范围1 - 100 + */ + level : number, + /** + * 是否正在充电中 + */ + isCharging : boolean } -/** - * 错误码 - * - 1001 getAppContext is null - */ -export type GetBatteryInfoErrorCode = 1001 ; -/** - * GetBatteryInfo 的错误回调参数 - */ -export interface GetBatteryInfoFail extends IUniError { - errCode : GetBatteryInfoErrorCode -}; - -/** -* 获取电量信息 -* @param {GetBatteryInfoOptions} options -* -* -* @tutorial https://uniapp.dcloud.net.cn/api/system/batteryInfo.html -* @platforms APP-IOS = ^9.0,APP-ANDROID = ^22 -* @since 3.6.11 -* -* @assert () => success({errCode: 0, errSubject: "uni-getBatteryInfo", errMsg: "getBatteryInfo:ok", level: 60, isCharging: false }) -* @assert () => fail({errCode: 1001, errSubject: "uni-getBatteryInfo", errMsg: "getBatteryInfo:fail getAppContext is null" }) -*/ +/** + * 错误码 + * - 1001 getAppContext is null + */ +export type GetBatteryInfoErrorCode = 1001 ; +/** + * GetBatteryInfo 的错误回调参数 + */ +export interface GetBatteryInfoFail extends IUniError { + errCode : GetBatteryInfoErrorCode +}; + +/** +* 获取电量信息 +* @param {GetBatteryInfoOptions} options +* +* +* @tutorial https://uniapp.dcloud.net.cn/api/system/batteryInfo.html +* @platforms APP-IOS = ^9.0,APP-ANDROID = ^22 +* @since 3.6.11 +* +* @assert () => success({errCode: 0, errSubject: "uni-getBatteryInfo", errMsg: "getBatteryInfo:ok", level: 60, isCharging: false }) +* @assert () => fail({errCode: 1001, errSubject: "uni-getBatteryInfo", errMsg: "getBatteryInfo:fail getAppContext is null" }) +*/ export type GetBatteryInfo = (options : GetBatteryInfoOptions) => void - -export type GetBatteryInfoSync = () => GetBatteryInfoResult - -interface Uni { - - /** - * 获取电池电量信息 - * @description 获取电池电量信息 - * @param {GetBatteryInfoOptions} options - * @example - * ```typescript - * uni.getBatteryInfo({ - * success(res) { - * console.log(res); - * } - * }) - * ``` - * @remark - * - 该接口需要同步调用 - * @uniPlatform { - * "app": { - * "android": { - * "osVer": "4.4.4", - * "uniVer": "3.6.11", - * "unixVer": "3.9.0" - * }, - * "ios": { - * "osVer": "12.0", - * "uniVer": "3.6.11", - * "unixVer": "4.11" - * } - * } - * } - * @uniVueVersion 2,3 //支持的vue版本 - * - */ + +export type GetBatteryInfoSync = () => GetBatteryInfoResult + +interface Uni { + + /** + * 获取电池电量信息 + * + * @example + * ```typescript + * uni.getBatteryInfo({ + * success(res) { + * console.log(res); + * } + * }) + * ``` + * @remark + * - 该接口需要同步调用 + * @uniPlatform { + * "app": { + * "android": { + * "osVer": "4.4.4", + * "uniVer": "3.6.11", + * "unixVer": "3.9.0" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "3.6.11", + * "unixVer": "4.11" + * }, + * "harmony": { + * "osVer": "x", + * "uniVer": "x", + * "unixVer": "x" + * } + * }, + * "web": { + * "uniVer": "3.6.11", + * "unixVer": "4.0" + * } + * } + * @uniVueVersion 2,3 //支持的vue版本 + * + */ getBatteryInfo (options : GetBatteryInfoOptions) : void, /** * 同步获取电池电量信息 - * @description 获取电池电量信息 + * * @example * ```typescript * uni.getBatteryInfo() @@ -119,12 +127,21 @@ interface Uni { * "osVer": "12.0", * "uniVer": "3.6.11", * "unixVer": "4.11" - * } + * }, + * "harmony": { + * "osVer": "x", + * "uniVer": "x", + * "unixVer": "x" + * } + * }, + * "web": { + * "uniVer": "3.6.11", + * "unixVer": "4.0" * } * } * @uniVueVersion 2,3 //支持的vue版本 * */ - getBatteryInfoSync():GetBatteryInfoResult - + getBatteryInfoSync():GetBatteryInfoResult + } diff --git a/uni_modules/uni-media/package.json b/uni_modules/uni-media/package.json index 7544e1837c4470807be7283d046e1a9bc0860473..734a2134e05937a2125101aae0c733a6c65b5777 100644 --- a/uni_modules/uni-media/package.json +++ b/uni_modules/uni-media/package.json @@ -86,7 +86,7 @@ "app": { "js": false, "kotlin": true, - "swift": false + "swift": true } }, "saveVideoToPhotosAlbum": { @@ -94,7 +94,7 @@ "app": { "js": false, "kotlin": true, - "swift": false + "swift": true } }, "getVideoInfo": { diff --git a/uni_modules/uni-media/utssdk/ChooseImageUtils.uts b/uni_modules/uni-media/utssdk/ChooseImageUtils.uts deleted file mode 100644 index 89c248bf3d04b1ab156d7f013ed92dd25df8c836..0000000000000000000000000000000000000000 --- a/uni_modules/uni-media/utssdk/ChooseImageUtils.uts +++ /dev/null @@ -1,72 +0,0 @@ -import { ChooseImageOptions, ChooseVideoOptions } from "./interface.uts" -import { - UniError_ChooseImage, UniError_ChooseVideo, MediaErrorImpl -} from "./unierror.uts" -export const CODE_CAMERA_ERROR = 11; -export const CODE_GALLERY_ERROR = 12; -export const CODE_GET_IMAGE_INFO_CODE = 13 - -export function uniChooseImage(options : ChooseImageOptions, onSourceTypeSelect : (count : number, compressed : boolean, index : number) => void) { - let count = options.count != null ? (options.count! <= 0 ? 9 : options.count) : 9 - // 默认为 false - let compressed = false; - if ((options.sizeType) != null) { - compressed = options.sizeType!.indexOf("original") < 0 - } - /* source type 乱传如何处理 */ - let sourceType : Array = (options.sourceType != null && options.sourceType!.length > 0) ? options.sourceType! : ["album", "camera"]; - let itemList = ["拍摄", "从相册选择"] - if (sourceType.length == 1) { - if (sourceType.indexOf("album") >= 0) { - onSourceTypeSelect(count!, compressed, 1) - } else if (sourceType.indexOf("camera") >= 0) { - onSourceTypeSelect(count!, compressed, 0) - } - return - } - if (sourceType.length == 2) { - uni.showActionSheet({ - itemList: itemList, - success: (e) => { - onSourceTypeSelect(count!, compressed, e.tapIndex!) - }, - fail: (e) => { - let error = new MediaErrorImpl(1101001, UniError_ChooseImage); - options.fail?.(error) - options.complete?.(error) - } - }) - } -} - -export function uniChooseVideo(options : ChooseVideoOptions, onSourceTypeSelect : (count : number, compressed : boolean, index : number) => void) { - let count = 1 - // 默认为 false - let compressed = options.compressed != null ? options.compressed! : true; - - /* source type 乱传如何处理 */ - let sourceType : Array = (options.sourceType != null && options.sourceType!.length > 0) ? options.sourceType! : ["album", "camera"]; - let itemList = ["拍摄", "从相册选择"] - if (sourceType.length == 1) { - if (sourceType.indexOf("album") >= 0) { - onSourceTypeSelect(count!, compressed, 1) - } else if (sourceType.indexOf("camera") >= 0) { - onSourceTypeSelect(count!, compressed, 0) - } - return - } - - if (sourceType.length == 2) { - uni.showActionSheet({ - itemList: itemList, - success: (e) => { - onSourceTypeSelect(count!, compressed, e.tapIndex!) - }, - fail: (e) => { - let error = new MediaErrorImpl(1101001, UniError_ChooseVideo); - options.fail?.(error) - options.complete?.(error) - } - }) - } -} \ No newline at end of file diff --git a/uni_modules/uni-media/utssdk/app-android/index.uts b/uni_modules/uni-media/utssdk/app-android/index.uts index 9b945e37dd1bf579312568fac8d0069723ac9618..44a84121a0cb88d261e974bc84d493ad0eb192b3 100644 --- a/uni_modules/uni-media/utssdk/app-android/index.uts +++ b/uni_modules/uni-media/utssdk/app-android/index.uts @@ -343,6 +343,7 @@ function copyFile(fromFilePath : string, toFilePath : string) : boolean { if (!fromFile.canRead()) { return false; } + fis = new FileInputStream(fromFile); } if (fis == null) { return false @@ -358,7 +359,6 @@ function copyFile(fromFilePath : string, toFilePath : string) : boolean { toFile.createNewFile() } try { - // let fis = new FileInputStream(fromFile) let fos = new FileOutputStream(toFile) let byteArrays = ByteArray(1024) var c = fis!!.read(byteArrays) @@ -592,6 +592,21 @@ export const getVideoInfo : GetVideoInfo = function (options : GetVideoInfoOptio export const saveVideoToPhotosAlbum : SaveVideoToPhotosAlbum = function (options : SaveVideoToPhotosAlbumOptions) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + let requestPermissionList : Array = [Manifest.permission.WRITE_EXTERNAL_STORAGE]; + UTSAndroid.requestSystemPermission(UTSAndroid.getUniActivity()!, requestPermissionList, (a : boolean, b : string[]) => { + loadFile(options); + }, (a : boolean, b : string[]) => { + let error = new MediaErrorImpl(1101005, UniError_SaveVideoToPhotosAlbum); + options.fail?.(error); + options.complete?.(error); + }) + } else { + loadFile(options); + } +} + +function loadFile(options : SaveVideoToPhotosAlbumOptions) { if (TextUtils.isEmpty(options.filePath)) { let error = new MediaErrorImpl(1101003, UniError_SaveVideoToPhotosAlbum); options.fail?.(error) diff --git a/uni_modules/uni-media/utssdk/app-android/utils/ChooseMediaUtils.uts b/uni_modules/uni-media/utssdk/app-android/utils/ChooseMediaUtils.uts index c2ea2c1b2ba031b6d65e8632abb453a972f36d1b..e354bf605bad1662126904a7011147734bf472af 100644 --- a/uni_modules/uni-media/utssdk/app-android/utils/ChooseMediaUtils.uts +++ b/uni_modules/uni-media/utssdk/app-android/utils/ChooseMediaUtils.uts @@ -8,7 +8,7 @@ import { MediaErrorImpl } from "../../unierror.uts" import { getVideoMetadata } from "./MediaUtils.uts" -import { uniChooseImage, uniChooseVideo } from "../../ChooseImageUtils.uts" +import { uniChooseImage, uniChooseVideo } from "./ChooseImageUtils.uts" import { getUniActivity } from "io.dcloud.uts.android"; import Intent from 'android.content.Intent'; import File from 'java.io.File'; diff --git a/uni_modules/uni-media/utssdk/app-android/utils/CompressUtils.uts b/uni_modules/uni-media/utssdk/app-android/utils/CompressUtils.uts index 41157c6cbc7d69b63a737b300815201027d3d462..2977ce16475b3a154022cb07f35988367de5a136 100644 --- a/uni_modules/uni-media/utssdk/app-android/utils/CompressUtils.uts +++ b/uni_modules/uni-media/utssdk/app-android/utils/CompressUtils.uts @@ -46,18 +46,16 @@ export function transcodeImage(options : CompressImageOptions) { var widthStr = "" var heightStr = "" if (options.compressedWidth != null) { - compressOption.width = options.compressedWidth! + widthStr = options.compressedWidth.toString(); } else { widthStr = TextUtils.isEmpty(options.width) ? "auto" : options.width! } if (options.compressedHeight != null) { - compressOption.height = options.compressedHeight! + heightStr = options.compressedHeight.toString(); } else { heightStr = TextUtils.isEmpty(options.height) ? "auto" : options.height! } - if (compressOption.width <= 0 || compressOption.height <= 0) { - getHeightAndWidth(compressOption, widthStr, heightStr) - } + getHeightAndWidth(compressOption, widthStr, heightStr); let bitmapOptions = new BitmapFactory.Options() bitmapOptions.inJustDecodeBounds = false; if (srcFile.length() > 1500000) { @@ -175,7 +173,7 @@ function str2Float(valuestr : string, realValue : number, defValue : number) : n } valuestr = valuestr.toLowerCase() if (valuestr.endsWith("px")) { - valuestr == valuestr.substring(0, valuestr.length - 2); + valuestr = valuestr.substring(0, valuestr.length - 2); } try { return Integer.parseInt(valuestr) @@ -231,8 +229,7 @@ export function transcodeVideo(options : CompressVideoOptions) { } else if (resolution! > 1 || resolution! <= 0) { resolution = 1.0 } - let fileName = getFileName(inPath); - let outPath = mediaCachePath + (fileName == "" ? (System.currentTimeMillis() + ".mp4") : fileName) + let outPath = mediaCachePath + "compress_video_" + System.currentTimeMillis() + ".mp4"; let outFile = new File(outPath) if (!outFile.getParentFile().exists()) { outFile.getParentFile().mkdirs() @@ -241,14 +238,6 @@ export function transcodeVideo(options : CompressVideoOptions) { MediaTranscoder.getInstance().transcodeVideo(inPath, outPath, MediaFormatStrategyPresets.createAndroid720pStrategy(compressLevel, resolution!), new MediaTranscoderListener(inPath, outPath, options)) } -function getFileName(path : string) : string { - const array = path.split("/") - if (array.length > 0) { - return array[array.length - 1] - } - return "" -} - class MediaTranscoderListener implements Listener { inPath : string outPath : string @@ -267,7 +256,7 @@ class MediaTranscoderListener implements Listener { if (outFile.exists()) { let success : CompressVideoSuccess = { tempFilePath: "file://" + this.outPath, - size: outFile.length() + size: outFile.length() / 1024 } this.options.success?.(success) this.options.complete?.(success) diff --git a/uni_modules/uni-media/utssdk/app-android/utils/MediaUtils.uts b/uni_modules/uni-media/utssdk/app-android/utils/MediaUtils.uts index 57bad6f4908a8c566e7ee5844b80b165abfae166..ae6ee26b4bb61c96022423f0a8c98afdbf4856ad 100644 --- a/uni_modules/uni-media/utssdk/app-android/utils/MediaUtils.uts +++ b/uni_modules/uni-media/utssdk/app-android/utils/MediaUtils.uts @@ -25,7 +25,7 @@ export function getVideoMetadata(src : string) : any { let error = new MediaErrorImpl(1101003, UniError_GetVideoInfo); return error } - videoInfo.size = videoFile.length() + videoInfo.size = videoFile.length() / 1024; try { let retriever = new MediaMetadataRetriever() retriever.setDataSource(path) diff --git a/uni_modules/uni-media/utssdk/app-ios/Frameworks/DCloudMediaPicker.xcframework/Info.plist b/uni_modules/uni-media/utssdk/app-ios/Frameworks/DCloudMediaPicker.xcframework/Info.plist index acbb5e10138890e053186683aa5ac3a18e4057ce..36d27d6b82a40240346a63370baca0b01819c7a0 100644 --- a/uni_modules/uni-media/utssdk/app-ios/Frameworks/DCloudMediaPicker.xcframework/Info.plist +++ b/uni_modules/uni-media/utssdk/app-ios/Frameworks/DCloudMediaPicker.xcframework/Info.plist @@ -8,32 +8,32 @@ BinaryPath DCloudMediaPicker.framework/DCloudMediaPicker LibraryIdentifier - ios-arm64 + ios-arm64_x86_64-simulator LibraryPath DCloudMediaPicker.framework SupportedArchitectures arm64 + x86_64 SupportedPlatform ios + SupportedPlatformVariant + simulator BinaryPath DCloudMediaPicker.framework/DCloudMediaPicker LibraryIdentifier - ios-arm64_x86_64-simulator + ios-arm64 LibraryPath DCloudMediaPicker.framework SupportedArchitectures arm64 - x86_64 SupportedPlatform ios - SupportedPlatformVariant - simulator CFBundlePackageType diff --git a/uni_modules/uni-media/utssdk/app-ios/Frameworks/DCloudMediaPicker.xcframework/ios-arm64/DCloudMediaPicker.framework/DCloudMediaPicker b/uni_modules/uni-media/utssdk/app-ios/Frameworks/DCloudMediaPicker.xcframework/ios-arm64/DCloudMediaPicker.framework/DCloudMediaPicker index 53df847de192f7b2f8e7e0eb9ba84fda3f1c9794..ec8eea0b6e8288273f73da65ec474bc14a4e737d 100644 Binary files a/uni_modules/uni-media/utssdk/app-ios/Frameworks/DCloudMediaPicker.xcframework/ios-arm64/DCloudMediaPicker.framework/DCloudMediaPicker and b/uni_modules/uni-media/utssdk/app-ios/Frameworks/DCloudMediaPicker.xcframework/ios-arm64/DCloudMediaPicker.framework/DCloudMediaPicker differ diff --git a/uni_modules/uni-media/utssdk/app-ios/Frameworks/DCloudMediaPicker.xcframework/ios-arm64_x86_64-simulator/DCloudMediaPicker.framework/DCloudMediaPicker b/uni_modules/uni-media/utssdk/app-ios/Frameworks/DCloudMediaPicker.xcframework/ios-arm64_x86_64-simulator/DCloudMediaPicker.framework/DCloudMediaPicker index 82231a550c92f7c99a41788cea406b720cd1716f..372e0eb9463d26ebad0dbc97d158686599bc77f2 100644 Binary files a/uni_modules/uni-media/utssdk/app-ios/Frameworks/DCloudMediaPicker.xcframework/ios-arm64_x86_64-simulator/DCloudMediaPicker.framework/DCloudMediaPicker and b/uni_modules/uni-media/utssdk/app-ios/Frameworks/DCloudMediaPicker.xcframework/ios-arm64_x86_64-simulator/DCloudMediaPicker.framework/DCloudMediaPicker differ diff --git a/uni_modules/uni-media/utssdk/app-ios/Frameworks/DCloudMediaPicker.xcframework/ios-arm64_x86_64-simulator/DCloudMediaPicker.framework/_CodeSignature/CodeDirectory b/uni_modules/uni-media/utssdk/app-ios/Frameworks/DCloudMediaPicker.xcframework/ios-arm64_x86_64-simulator/DCloudMediaPicker.framework/_CodeSignature/CodeDirectory index b43c40fc441f50c1bf104422b4fdcce263bb8af3..84df794288122589c10b297f4505add42700b6e1 100644 Binary files a/uni_modules/uni-media/utssdk/app-ios/Frameworks/DCloudMediaPicker.xcframework/ios-arm64_x86_64-simulator/DCloudMediaPicker.framework/_CodeSignature/CodeDirectory and b/uni_modules/uni-media/utssdk/app-ios/Frameworks/DCloudMediaPicker.xcframework/ios-arm64_x86_64-simulator/DCloudMediaPicker.framework/_CodeSignature/CodeDirectory differ diff --git a/uni_modules/uni-media/utssdk/app-ios/Frameworks/DCloudMediaPicker.xcframework/ios-arm64_x86_64-simulator/DCloudMediaPicker.framework/_CodeSignature/CodeRequirements-1 b/uni_modules/uni-media/utssdk/app-ios/Frameworks/DCloudMediaPicker.xcframework/ios-arm64_x86_64-simulator/DCloudMediaPicker.framework/_CodeSignature/CodeRequirements-1 index 62fa0caf89c1740d145ee9e93b46e79ae28add30..46efb4280f6b7981be4e6dd4951af0efba168594 100644 Binary files a/uni_modules/uni-media/utssdk/app-ios/Frameworks/DCloudMediaPicker.xcframework/ios-arm64_x86_64-simulator/DCloudMediaPicker.framework/_CodeSignature/CodeRequirements-1 and b/uni_modules/uni-media/utssdk/app-ios/Frameworks/DCloudMediaPicker.xcframework/ios-arm64_x86_64-simulator/DCloudMediaPicker.framework/_CodeSignature/CodeRequirements-1 differ diff --git a/uni_modules/uni-media/utssdk/app-ios/Frameworks/DCloudMediaPicker.xcframework/ios-arm64_x86_64-simulator/DCloudMediaPicker.framework/_CodeSignature/CodeResources b/uni_modules/uni-media/utssdk/app-ios/Frameworks/DCloudMediaPicker.xcframework/ios-arm64_x86_64-simulator/DCloudMediaPicker.framework/_CodeSignature/CodeResources index 04b7ae1ba3fad6d0e11ece1816319c5eaeb650a5..e4a35afd077442fe1f9816b01c0e31d7c80c623b 100644 --- a/uni_modules/uni-media/utssdk/app-ios/Frameworks/DCloudMediaPicker.xcframework/ios-arm64_x86_64-simulator/DCloudMediaPicker.framework/_CodeSignature/CodeResources +++ b/uni_modules/uni-media/utssdk/app-ios/Frameworks/DCloudMediaPicker.xcframework/ios-arm64_x86_64-simulator/DCloudMediaPicker.framework/_CodeSignature/CodeResources @@ -28,6 +28,10 @@ nghJYGVbKFhvAi/+2XYvdy408is= + PrivacyInfo.xcprivacy + + L50owgIQfV6zTzg7T11NlSDYSZU= + files2 @@ -86,6 +90,17 @@ M9nMA2y1DqhJFLOymGCa66mNVw5qDN8J1QzcxQD3H/w= + PrivacyInfo.xcprivacy + + hash + + L50owgIQfV6zTzg7T11NlSDYSZU= + + hash2 + + NOpzMYrYXZEAI4Xdo9XJX+tflymAvdW2UHdZwen1+iU= + + rules diff --git a/uni_modules/uni-media/utssdk/app-ios/index.uts b/uni_modules/uni-media/utssdk/app-ios/index.uts index 1eca53f5718696edaa68f6cb7b8e6bd3f599dc20..cbb848f6c2af043a06c4f4fa3bb84dc114c69b81 100644 --- a/uni_modules/uni-media/utssdk/app-ios/index.uts +++ b/uni_modules/uni-media/utssdk/app-ios/index.uts @@ -2,13 +2,15 @@ import { ChooseImageOptions, ChooseImage, ChooseImageSuccess, PreviewImageOptions, PreviewImage, PreviewImageSuccess, ClosePreviewImage, ClosePreviewImageSuccess, ClosePreviewImageOptions, - SaveImageToPhotosAlbum, SaveImageToPhotosAlbumOptions, SaveImageToPhotosAlbumSuccess, + SaveImageToPhotosAlbum, SaveImageToPhotosAlbumOptions, SaveImageToPhotosAlbumSuccess, + ChooseVideo, ChooseVideoOptions, + SaveVideoToPhotosAlbum, SaveVideoToPhotosAlbumOptions, SaveVideoToPhotosAlbumSuccess, ChooseVideoSuccess, } from "../interface.uts"; import { UniError_ChooseImage, UniError_SaveImageToPhotosAlbum, - MediaErrorImpl,UniError_PreviewImage + MediaErrorImpl,UniError_PreviewImage, UniError_ChooseVideo, UniError_SaveVideoToPhotosAlbum } from "../unierror.uts" -import { uniChooseImage, uniChooseVideo } from "../ChooseImageUtils.uts"; +import { uniChooseImage, uniChooseVideo } from "./ChooseImageUtils.uts"; import { UTSiOS } from "DCloudUTSFoundation"; import { NSFileManager } from "Foundation"; @@ -23,7 +25,7 @@ export const chooseImage : ChooseImage = function (option : ChooseImageOptions) if (index == 0) { requestCameraPermission(function (status : number) { if (status == 1) { - mediaPicker.openCameraForImage(option, compressed) + mediaPicker.openCameraForImage(option) } else { let error = new MediaErrorImpl(1101005, UniError_ChooseImage); option.fail?.(error) @@ -34,7 +36,7 @@ export const chooseImage : ChooseImage = function (option : ChooseImageOptions) } else if (index == 1) { requestAlbumPermission("readWrite", function (status : number) { if (status == 1) { - mediaPicker.openAlbumForImage(option, count, 101) + mediaPicker.openAlbumForImage(option, count) } else { let error = new MediaErrorImpl(1101005, UniError_ChooseImage); option.fail?.(error) @@ -45,14 +47,57 @@ export const chooseImage : ChooseImage = function (option : ChooseImageOptions) }); } +export const chooseVideo : ChooseVideo = function (option : ChooseVideoOptions) { + uniChooseVideo(option, (count : number, compressed : boolean, index : number) => { + if (index == 0) { + requestCameraPermission(function (status : number) { + if (status == 1) { + requestMicrophonePermission(function (status : number){ + if (status == 1) { + mediaPicker.openCameraForVideo(option) + }else{ + let error = new MediaErrorImpl(1101005, UniError_ChooseVideo); + option.fail?.(error) + option.complete?.(error) + } + }) + + } else { + let error = new MediaErrorImpl(1101005, UniError_ChooseVideo); + option.fail?.(error) + option.complete?.(error) + } + }) + + } else if (index == 1) { + requestAlbumPermission("readWrite", function (status : number) { + if (status == 1) { + mediaPicker.openAlbumForVideo(option) + } else { + let error = new MediaErrorImpl(1101005, UniError_ChooseVideo); + option.fail?.(error) + option.complete?.(error) + } + }) + } + }) +} + class DCUniMediaPicker { - private mediaAlbum : DCloudMediaAlbum = new DCloudMediaAlbum(); - private mediaCamera : DCloudMediaCamera = new DCloudMediaCamera(); - openAlbumForImage(option : ChooseImageOptions, count : number, type : number){ - this.chooseImageWithAlbum(option,count,type); + private mediaAlbum : DCloudMediaAlbum | null = null; + private mediaCamera : DCloudMediaCamera | null = null; + private imageBrowser : PreviewImageBrowser | null = null; + openAlbumForImage(option : ChooseImageOptions, count : number){ + this.chooseImageWithAlbum(option,count); + } + openAlbumForVideo(option : ChooseVideoOptions){ + this.chooseVideoWithAlbum(option); } - openCameraForImage(option : ChooseImageOptions, compressed : boolean){ - this.chooseImageWithCamera(option,compressed); + openCameraForVideo(option : ChooseVideoOptions){ + this.chooseVideoWithCamera(option); + } + openCameraForImage(option : ChooseImageOptions){ + this.chooseImageWithCamera(option); } preview(options : PreviewImageOptions){ this.previewImageWithOptions(options); @@ -60,7 +105,47 @@ class DCUniMediaPicker { close(){ this.closePreview(); } - private chooseImageWithAlbum(option : ChooseImageOptions, count : number, type : number){ + + private chooseVideoWithAlbum(option : ChooseVideoOptions){ + const mediaCachePath = UTSiOS.getMediaCacheDir() + "/" + let fileManager = FileManager.default + if (fileManager.fileExists(atPath = mediaCachePath) == false) { + try { + UTSiOS.try(fileManager.createDirectory(atPath = mediaCachePath, withIntermediateDirectories = true, attributes = null)) + } catch (e) { + console.log(e) + } + } + let options : Map = new Map(); + options.set('resolution', "high"); + options.set('videoCompress', option.compressed); + options.set('filePath', mediaCachePath); + options.set('maximum', 1); + options.set('filter', "video"); + DispatchQueue.main.async(execute = () : void => { + if (this.mediaAlbum == null){ + this.mediaAlbum = new DCloudMediaAlbum(); + } + this.mediaAlbum?.start(options, success = (response : Map) : void => { + const filePath : string = response.get('tempFilePath') as string + let success : ChooseVideoSuccess = { + tempFilePath: "file://" + filePath, + width: response.get('width'), + height: response.get('height'), + size: response.get('size'), + duration: response.get('duration'), + } + option.success?.(success) + option.complete?.(success) + }, fail = (code : number) : void => { + let mediaError = new MediaErrorImpl(code, UniError_ChooseVideo); + option.fail?.(mediaError) + option.complete?.(mediaError) + }) + }) + } + + private chooseImageWithAlbum(option : ChooseImageOptions, count : number){ const mediaCachePath = UTSiOS.getMediaCacheDir() + "/" let fileManager = FileManager.default if (fileManager.fileExists(atPath = mediaCachePath) == false) { @@ -94,7 +179,10 @@ class DCUniMediaPicker { options.set('crop', crop); } DispatchQueue.main.async(execute = () : void => { - this.mediaAlbum.start(options, success = (response : Map) : void => { + if (this.mediaAlbum == null){ + this.mediaAlbum = new DCloudMediaAlbum(); + } + this.mediaAlbum?.start(options, success = (response : Map) : void => { let success : ChooseImageSuccess = { "errSubject": "uni-chooseImage", "tempFilePaths": response.get('tempFilePaths'), @@ -111,7 +199,59 @@ class DCUniMediaPicker { }) } - private chooseImageWithCamera(option : ChooseImageOptions, compressed : boolean){ + private chooseVideoWithCamera(option : ChooseVideoOptions){ + const mediaCachePath = UTSiOS.getMediaCacheDir() + "/" + const fileManager = FileManager.default + if (fileManager.fileExists(atPath = mediaCachePath) == false) { + try { + UTSiOS.try(fileManager.createDirectory(atPath = mediaCachePath, withIntermediateDirectories = true, attributes = null)) + } catch (e) { + console.log(e) + } + } + + const currentTime = Int(Date().timeIntervalSince1970) + const cameraPath = (mediaCachePath + currentTime.toString() + ".mp4") + + let options : Map = new Map(); + options.set('resolution', "high"); + options.set('videoCompress', option.compressed); + options.set('filePath', cameraPath); + options.set('type', "video"); + if (option.maxDuration != null){ + if(option.maxDuration! > 0){ + options.set('videoMaximumDuration', option.maxDuration); + } + }else{ + options.set('videoMaximumDuration', 60); + } + if (option.camera != null){ + options.set('index', option.camera == "front" ? 2 : 1); + } + + DispatchQueue.main.async(execute = () : void => { + if (this.mediaCamera == null){ + this.mediaCamera = new DCloudMediaCamera(); + } + this.mediaCamera?.start(options, success = (response : Map) : void => { + let success : ChooseVideoSuccess = { + tempFilePath: "file://" + cameraPath, + width: response.get('width'), + height: response.get('height'), + size: response.get('size'), + duration: response.get('duration'), + } + option.success?.(success) + option.complete?.(success) + }, fail = (code : number) : void => { + let mediaError = new MediaErrorImpl(code, UniError_ChooseVideo); + option.fail?.(mediaError) + option.complete?.(mediaError) + }) + }) + } + + private chooseImageWithCamera(option : ChooseImageOptions){ const mediaCachePath = UTSiOS.getMediaCacheDir() + "/" const fileManager = FileManager.default if (fileManager.fileExists(atPath = mediaCachePath) == false) { @@ -129,6 +269,7 @@ class DCUniMediaPicker { options.set('resolution', "high"); options.set('sizeType', option.sizeType); options.set('filePath', cameraPath); + options.set('type', "image"); if (option.crop != null) { let crop : Map = new Map(); if (option.crop!.width != nil) { @@ -146,7 +287,10 @@ class DCUniMediaPicker { options.set('crop', crop); } DispatchQueue.main.async(execute = () : void => { - this.mediaCamera.start(options, success = (response : Map) : void => { + if (this.mediaCamera == null){ + this.mediaCamera = new DCloudMediaCamera(); + } + this.mediaCamera?.start(options, success = (response : Map) : void => { let success : ChooseImageSuccess = { "errSubject": "uni-chooseImage", "tempFilePaths": ["file://" + cameraPath], @@ -163,9 +307,14 @@ class DCUniMediaPicker { }) } - private imageBrowser = new PreviewImageBrowser() + private closePreview(){ - this.imageBrowser.close() + DispatchQueue.main.async(execute=():void => { + if (this.imageBrowser == null){ + this.imageBrowser = new PreviewImageBrowser(); + } + this.imageBrowser?.close(); + }) } private previewImageWithOptions(options : PreviewImageOptions){ @@ -187,13 +336,33 @@ class DCUniMediaPicker { op.set('loop', options.loop); op.set("cachePath", UTSiOS.getMediaCacheDir()); DispatchQueue.main.async(execute=():void => { - this.imageBrowser.startPreview(op); + if (this.imageBrowser == null){ + this.imageBrowser = new PreviewImageBrowser(); + } + this.imageBrowser?.startPreview(op); }) let success : PreviewImageSuccess = { errMsg: 'ok', "errSubject": UniError_PreviewImage } options.success?.(success) options.complete?.(success) } +} + +function requestMicrophonePermission(completion : (status : number) => void) { + let authorized = AVCaptureDevice.authorizationStatus(for= AVMediaType.audio) + if (authorized == AVAuthorizationStatus.authorized) { + completion(1) + } else if (authorized == AVAuthorizationStatus.notDetermined) { + AVCaptureDevice.requestAccess(for=AVMediaType.audio, completionHandler = (result : Bool) : void => { + if (result) { + completion(1) + } else { + completion(0) + } + }) + } else { + completion(0) + } } function requestCameraPermission(completion : (status : number) => void) { @@ -334,4 +503,35 @@ export const saveImageToPhotosAlbum : SaveImageToPhotosAlbum = function (options options.complete?.(error) } }) +} + +export const saveVideoToPhotosAlbum : SaveVideoToPhotosAlbum = function (options : SaveVideoToPhotosAlbumOptions) { + const path = UTSiOS.getResourceAbsolutePath(options.filePath,null) + let url = new URL(string = path) + if (url == null) { + let error = new MediaErrorImpl(1101003, UniError_SaveVideoToPhotosAlbum); + options.fail?.(error) + options.complete?.(error) + return + } + requestAlbumPermission("addOnly", function (status : number) { + if (status == 1) { + try { + UTSiOS.try(PHPhotoLibrary.shared().performChangesAndWait(() : void => { + PHAssetCreationRequest.creationRequestForAssetFromVideo(atFileURL = url!) + })) + let success : SaveVideoToPhotosAlbumSuccess = {} + options.success?.(success) + options.complete?.(success) + } catch (e) { + let error = new MediaErrorImpl(1101006, UniError_SaveVideoToPhotosAlbum); + options.fail?.(error) + options.complete?.(error) + } + } else { + let error = new MediaErrorImpl(1101005, UniError_SaveVideoToPhotosAlbum); + options.fail?.(error) + options.complete?.(error) + } + }) } \ No newline at end of file diff --git a/uni_modules/uni-media/utssdk/app-ios/info.plist b/uni_modules/uni-media/utssdk/app-ios/info.plist index ee3a2507358f1c198bc34e7c3c5bd0e8aa432c4d..8e69cb22415bdb2f47ac91abf679781eb4cd0212 100644 --- a/uni_modules/uni-media/utssdk/app-ios/info.plist +++ b/uni_modules/uni-media/utssdk/app-ios/info.plist @@ -5,8 +5,10 @@ NSCameraUsageDescription APP需要您的同意,才能使用摄像头,以便于相机拍摄 NSPhotoLibraryAddUsageDescription - APP需要您的同意,才能访问相册,以便于保存图片 + APP需要您的同意,才能访问相册,以便于保存图像 NSPhotoLibraryUsageDescription - APP需要您的同意,才能访问相册,以便于图片选取 + APP需要您的同意,才能访问相册,以便于图像选取 + NSMicrophoneUsageDescription + APP需要您的同意,才能使用麦克风,以便于录制音频 \ No newline at end of file diff --git a/uni_modules/uni-media/utssdk/interface.uts b/uni_modules/uni-media/utssdk/interface.uts index f7979fff575ea74fa08bc7f99980fe8037538efd..84ea9da38c1316a9240a27e560875fee7105e45b 100644 --- a/uni_modules/uni-media/utssdk/interface.uts +++ b/uni_modules/uni-media/utssdk/interface.uts @@ -79,6 +79,12 @@ export type ChooseImageOptions = { * original 原图,compressed 压缩图,默认二者都有 * @type string | string [] * @defaultValue ['original','compressed'] + * @uniPlatform { + * "web": { + * "uniVer": "x", + * "unixVer": "x" + * } + * } */ sizeType ?: (string[]) | null, /** @@ -101,6 +107,12 @@ export type ChooseImageOptions = { extension ?: (string[]) | null, /** * 图像裁剪参数,设置后 sizeType 失效。 + * @uniPlatform { + * "web": { + * "uniVer": "x", + * "unixVer": "x" + * } + * } */ crop ?: (ChooseImageCropOptions) | null, /** @@ -171,7 +183,7 @@ export type PreviewImageCompleteCallback = ChooseImageCompleteCallback export type PreviewImageOptions = { /** - * current 为当前显示图片的链接/索引值,不填或填写的值无效则为 urls 的第一张。 + * current 为当前显示图片的链接/索引值,不填或填写的值无效则为 urls 的第一张。APP平台仅支持索引值。 * @type string | number */ current ?: any | null, @@ -197,7 +209,7 @@ export type PreviewImageOptions = { * @uniPlatform { * "app": { * "android": { - * "osVer": "4.4", + * "osVer": "5.0", * "uniVer": "√", * "unixVer": "x" * } @@ -265,10 +277,22 @@ export type GetImageInfoSuccess = { path : string, /** * 返回图片的方向 + * @uniPlatform { + * "web": { + * "uniVer": "x", + * "unixVer": "x" + * } + * } */ orientation : string | null, /** * 返回图片的格式 + * @uniPlatform { + * "web": { + * "uniVer": "x", + * "unixVer": "x" + * } + * } */ type : string | null }; @@ -357,10 +381,12 @@ export type CompressImageOptions = { rotate ?: number | null, /** * 缩放图片的宽度 + * @deprecated 已废弃 */ width ?: string | null, /** * 缩放图片的高度 + * @deprecated 已废弃 */ height ?: string | null, /** @@ -429,10 +455,23 @@ export type ChooseVideoOptions = { /** * 是否压缩所选的视频源文件,默认值为true,需要压缩 * @type boolean + * @default true + * @uniPlatform { + * "web": { + * "uniVer": "x", + * "unixVer": "x" + * } + * } */ compressed ?: boolean | null, /** * 拍摄视频最长拍摄时间,单位秒。最长支持 60 秒 + * @uniPlatform { + * "web": { + * "uniVer": "x", + * "unixVer": "x" + * } + * } */ maxDuration ?: number | null, /** @@ -440,10 +479,25 @@ export type ChooseVideoOptions = { * - front: 前置摄像头 * - back: 后置摄像头 * @type 'front' | 'back' + * @uniPlatform { + * "web": { + * "uniVer": "x", + * "unixVer": "x" + * } + * } */ camera ?: string | null, /** * 根据文件拓展名过滤,每一项都不能是空字符串。默认不过滤。 + * @uniPlatform { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "x" + * } + * } + * } */ extension ?: (string[]) | null, /** @@ -465,10 +519,22 @@ export type ChooseVideo = (options : ChooseVideoOptions) => void; export type GetVideoInfoSuccess = { /** * 画面方向 + * @uniPlatform { + * "web": { + * "uniVer": "x", + * "unixVer": "x" + * } + * } */ orientation : string | null, /** * 视频格式 + * @uniPlatform { + * "web": { + * "uniVer": "x", + * "unixVer": "x" + * } + * } */ type : string | null, /** @@ -489,10 +555,22 @@ export type GetVideoInfoSuccess = { width : number, /** * 视频帧率 + * @uniPlatform { + * "web": { + * "uniVer": "x", + * "unixVer": "x" + * } + * } */ fps : number | null, /** * 视频码率,单位 kbps + * @uniPlatform { + * "web": { + * "uniVer": "x", + * "unixVer": "x" + * } + * } */ bitrate : number | null }; @@ -582,10 +660,28 @@ export type CompressVideoOptions = { quality ?: string | null, /** * 码率,单位 kbps + * @uniPlatform { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "x" + * } + * } + * } */ bitrate ?: number | null, /** * 帧率 + * @uniPlatform { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "x" + * } + * } + * } */ fps ?: number | null, /** @@ -615,7 +711,7 @@ export interface Uni { * @uniPlatform { * "app": { * "android": { - * "osVer": "4.4", + * "osVer": "5.0", * "uniVer": "√", * "unixVer": "3.9+" * }, @@ -652,7 +748,7 @@ export interface Uni { * @uniPlatform { * "app": { * "android": { - * "osVer": "4.4", + * "osVer": "5.0", * "uniVer": "√", * "unixVer": "3.9+" * }, @@ -689,7 +785,7 @@ export interface Uni { * @uniPlatform { * "app": { * "android": { - * "osVer": "4.4", + * "osVer": "5.0", * "uniVer": "√", * "unixVer": "3.9+" * }, @@ -698,7 +794,11 @@ export interface Uni { * "uniVer": "√", * "unixVer": "4.11" * } - * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } * } * @uniVueVersion 2,3 * @example @@ -721,11 +821,15 @@ export interface Uni { * @uniPlatform { * "app": { * "android": { - * "osVer": "4.4", + * "osVer": "5.0", * "uniVer": "√", - * "unixVer": "3.9+" + * "unixVer": "4.18" * } - * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } * } * @uniVueVersion 2,3 * @example @@ -754,7 +858,7 @@ export interface Uni { * @uniPlatform { * "app": { * "android": { - * "osVer": "4.4", + * "osVer": "5.0", * "uniVer": "√", * "unixVer": "3.9+" * }, @@ -763,7 +867,11 @@ export interface Uni { * "uniVer": "√", * "unixVer": "4.11" * } - * } + * }, + * "web": { + * "uniVer": "x", + * "unixVer": "x" + * } * } * @uniVueVersion 2,3 * @example @@ -792,11 +900,15 @@ export interface Uni { * @uniPlatform { * "app": { * "android": { - * "osVer": "4.4", + * "osVer": "5.0", * "uniVer": "√", - * "unixVer": "3.9+" + * "unixVer": "4.18" * } - * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } * } * @uniVueVersion 2,3 * @example @@ -826,11 +938,20 @@ export interface Uni { * @uniPlatform { * "app": { * "android": { - * "osVer": "4.4", + * "osVer": "5.0", * "uniVer": "√", - * "unixVer": "3.9+" + * "unixVer": "4.18" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.18" * } - * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } * } * @uniVueVersion 2,3 * @example @@ -851,11 +972,15 @@ export interface Uni { * @uniPlatform { * "app": { * "android": { - * "osVer": "4.4", + * "osVer": "5.0", * "uniVer": "√", - * "unixVer": "3.9+" + * "unixVer": "4.18" * } - * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } * } * @uniVueVersion 2,3 * @example @@ -877,11 +1002,20 @@ export interface Uni { * @uniPlatform { * "app": { * "android": { - * "osVer": "4.4", + * "osVer": "5.0", * "uniVer": "√", - * "unixVer": "3.9+" + * "unixVer": "4.18" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.18" * } - * } + * }, + * "web": { + * "uniVer": "x", + * "unixVer": "x" + * } * } * @uniVueVersion 2,3 * @example @@ -903,11 +1037,15 @@ export interface Uni { * @uniPlatform { * "app": { * "android": { - * "osVer": "4.4", + * "osVer": "5.0", * "uniVer": "√", - * "unixVer": "3.9+" + * "unixVer": "4.18" * } - * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } * } * @uniVueVersion 2,3 * @example diff --git a/uni_modules/uni-navigationBar/utssdk/app-android/index.uts b/uni_modules/uni-navigationBar/utssdk/app-android/index.uts index f8a5df2518ab00fb6667cdedbb7591557ce1438c..adf800beb4303ea8beae8fe174a35c44717a6ff1 100644 --- a/uni_modules/uni-navigationBar/utssdk/app-android/index.uts +++ b/uni_modules/uni-navigationBar/utssdk/app-android/index.uts @@ -25,17 +25,12 @@ export const setNavigationBarColor = defineAsyncApi< appPage!.updateStyle( new Map([ [ - 'navigationBar', - new Map([ - [ - 'navigationBarTextStyle', - options.frontColor == '#000000' ? 'black' : 'white', - ], - [ - 'navigationBarBackgroundColor', - options.backgroundColor, - ], - ]), + 'navigationBarTextStyle', + options.frontColor == '#000000' ? 'black' : 'white', + ], + [ + 'navigationBarBackgroundColor', + options.backgroundColor, ], ]), ) @@ -57,12 +52,7 @@ export const setNavigationBarTitle = defineAsyncApi< const appPage = page.$nativePage appPage!.updateStyle( new Map([ - [ - 'navigationBar', - new Map([ - ['navigationBarTitleText', options.title], - ]), - ], + ['navigationBarTitleText', options.title], ]), ) res.resolve(null) diff --git a/uni_modules/uni-network/utssdk/app-ios/index.uts b/uni_modules/uni-network/utssdk/app-ios/index.uts index bc6c3c7dcfd4960c0e369204845f82a2bef9b1ec..cc7a69b47137cc8ffa593b63bb6578ba8535328c 100644 --- a/uni_modules/uni-network/utssdk/app-ios/index.uts +++ b/uni_modules/uni-network/utssdk/app-ios/index.uts @@ -1,15 +1,15 @@ -import { Request, RequestOptions, RequestSuccess, RequestFail, RequestTask, UploadFileOptions, UploadFile, UploadTask, OnProgressUpdateResult, UploadFileSuccess, UploadFileProgressUpdateCallback, DownloadFileProgressUpdateCallback, DownloadFileOptions, OnProgressDownloadResult, DownloadFile ,DownloadFileSuccess} from './interface'; +import { Request, RequestOptions, RequestSuccess, RequestFail, RequestTask, UploadFileOptions, UploadFile, UploadTask, OnProgressUpdateResult, UploadFileSuccess, UploadFileProgressUpdateCallback, DownloadFileProgressUpdateCallback, DownloadFileOptions, OnProgressDownloadResult, DownloadFile, DownloadFileSuccess } from './interface'; import { NetworkManager, NetworkRequestListener, NetworkUploadFileListener, NetworkDownloadFileListener } from './network/NetworkManager.uts' import { Data, HTTPURLResponse, NSError, NSNumber, ComparisonResult, RunLoop, Thread } from 'Foundation'; import { StatusCode } from './network/StatusCode.uts'; import { RequestFailImpl, UploadFileFailImpl, DownloadFileFailImpl, getErrcode } from '../unierror'; -class SimpleNetworkListener extends NetworkRequestListener { - private param : RequestOptions | null = null; +class SimpleNetworkListener extends NetworkRequestListener { + private param : RequestOptions | null = null; private headers : Map | null = null; private received : number = 0; private data : Data = new Data(); - constructor(param : RequestOptions) { + constructor(param : RequestOptions) { this.param = param; super(); } @@ -53,12 +53,21 @@ class SimpleNetworkListener extends NetworkRequestListener { result['data'] = this.parseData(this.data, strData, type); - let tmp : RequestSuccess = { - data: result['data']!, + if (result['data'] == null) { + let failResult = new RequestFailImpl(getErrcode(100001)); + let fail = kParam?.fail; + let complete = kParam?.complete; + fail?.(failResult); + complete?.(failResult); + return + } + + let tmp = new RequestSuccess({ + data: result['data']! as T, statusCode: (new NSNumber(value = response.statusCode)), header: result['header'] ?? "", cookies: this.parseCookie(this.headers) - }; + }) let success = kParam?.success; let complete = kParam?.complete; success?.(tmp); @@ -69,21 +78,21 @@ class SimpleNetworkListener extends NetworkRequestListener { public override onFail(error : NSError) : void { let kParam = this.param; - let code = (error as NSError).code; + let code = (error as NSError).code; let errCode = code; let cause = error.localizedDescription; - if (code == -1001) { - errCode = 5; - } else if (code == -1004) { - errCode = 1000; - } else if (code == -1009) { - errCode = 600003; - } else { - errCode = 602001; - } - - let failResult = new RequestFailImpl(getErrcode(Number.from(errCode))); - failResult.cause = new SourceError(cause); + if (code == -1001) { + errCode = 5; + } else if (code == -1004) { + errCode = 1000; + } else if (code == -1009) { + errCode = 600003; + } else { + errCode = 602001; + } + + let failResult = new RequestFailImpl(getErrcode(Number.from(errCode))); + failResult.cause = new SourceError(cause); let fail = kParam?.fail; let complete = kParam?.complete; @@ -108,52 +117,59 @@ class SimpleNetworkListener extends NetworkRequestListener { return result; } - private parseData(data : Data | null, dataStr : string | null, type : string | null) : any | null { - if (type != null && type!.contains("json")) { - if (dataStr == null || dataStr!.length == 0) { - return {}; - } - return this.parseJson(dataStr!); - } else if (type == 'jsonp') { - if (dataStr == null || dataStr!.length == 0) { - return {}; - } - let start = dataStr!.indexOf('('); - let end = dataStr!.indexOf(')'); - if (start == 0 || start >= end) { - return {}; + private parseData(data : Data | null, dataStr : string | null, parseType : string | null) : any | null { + if (`${type(of = T.self)}` == "Any.Protocol" || `${type(of = T.self)}` == "Optional.Type") { + if (parseType != null && parseType!.contains("json")) { + if (dataStr == null || dataStr!.length == 0) { + return {}; + } + + return JSON.parse(dataStr!); + } else if (parseType == 'jsonp') { + if (dataStr == null || dataStr!.length == 0) { + return {}; + } + let start = dataStr!.indexOf('('); + let end = dataStr!.indexOf(')'); + if (start == 0 || start >= end) { + return {}; + } + start += 1; + let tmp = dataStr!.slice(start, end); + return JSON.parse(tmp); + } else { + //dataStr如果解码失败是空的时候,还需要继续尝试解码。极端情况,服务器不是utf8的,所以字符解码会出现乱码,所以特殊处理一下非utf8的字符。 + if (data == null) { + return data; + } + + let currentStr : string | null = dataStr; + //todo 等uts支持swift文件混编的时候,再进行处理。 + // if (currentStr == null) { + // let data = cleanUTF8(data); + // if (data != null) { + // currentStr = new String(data = data, encoding = String.Encoding.utf8); + // } + // } + + if (currentStr == null) { + currentStr = new String(data = data!, encoding = String.Encoding.utf8); + } + // utf8 如果失败了,就用ascii,虽然几率很小。 + if (currentStr == null) { + currentStr = new String(data = data!, encoding = String.Encoding.ascii); + } + + return currentStr; } - start += 1; - let tmp = dataStr!.slice(start, end); - return this.parseJson(tmp); } else { - //dataStr如果解码失败是空的时候,还需要继续尝试解码。极端情况,服务器不是utf8的,所以字符解码会出现乱码,所以特殊处理一下非utf8的字符。 - if (data == null) { - return data; - } - - let currentStr : string | null = dataStr; - //todo 等uts支持swift文件混编的时候,再进行处理。 - // if (currentStr == null) { - // let data = cleanUTF8(data); - // if (data != null) { - // currentStr = new String(data = data, encoding = String.Encoding.utf8); - // } - // } - - if (currentStr == null) { - currentStr = new String(data = data!, encoding = String.Encoding.ascii); + if (dataStr == null || dataStr!.length == 0) { + return null; } - - return currentStr; + return JSON.parse(dataStr!) } } - - private parseJson(str : string) : any | null { - return JSON.parse(str); - } - private parseCookie(header : Map | null) : string[] { if (header == null) { return [] @@ -275,7 +291,7 @@ class UploadNetworkListener implements NetworkUploadFileListener { } class DownloadNetworkListener implements NetworkDownloadFileListener { - public options : DownloadFileOptions | null = null; + public options : DownloadFileOptions | null = null; public progressListeners : Array = []; private data : Data = new Data(); @@ -293,19 +309,19 @@ class DownloadNetworkListener implements NetworkDownloadFileListener { } } - onFinished(response : HTTPURLResponse, filePath: string) : void { - try { - let kParam = this.options; - let tmp : DownloadFileSuccess = { - tempFilePath:filePath, - statusCode: response.statusCode - }; - let success = kParam?.success; - let complete = kParam?.complete; - success?.(tmp); - complete?.(tmp); - } catch (e) { - } + onFinished(response : HTTPURLResponse, filePath : string) : void { + try { + let kParam = this.options; + let tmp : DownloadFileSuccess = { + tempFilePath: filePath, + statusCode: response.statusCode + }; + let success = kParam?.success; + let complete = kParam?.complete; + success?.(tmp); + complete?.(tmp); + } catch (e) { + } this.progressListeners.splice(0, this.progressListeners.length) } @@ -313,7 +329,7 @@ class DownloadNetworkListener implements NetworkDownloadFileListener { let kParam = this.options; let code = (error as NSError).code; let errCode = code; - let cause = error.localizedDescription; + let cause = error.localizedDescription; if (code == -1001) { errCode = 5; } else if (code == -1004) { @@ -335,10 +351,15 @@ class DownloadNetworkListener implements NetworkDownloadFileListener { } -export const request : Request = (options : RequestOptions) : RequestTask => { - return NetworkManager.getInstance().request(options, new SimpleNetworkListener(options)); +// export const request : Request = (options : RequestOptions) : RequestTask => { +// return NetworkManager.getInstance().request(options, new SimpleNetworkListener(options)); +// } + +export function request(options : RequestOptions, _t : T.Type) : RequestTask { + return NetworkManager.getInstance().request(options, new SimpleNetworkListener(options)); } + export const uploadFile : UploadFile = (options : UploadFileOptions) : UploadTask => { return NetworkManager.getInstance().uploadFile(options, new UploadNetworkListener(options)); } diff --git a/uni_modules/uni-network/utssdk/app-ios/interface.uts b/uni_modules/uni-network/utssdk/app-ios/interface.uts index 37309cf04844162d9e7412e83165168e204c7a0c..107b8e9d1aab553b7cf81a1904d04a902dfb1479 100644 --- a/uni_modules/uni-network/utssdk/app-ios/interface.uts +++ b/uni_modules/uni-network/utssdk/app-ios/interface.uts @@ -1,10 +1,10 @@ -export type Request = (param: RequestOptions) => RequestTask; +export type Request = (param: RequestOptions) => RequestTask; /** * 网络请求参数 */ -export type RequestOptions = { +export type RequestOptions = { /** * 开发者服务器接口地址 */ @@ -80,7 +80,7 @@ export type RequestOptions = { * 网络请求成功回调。 * @defaultValue null */ - success?: RequestSuccessCallback | null, + success?: RequestSuccessCallback | null, /** * 网络请求失败回调。 * @defaultValue null @@ -93,12 +93,12 @@ export type RequestOptions = { complete?: RequestCompleteCallback | null } -export type RequestSuccess = { +export type RequestSuccess = { /** * 开发者服务器返回的数据 * @type {RequestDataOptions} */ - data: any | null, + data: T | null, /** * 开发者服务器返回的 HTTP 状态码 */ @@ -138,7 +138,7 @@ export type RequestMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD" export type RequestErrorCode = 5 | 1000 | 100001 | 100002 | 600003 | 600009 | 602001; -export type RequestFail = UniError; +// export type RequestFail = UniError; // /** // * 网络请求失败的错误回调参数 // */ @@ -146,8 +146,7 @@ export type RequestFail = UniError; // errCode: RequestErrorCode // }; - -export type RequestSuccessCallback = (option: RequestSuccess) => void; +export type RequestSuccessCallback = (option: RequestSuccess) => void; export type RequestFailCallback = (option: RequestFail) => void; export type RequestCompleteCallback = (option: any) => void; @@ -231,7 +230,7 @@ export type UploadFileSuccess = { statusCode: number }; export type UploadFileSuccessCallback = (result: UploadFileSuccess) => void; -export type UploadFileFail = UniError; +// export type UploadFileFail = UniError; // /** // * 上传文件失败的错误回调参数 // */ @@ -387,7 +386,7 @@ export type DownloadFileSuccess = { statusCode: number }; export type DownloadFileSuccessCallback = (result: DownloadFileSuccess) => void; -export type DownloadFileFail = UniError; +// export type DownloadFileFail = UniError; // /** // * 下载文件失败的错误回调参数 // */ @@ -570,7 +569,7 @@ export interface Uni { }); ``` */ - request: Request, + request(param: RequestOptions): RequestTask; /** * UploadFile() * @description @@ -607,7 +606,7 @@ export interface Uni { }); ``` */ - uploadFile: UploadFile, + uploadFile: UploadFile; /** * DownloadFile() * @description @@ -639,5 +638,5 @@ export interface Uni { }); ``` */ - downloadFile: DownloadFile + downloadFile: DownloadFile; } diff --git a/uni_modules/uni-network/utssdk/app-ios/network/NetworkManager.uts b/uni_modules/uni-network/utssdk/app-ios/network/NetworkManager.uts index fbe465d257751717cf63f74a01d870d5c4d1784b..8a892c6e2f128729a6ca1ecd7fba25cab1cfac81 100644 --- a/uni_modules/uni-network/utssdk/app-ios/network/NetworkManager.uts +++ b/uni_modules/uni-network/utssdk/app-ios/network/NetworkManager.uts @@ -1,8 +1,8 @@ import { RequestOptions, RequestTask, UploadTask, UploadFileOptions, OnProgressUpdateResult, UploadFileProgressUpdateCallback, OnProgressDownloadResult, DownloadTask, DownloadFileOptions, DownloadFileProgressUpdateCallback } from '../interface.uts'; import { UTSiOS } from "DCloudUTSFoundation"; -import { URLSessionDataDelegate, URL, CharacterSet, URLSession, URLSessionConfiguration, OperationQueue, URLSessionTask, URLResponse, URLSessionDataTask, URLAuthenticationChallengeSender, URLAuthenticationChallenge, URLCredential, URLSessionTaskMetrics, Data, HTTPURLResponse, NSError, URLRequest, ComparisonResult } from 'Foundation'; +import { URLSessionDataDelegate, URL, CharacterSet, URLSession, URLSessionConfiguration, OperationQueue, URLSessionTask, URLResponse, URLSessionDataTask, URLAuthenticationChallengeSender, URLAuthenticationChallenge, URLCredential, URLSessionTaskMetrics, Data, HTTPURLResponse, NSError, URLRequest, ComparisonResult } from 'Foundation'; import { UploadController } from './upload/UploadController.uts'; -import { DownloadController } from './download/DownloadController.uts'; +import { DownloadController } from './download/DownloadController.uts'; class NetworkRequestListener { public onStart() : void { } @@ -14,21 +14,21 @@ class NetworkRequestListener { public onFinished(response : HTTPURLResponse) : void { } public onFail(error : NSError) : void { } -} - -interface NetworkUploadFileListener { - progressListeners: Array; - onProgress(progressUpdate: OnProgressUpdateResult): void; - onDataReceived(data : Data) : void; - onFinished(response : HTTPURLResponse) : void; - onFail(error : NSError) : void; -} - -interface NetworkDownloadFileListener { +} + +interface NetworkUploadFileListener { + progressListeners : Array; + onProgress(progressUpdate : OnProgressUpdateResult) : void; + onDataReceived(data : Data) : void; + onFinished(response : HTTPURLResponse) : void; + onFail(error : NSError) : void; +} + +interface NetworkDownloadFileListener { options : DownloadFileOptions | null; - progressListeners: Array; - onProgress(progressUpdate: OnProgressDownloadResult): void; - onFinished(response : HTTPURLResponse, filePath: string) : void; + progressListeners : Array; + onProgress(progressUpdate : OnProgressDownloadResult) : void; + onFinished(response : HTTPURLResponse, filePath : string) : void; onFail(error : NSError) : void; } @@ -60,7 +60,7 @@ class NetworkManager implements URLSessionDataDelegate { } - public request(param : RequestOptions, listener : NetworkRequestListener) : RequestTask { + public request(param : RequestOptions, listener : NetworkRequestListener) : RequestTask { let request = this.createRequest(param); if (request == null) { let error = new NSError(domain = "invalid URL", code = 600009); @@ -80,19 +80,20 @@ class NetworkManager implements URLSessionDataDelegate { } let requestTask = new NetworkRequestTaskImpl(task); return requestTask; - } - - public uploadFile(options: UploadFileOptions, listener: NetworkUploadFileListener): UploadTask { - return UploadController.getInstance().uploadFile(options, listener); - } - - public downloadFile(options: DownloadFileOptions, listener: NetworkDownloadFileListener): DownloadTask { - return DownloadController.getInstance().downloadFile(options, listener); + } + + public uploadFile(options : UploadFileOptions, listener : NetworkUploadFileListener) : UploadTask { + return UploadController.getInstance().uploadFile(options, listener); + } + + public downloadFile(options : DownloadFileOptions, listener : NetworkDownloadFileListener) : DownloadTask { + return DownloadController.getInstance().downloadFile(options, listener); } - public createRequest(param : RequestOptions) : URLRequest | null { - let url = new URL(string = param.url); + public createRequest(param : RequestOptions) : URLRequest | null { + const encodeUrl = this.percentEscapedString(param.url) + let url = new URL(string = encodeUrl); if (url == null) { return null } @@ -120,17 +121,19 @@ class NetworkManager implements URLSessionDataDelegate { let hasContentType = false; if (headers != null) { for (entry in headers!) { - let key = entry.key; + let key = entry.key; let value = entry.value; if (key.caseInsensitiveCompare("Content-Type") == ComparisonResult.orderedSame) { hasContentType = true; } - let valueStr = ""; - if (value instanceof UTSJSONObject) { - valueStr = JSON.stringify(value) ?? "" - }else{ - valueStr = `${value}` - } + let valueStr = ""; + if (value instanceof UTSJSONObject) { + valueStr = JSON.stringify(value) ?? "" + } else if (value instanceof Map) { + valueStr = JSON.stringify(new UTSJSONObject(value)) ?? "" + } else { + valueStr = `${value}` + } request.setValue(valueStr, forHTTPHeaderField = key); } } @@ -139,7 +142,7 @@ class NetworkManager implements URLSessionDataDelegate { if ("GET" != method) { request.setValue("application/json", forHTTPHeaderField = "Content-Type"); } - } + } if ("GET" == method) { const data = param.data; if (data != null) { @@ -148,10 +151,12 @@ class NetworkManager implements URLSessionDataDelegate { json = JSON.parseObject(data as string); } else if (data instanceof UTSJSONObject) { json = data as UTSJSONObject; - } + } else if (data instanceof Map) { + json = new UTSJSONObject(data!) + } if (json != null) { - let urlStr = param.url; - let url = new URL(string = this.stringifyQuery(urlStr!, json!)); + let urlWithQuery = this.stringifyQuery(encodeUrl, json!) + let url = new URL(string = urlWithQuery); request.url = url; } } @@ -159,6 +164,23 @@ class NetworkManager implements URLSessionDataDelegate { let bodyData : Data | null = null; if (typeof (param.data) == 'string') { bodyData = (param.data as string).data(using = String.Encoding.utf8); + } else if (param.data instanceof Map) { + let body : string | null = ""; + const contentType = request.value(forHTTPHeaderField = "Content-Type") + const data = new UTSJSONObject(param.data!); + if (contentType != null) { + if (contentType!.indexOf("application/x-www-form-urlencoded") == 0) { + const map : Map = data.toMap(); + const bodyArray = new Array(); + map.forEach((value, key) => { + bodyArray.push(key + "=" + `${value ?? "null"}`); + }) + body = bodyArray.join("&"); + } else { + body = JSON.stringify(data); + } + bodyData = body?.data(using = String.Encoding.utf8); + } } else if (param.data instanceof UTSJSONObject) { let body : string | null = ""; const contentType = request.value(forHTTPHeaderField = "Content-Type") @@ -206,39 +228,46 @@ class NetworkManager implements URLSessionDataDelegate { newUrl = str[0] // http:xxx/xxx const pairs = query.split('&') const queryMap = new Map(); - pairs.forEach((item: string, index: number) => { + pairs.forEach((item : string, index : number) => { const temp = item.split('=') if (temp.length > 1) { queryMap[temp[0]] = temp[1] } }); const dataMap : Map = data.toMap(); - dataMap.forEach((value, key) => { - if(value == null){ - value = ""; - } - let encodeKey = encodeURIComponent(key)! - if (value instanceof UTSJSONObject || value instanceof Array){ - queryMap[encodeKey] = encodeURIComponent(JSON.stringify(value)!)! - }else{ - queryMap[encodeKey] = encodeURIComponent(`${value!}`)!; + dataMap.forEach((value, key) => { + if (value == null) { + value = ""; + } + let encodeKey = encodeURIComponent(key)! + if (value instanceof UTSJSONObject || value instanceof Array) { + queryMap[encodeKey] = encodeURIComponent(JSON.stringify(value)!)! + } else if (value instanceof Map) { + queryMap[encodeKey] = encodeURIComponent(JSON.stringify(new UTSJSONObject(value))!)! + } else { + queryMap[encodeKey] = encodeURIComponent(`${value!}`)!; } }) let queryStr = ""; queryMap.forEach((value, key) => { queryStr += key + "=" + value + "&" - }); - + }); + queryStr = queryStr.slice(0, -1); if (queryStr.length > 0) { newUrl += "?" + queryStr; } if (hash.length > 0) { newUrl += "#" + hash; - } + } return newUrl; } + private percentEscapedString(str : string) : string { + //如果url已经有部分经过encode,那么需要先decode再encode。 + return str.removingPercentEncoding?.addingPercentEncoding(withAllowedCharacters = CharacterSet.urlQueryAllowed) ?? str + } + //mark --- URLSessionDataDelegate @@ -281,7 +310,7 @@ class NetworkManager implements URLSessionDataDelegate { export { NetworkManager, - NetworkRequestListener, - NetworkUploadFileListener, + NetworkRequestListener, + NetworkUploadFileListener, NetworkDownloadFileListener } \ No newline at end of file diff --git a/uni_modules/uni-network/utssdk/app-ios/network/download/DownloadController.uts b/uni_modules/uni-network/utssdk/app-ios/network/download/DownloadController.uts index 82e9f973458e5cd877e0cc7147c73e15af04b398..a93e66f57a174a69aa58a52493b10a87af281a4e 100644 --- a/uni_modules/uni-network/utssdk/app-ios/network/download/DownloadController.uts +++ b/uni_modules/uni-network/utssdk/app-ios/network/download/DownloadController.uts @@ -1,6 +1,6 @@ import { DownloadFileOptions, DownloadTask, DownloadFileProgressUpdateCallback, OnProgressDownloadResult } from '../../interface.uts'; import { NetworkDownloadFileListener } from '../NetworkManager.uts'; -import { UUID, Data, URL, URLResourceKey, URLSessionDataTask, URLSessionTask, URLSession, URLSessionConfiguration, OperationQueue, URLSessionDataDelegate, URLSessionDownloadTask, NSError, URLSessionDownloadDelegate, URLRequest, FileManager, NSString, NSTemporaryDirectory, NSHomeDirectory } from 'Foundation'; +import { UUID, Data, URL, URLResourceKey, URLSessionDataTask, URLSessionTask, URLSession, URLSessionConfiguration, OperationQueue, URLSessionDataDelegate, URLSessionDownloadTask, NSError, URLSessionDownloadDelegate, URLRequest, FileManager, NSString, NSTemporaryDirectory, NSHomeDirectory , CharacterSet } from 'Foundation'; import { } from 'CommonCrypto'; import { UnsafeBufferPointer, UnsafeRawBufferPointer } from 'Swift'; import { ObjCBool } from "ObjectiveC"; @@ -63,10 +63,11 @@ export class DownloadController implements URLSessionDownloadDelegate { let requestTask = new NetworkDownloadTaskImpl(task, listener); return requestTask; - } - - private createDownloadRequest(options : DownloadFileOptions, listener : NetworkDownloadFileListener) : URLRequest | null { - let url = new URL(string = options.url); + } + + private createDownloadRequest(options : DownloadFileOptions, listener : NetworkDownloadFileListener) : URLRequest | null { + const encodeUrl = this.percentEscapedString(options.url) + let url = new URL(string = encodeUrl); if (url == null) { let error = new NSError(domain = "invalid URL", code = 600009); listener.onFail(error); @@ -90,6 +91,8 @@ export class DownloadController implements URLSessionDownloadDelegate { let valueStr = ""; if (value instanceof UTSJSONObject) { valueStr = JSON.stringify(value) ?? "" + }else if(value instanceof Map){ + valueStr = JSON.stringify(new UTSJSONObject(value)) ?? "" }else{ valueStr = `${value}` } @@ -97,6 +100,11 @@ export class DownloadController implements URLSessionDownloadDelegate { } } return request; + } + + private percentEscapedString(str: string): string { + //如果url已经有部分经过encode,那么需要先decode再encode。 + return str.removingPercentEncoding?.addingPercentEncoding(withAllowedCharacters= CharacterSet.urlQueryAllowed) ?? str } private convertToMD5(param : string) : string { diff --git a/uni_modules/uni-network/utssdk/app-ios/network/upload/UploadController.uts b/uni_modules/uni-network/utssdk/app-ios/network/upload/UploadController.uts index 70186f4f40dca518456902b45b3a1124fd3cd62d..a4a548e042796b6c91b57ff746df27c8cf93400c 100644 --- a/uni_modules/uni-network/utssdk/app-ios/network/upload/UploadController.uts +++ b/uni_modules/uni-network/utssdk/app-ios/network/upload/UploadController.uts @@ -67,8 +67,9 @@ class UploadController implements URLSessionDataDelegate { } - private createRequest(param : UploadFileOptions, listener : NetworkUploadFileListener, boundary : string) : URLRequest | null { - let url = new URL(string = param.url); + private createRequest(param : UploadFileOptions, listener : NetworkUploadFileListener, boundary : string) : URLRequest | null { + const encodeUrl = this.percentEscapedString(param.url) + let url = new URL(string = encodeUrl); if (url == null) { let error = new NSError(domain = "invalid URL", code = 600009); listener.onFail(error); @@ -96,6 +97,8 @@ class UploadController implements URLSessionDataDelegate { let valueStr = ""; if (value instanceof UTSJSONObject) { valueStr = JSON.stringify(value) ?? "" + }else if(value instanceof Map){ + valueStr = JSON.stringify(new UTSJSONObject(value)) ?? "" }else{ valueStr = `${value}` } @@ -118,6 +121,11 @@ class UploadController implements URLSessionDataDelegate { if (valueStr != null) { this.fillTextPart(body, boundary, key, valueStr as string) } + }else if(value instanceof Map){ + let valueStr = JSON.stringify(new UTSJSONObject(value)) + if (valueStr != null) { + this.fillTextPart(body, boundary, key, valueStr as string) + } }else{ this.fillTextPart(body, boundary, key, `${value}`) } @@ -154,6 +162,12 @@ class UploadController implements URLSessionDataDelegate { body.append(`--${boundary}--\r\n`.data(using = String.Encoding.utf8)!) return body.copy() as Data; + } + + + private percentEscapedString(str: string): string { + //如果url已经有部分经过encode,那么需要先decode再encode。 + return str.removingPercentEncoding?.addingPercentEncoding(withAllowedCharacters= CharacterSet.urlQueryAllowed) ?? str } diff --git a/uni_modules/uni-network/utssdk/interface.uts b/uni_modules/uni-network/utssdk/interface.uts index f54d17f6f73a853a23c81af7e917e97b63838469..32137befee2b9ae5583ebd5584f1cc5cb93d4939 100644 --- a/uni_modules/uni-network/utssdk/interface.uts +++ b/uni_modules/uni-network/utssdk/interface.uts @@ -6,17 +6,75 @@ export type Request = (param: RequestOptions) => RequestTask; export type RequestOptions = { /** * 开发者服务器接口地址 + * + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } */ url: string, /** * 请求的参数 UTSJSONObject|string类型 * @type {RequestDataOptions} * @defaultValue null + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } */ data?: any | null, /** * 设置请求的 header,header 中不能设置 Referer * @defaultValue null + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } */ header?: UTSJSONObject | null, /** @@ -24,11 +82,45 @@ export type RequestOptions = { * 如果设置的值不在取值范围内,会以GET方法进行请求。 * @type {RequestMethod} * @defaultValue "GET" + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } */ method?: RequestMethod | null, /** * 超时时间,单位 ms * @defaultValue 60000 + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * } + * } */ timeout?: number | null, /** @@ -69,16 +161,35 @@ export type RequestOptions = { * "unixVer": "x" * } * }, - * "web": { - * "uniVer": "√", - * "unixVer": "4.0" - * } + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } * } */ withCredentials?: boolean | null, /** * DNS解析时优先使用ipv4 * @defaultValue false + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "x" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "x" + * } + * }, + * "web": { + * "uniVer": "x", + * "unixVer": "x" + * } + * } */ firstIpv4?: boolean | null, /** @@ -102,18 +213,94 @@ export type RequestSuccess = { /** * 开发者服务器返回的数据 * @type {RequestDataOptions} + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } */ data: T | null, /** * 开发者服务器返回的 HTTP 状态码 + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } */ statusCode: number, /** * 开发者服务器返回的 HTTP Response Header + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } */ header: any, /** * 开发者服务器返回的 cookies,格式为字符串数组 + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "x", + * "unixVer": "x" + * } + * } */ cookies: Array } @@ -174,10 +361,10 @@ export interface RequestTask { * "unixVer": "4.11" * } * }, - * "web": { - * "uniVer": "√", - * "unixVer": "4.0" - * } + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } * } * @example ```typescript @@ -199,10 +386,48 @@ export type UploadFileOptionFiles = { /** * multipart 提交时,表单的项目名,默认为 file,如果 name 不填或填的值相同,可能导致服务端读取文件时只能读取到一个文件。 * @defaultValue "file" + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } */ name?: string | null, /** * 要上传文件资源的路径 + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "x", + * "unixVer": "x" + * } + * } */ uri: string, /** @@ -221,10 +446,10 @@ export type UploadFileOptionFiles = { * "unixVer": "4.11" * } * }, - * "web": { - * "uniVer": "√", - * "unixVer": "4.0" - * } + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } * } */ file?: any | null @@ -232,10 +457,48 @@ export type UploadFileOptionFiles = { export type UploadFileSuccess = { /** * 开发者服务器返回的数据 + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } */ data: string, /** * 开发者服务器返回的 HTTP 状态码 + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } */ statusCode: number }; @@ -252,36 +515,169 @@ export type UploadFileCompleteCallback = (result: any) => void; export type UploadFileOptions = { /** * 开发者服务器 url + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } */ url: string, /** * 要上传文件资源的路径, 支持uni.env * @defaultValue null + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } */ filePath?: string | null, /** * 文件对应的 key , 开发者在服务器端通过这个 key 可以获取到文件二进制内容 * @defaultValue null + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } */ name?: string | null, /** * 需要上传的文件列表。 * @defaultValue null + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } */ files?: (UploadFileOptionFiles[]) | null, /** * HTTP 请求 Header, header 中不能设置 Referer * @defaultValue null + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } */ header?: UTSJSONObject | null, /** * HTTP 请求中其他额外的 form data * @defaultValue null + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } */ formData?: UTSJSONObject | null, /** * 超时时间,单位 ms * @defaultValue 120000 + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } */ timeout?: number | null, /** @@ -303,14 +699,71 @@ export type UploadFileOptions = { export type OnProgressUpdateResult = { /** * 上传进度百分比 + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } */ progress: number, /** * 已经上传的数据长度,单位 Bytes + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } */ totalBytesSent: number, /** * 预期需要上传的数据总长度,单位 Bytes + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } */ totalBytesExpectedToSend: number }; @@ -338,10 +791,10 @@ export interface UploadTask { * "unixVer": "4.11" * } * }, - * "web": { - * "uniVer": "√", - * "unixVer": "4.0" - * } + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } * } * @example ```typescript @@ -374,10 +827,10 @@ export interface UploadTask { * "unixVer": "4.11" * } * }, - * "web": { - * "uniVer": "√", - * "unixVer": "4.0" - * } + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } * } * @example ```typescript @@ -397,10 +850,48 @@ export type DownloadFile = (options: DownloadFileOptions) => DownloadTask; export type DownloadFileSuccess = { /** * 临时文件路径,下载后的文件会存储到一个临时文件 + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } */ tempFilePath: string, /** * 开发者服务器返回的 HTTP 状态码 + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } */ statusCode: number }; @@ -417,11 +908,45 @@ export type DownloadFileCompleteCallback = (result: DownloadFileComplete) => voi export type DownloadFileOptions = { /** * 下载资源的 url + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } */ url: string, /** * HTTP 请求 Header,header 中不能设置 Referer * @defaultValue null + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * } + * } */ header?: UTSJSONObject | null, /** @@ -432,11 +957,49 @@ export type DownloadFileOptions = { * `/imgs/` * 支持uni.env的平台兼容性:Android自3.9开始支持uni.env,iOS自4.13开始支持uni.env * @defaultValue null + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } */ filePath?: string | null, /** * 超时时间,单位 ms * @defaultValue 120000 + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } */ timeout?: number | null, /** @@ -458,14 +1021,71 @@ export type DownloadFileOptions = { export type OnProgressDownloadResult = { /** * 下载进度百分比 + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } */ progress: number, /** * 已经下载的数据长度,单位 Bytes + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } */ totalBytesWritten: number, /** * 预期需要下载的数据总长度,单位 Bytes + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } */ totalBytesExpectedToWrite: number }; @@ -492,10 +1112,10 @@ export interface DownloadTask { * "unixVer": "4.11" * } * }, - * "web": { - * "uniVer": "√", - * "unixVer": "4.0" - * } + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } * } * @example ```typescript @@ -528,10 +1148,10 @@ export interface DownloadTask { * "unixVer": "4.11" * } * }, - * "web": { - * "uniVer": "√", - * "unixVer": "4.0" - * } + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } * } * @example ```typescript @@ -568,10 +1188,10 @@ export interface Uni { * "unixVer": "4.11" * } * }, - * "web": { - * "uniVer": "√", - * "unixVer": "4.0" - * } + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } * } * @example ```typescript @@ -624,10 +1244,10 @@ export interface Uni { * "unixVer": "4.11" * } * }, - * "web": { - * "uniVer": "√", - * "unixVer": "4.0" - * } + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } * } * @example ```typescript @@ -666,10 +1286,10 @@ export interface Uni { * "unixVer": "4.11" * } * }, - * "web": { - * "uniVer": "√", - * "unixVer": "4.0" - * } + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } * } * @example ```typescript diff --git a/uni_modules/uni-payment-alipay/utssdk/app-android/Alipay.uts b/uni_modules/uni-payment-alipay/utssdk/app-android/Alipay.uts index 650dc10baece1de55207b4d10f4f1b1ca70ca2a8..353650359ffa3313eeacc70a82f3ef53050fb45c 100644 --- a/uni_modules/uni-payment-alipay/utssdk/app-android/Alipay.uts +++ b/uni_modules/uni-payment-alipay/utssdk/app-android/Alipay.uts @@ -1,13 +1,13 @@ import PayTask from 'com.alipay.sdk.app.PayTask'; import string from 'android.R.string'; -const defaultErrorCode : number = 700716 +const defaultErrorCode : number = 700000 const errorCodeMap : Map = new Map([ - [8000, 700710], - [4000, 700711], - [5000, 700712], - [6001, 700713], - [6002, 700714], - [6004, 700715] + [8000, 700600], + [4000, 701100], + [5000, 701110], + [6001, 700601], + [6002, 700602], + [6004, 700603] ]) export class Alipay { public requestPayment(options : RequestPaymentOptions) { diff --git a/uni_modules/uni-payment-alipay/utssdk/app-android/index.uts b/uni_modules/uni-payment-alipay/utssdk/app-android/index.uts index 6826b8dbcc2270f458258d25eafc5aea4e603fb0..efeda19ed173f28eee6b12e376c2d45380bbf404 100644 --- a/uni_modules/uni-payment-alipay/utssdk/app-android/index.uts +++ b/uni_modules/uni-payment-alipay/utssdk/app-android/index.uts @@ -1,4 +1,11 @@ -import { Alipay } from './Alipay.uts' -export const requestPayment : RequestPayment = function (options : RequestPaymentOptions) { - new Alipay().requestPayment(options) -}; \ No newline at end of file +import { Alipay } from './Alipay.uts' + +export class UniPaymentAlipayProvider implements UniPaymentProvider { + override id : String = "alipay" + override description : String = "Alipay" + override isAppExist : boolean | null = null + + override requestPayment(options : RequestPaymentOptions) { + new Alipay().requestPayment(options) + } +} diff --git a/uni_modules/uni-payment-alipay/utssdk/app-ios/config.json b/uni_modules/uni-payment-alipay/utssdk/app-ios/config.json index 25eb4ef311a538f0457ada60afcbb082ea48ed75..7148fc57181e9520eaa4559cde3e07581f32aafc 100644 --- a/uni_modules/uni-payment-alipay/utssdk/app-ios/config.json +++ b/uni_modules/uni-payment-alipay/utssdk/app-ios/config.json @@ -1,17 +1,37 @@ -{ - "frameworks": [ - "libc++.tbd", - "libz.tbd", - "SystemConfiguration.framework", - "CoreTelephony.framework", - "QuartzCore.framework", - "CoreText.framework", - "CoreGraphics.framework", - "UIKit.framework", - "Foundation.framework", - "CFNetwork.framework", - "CoreMotion.framework" - ], - "deploymentTarget": "12.0" -} - +{ + "frameworks": [ + "libc++.tbd", + "libz.tbd", + "SystemConfiguration.framework", + "CoreTelephony.framework", + "QuartzCore.framework", + "CoreText.framework", + "CoreGraphics.framework", + "UIKit.framework", + "Foundation.framework", + "CFNetwork.framework", + "CoreMotion.framework" + ], + "deploymentTarget": "12.0", + "parameters": { + "universalLink": { + "des": "请填写能唤起当前应用的Universal Links路径(https开头,以“/”结尾,建议带path,比如“https://your_domain/app/”),在实际调用SDK时,会校验Universal Links是否匹配" + } + }, + "plists": { + "CFBundleURLTypes": [{ + "CFBundleTypeRole": "Editor", + "CFBundleURLName": "Alipay", + "CFBundleURLSchemes": [ + "alipay{$_dcloud_appid_md5}" + ] + }], + "LSApplicationQueriesSchemes": [ + "alipay", + "safepay" + ], + "Alipay": { + "universalLink": "{$universalLink}" + } + } +} \ No newline at end of file diff --git a/uni_modules/uni-payment-alipay/utssdk/app-ios/index.uts b/uni_modules/uni-payment-alipay/utssdk/app-ios/index.uts index 4015a64e0e30f780b78e2eee90bbe01d87d8b7b1..5a5cebbc38cb5a5ae8e136439b95a2cceb947222 100644 --- a/uni_modules/uni-payment-alipay/utssdk/app-ios/index.uts +++ b/uni_modules/uni-payment-alipay/utssdk/app-ios/index.uts @@ -1,5 +1,149 @@ -import { Alipay } from './Alipay.uts' +import { UTSiOSHookProxy } from "DCloudUniappRuntime"; +import { UIApplication } from "UIKit" +import { AlipaySDK } from "AlipaySDK" assert { type: "implementationOnly" }; +import { URL, NSUserActivity, NSUserActivityTypeBrowsingWeb, Bundle } from "Foundation" -export const requestPayment : RequestPayment = function (options : RequestPaymentOptions) { - new Alipay().requestPayment(options) -}; \ No newline at end of file +const defaultErrorCode : number = 700000; + +const errorCodeMap : Map = new Map([ + ['8000', 700600], + ['4000', 701100], + ['5000', 701110], + ['6001', 700601], + ['6002', 700602], + ['6004', 700603] +]); + +export class UniPaymentAlipayProvider implements UniPaymentProvider { + + id: string + + override description: string = "Alipay" + + isAppExist: boolean + + requestPayment(options : RequestPaymentOptions) { + Alipay.requestPayment(options) + } + + constructor() { + this.id = "alipay" + this.isAppExist = true + } +} + + +export class AlipayHookProxy implements UTSiOSHookProxy { + + // 通过 url scheme 方式唤起 app 时的回调函数。 + applicationOpenURLOptions(app : UIApplication | null, url : URL, options : Map | null = null) : boolean { + // this.processOrder(url) + Alipay.share.processOrder(url) + return true + } + + // 当应用程序接收到与用户活动相关的数据时调用此方法,例如,当用户使用 Universal Link 唤起应用时。 + applicationContinueUserActivityRestorationHandler(application : UIApplication | null, userActivity : NSUserActivity | null, restorationHandler : ((res : [any] | null) => void) | null = null) : boolean { + Alipay.share.handleOpenUniversalLink(userActivity) + return true + } +} + +export class Alipay { + static share = new Alipay() + + private options ?: RequestPaymentOptions + + static requestPayment(options : RequestPaymentOptions) { + Alipay.share.options = options + if (Alipay.share.getApplicationScheme() == null) { + let err = new RequestPaymentFailImpl(700800); + Alipay.share.options?.fail?.(err) + Alipay.share.options?.complete?.(err) + return + } + Alipay.share.payOrder() + } + + @UTSiOS.keyword("fileprivate") + processOrder(url : URL) { + if (url.host == 'safepay') { + AlipaySDK.defaultService().processOrder(withPaymentResult = url, standbyCallback = (resultDic ?: Map) : void => { + this.handlePaymentResult(resultDic) + }) + } + } + + @UTSiOS.keyword("fileprivate") + handleOpenUniversalLink(userActivity : NSUserActivity | null) { + if (userActivity?.activityType == NSUserActivityTypeBrowsingWeb) { + AlipaySDK.defaultService().handleOpenUniversalLink(userActivity, standbyCallback = (resultDic ?: Map) : void => { + this.handlePaymentResult(resultDic) + }) + } + } + + private payOrder() { + AlipaySDK.defaultService().payOrder(this.options?.orderInfo, fromScheme = this.getApplicationScheme(), fromUniversalLink = this.getApplicationUniversalLink(), callback = (resultDic ?: Map) : void => { + this.handlePaymentResult(resultDic) + }) + } + + private getApplicationScheme() : string | null { + let scheme : string | null = null + const infoDictionary = Bundle.main.infoDictionary + if (infoDictionary != null) { + const bundleURLTypes = infoDictionary!['CFBundleURLTypes'] as Map[] | null + if (bundleURLTypes != null) { + bundleURLTypes!.forEach((value, key) => { + const urlIdentifier = value['CFBundleURLName'] as string | null + if (urlIdentifier != null && urlIdentifier!.toLowerCase() == "alipay") { + const urlSchemes = value['CFBundleURLSchemes'] as string[] + scheme = urlSchemes[0] + } + }) + } + } + return scheme + } + + private getApplicationUniversalLink() : string | null { + let universalLink : string | null = null + const infoDictionary = Bundle.main.infoDictionary + if (infoDictionary != null) { + const alipay = infoDictionary!['Alipay'] as Map | null + if (alipay != null) { + universalLink = alipay!['universalLink'] as string | null + } + } + return universalLink + } + + private handlePaymentResult(resultDic ?: Map) { + let resultStatus : string = '' + if (resultDic == null) { + resultStatus = defaultErrorCode.toString() + } else { + resultStatus = resultDic!.get("resultStatus") as string + if (resultStatus == null) { + resultStatus = defaultErrorCode.toString() + } + } + + if (resultStatus == "9000") { + let res : RequestPaymentSuccess = { + data: resultDic + } + Alipay.share.options?.success?.(res) + Alipay.share.options?.complete?.(res) + } else { + let code = errorCodeMap[resultStatus]; + if (code == null) { + code = defaultErrorCode + } + let err = new RequestPaymentFailImpl(code!); + Alipay.share.options?.fail?.(err) + Alipay.share.options?.complete?.(err) + } + } +} \ No newline at end of file diff --git a/uni_modules/uni-payment-wxpay/utssdk/app-android/index.uts b/uni_modules/uni-payment-wxpay/utssdk/app-android/index.uts index a12df613614098a54166dce55d4782367d731795..f52fd13f6fd3317b212d3dfcd4c70108041db8ed 100644 --- a/uni_modules/uni-payment-wxpay/utssdk/app-android/index.uts +++ b/uni_modules/uni-payment-wxpay/utssdk/app-android/index.uts @@ -1,5 +1,26 @@ import { Wxpay } from "./src/Wxpay"; +import PackageManager from 'android.content.pm.PackageManager'; export * from './src/WXPayEntryActivity.uts' -export const requestPayment : RequestPayment = function (options : RequestPaymentOptions) { - new Wxpay().requestPayment(options) -}; \ No newline at end of file +export class UniPaymentWxpayProvider implements UniPaymentProvider { + override id : String = "wxpay" + override description : String = "wechat" + override isAppExist : boolean | null = null + + override requestPayment(options : RequestPaymentOptions) { + new Wxpay().requestPayment(options) + } + constructor() { + this.isAppExist = this.isWeChatInstalled() + } + isWeChatInstalled() : boolean { + let pm = UTSAndroid.getAppContext()?.getPackageManager(); + let app_installed : Boolean; + try { + pm?.getPackageInfo("com.tencent.mm", PackageManager.GET_ACTIVITIES); + app_installed = true; + } catch (e : PackageManager.NameNotFoundException) { + app_installed = false; + } + return app_installed; + } +} \ No newline at end of file diff --git a/uni_modules/uni-payment-wxpay/utssdk/app-android/src/WXPayEntryActivity.uts b/uni_modules/uni-payment-wxpay/utssdk/app-android/src/WXPayEntryActivity.uts index 59838e098773d6fe76a6a36280509f30ba8a5f6b..149c7d570183331e2b86e2b55b9a1c122dd79b80 100644 --- a/uni_modules/uni-payment-wxpay/utssdk/app-android/src/WXPayEntryActivity.uts +++ b/uni_modules/uni-payment-wxpay/utssdk/app-android/src/WXPayEntryActivity.uts @@ -7,10 +7,10 @@ import Bundle from 'android.os.Bundle' import WXAPIFactory from 'com.tencent.mm.opensdk.openapi.WXAPIFactory'; import {Wxpay} from './Wxpay'; import R from 'uts.sdk.modules.uniPaymentWxpay.R'; -const defaultErrorCode : number = 700716 +const defaultErrorCode : number = 700000 const errorCodeMap : Map = new Map([ - [-1, 700711], - [-2, 700713] + [-1, 701100], + [-2, 700601] ]) export class WXPayEntryActivity extends Activity implements IWXAPIEventHandler { constructor() { diff --git a/uni_modules/uni-payment-wxpay/utssdk/app-android/src/Wxpay.uts b/uni_modules/uni-payment-wxpay/utssdk/app-android/src/Wxpay.uts index 2eff27a35d315e4b6d7dde9a679c2410a7311d14..2303ac2c7ed234aa34467766dc30740692b650e6 100644 --- a/uni_modules/uni-payment-wxpay/utssdk/app-android/src/Wxpay.uts +++ b/uni_modules/uni-payment-wxpay/utssdk/app-android/src/Wxpay.uts @@ -2,7 +2,7 @@ import IWXAPI from 'com.tencent.mm.opensdk.openapi.IWXAPI'; import WXAPIFactory from 'com.tencent.mm.opensdk.openapi.WXAPIFactory'; import PayReq from 'com.tencent.mm.opensdk.modelpay.PayReq'; import BaseReq from 'com.tencent.mm.opensdk.modelbase.BaseReq'; -const defaultErrorCode : number = 700716 +const defaultErrorCode : number = 700000 export class Wxpay { public static mOptions : RequestPaymentOptions = { orderInfo: "", @@ -10,7 +10,7 @@ export class Wxpay { } as RequestPaymentOptions public requestPayment(options : RequestPaymentOptions) { if (!Wxpay.isInstalled()) { - let err = new RequestPaymentFailImpl(700717); + let err = new RequestPaymentFailImpl(700604); options.fail?.(err) options.complete?.(err) return diff --git a/uni_modules/uni-payment-wxpay/utssdk/app-ios/Libs/WeChatSDK/README.txt b/uni_modules/uni-payment-wxpay/utssdk/app-ios/Libs/WeChatSDK/README.txt new file mode 100644 index 0000000000000000000000000000000000000000..862fe91bb0ea2d3f3ac0d251be8c9777aad15d8d --- /dev/null +++ b/uni_modules/uni-payment-wxpay/utssdk/app-ios/Libs/WeChatSDK/README.txt @@ -0,0 +1,163 @@ +重要! +SDK2.0.4 +1.增加privacy manifest文件 +2.修复跳微信时可能卡顿的问题 + +SDK2.0.2 +1. 优化XCFramework打包方式 + +SDK2.0.1 +1. SDK支持XCFramework + +SDK2.0.0 +1. 分享能力支持内容防篡改校验 + +SDK1.9.9 +1. 授权登录支持关闭自动授权 +2. 分享支持添加签名,防止篡改 + +SDK1.9.7 +1. 适配CocoaPods + +SDK1.9.6 +1. 适配iOS 16,减少读写剪切板 + +SDK1.9.4 +1. 修复授权登录取消/拒绝时state字段没有带回 + +SDK1.9.3 +1. 新增发起二维码支付能力 + +SDK1.9.2 +1. 新增发起企微客服会话能力 + +SDK1.9.1 +1. 音乐视频分享类型增加运营H5字段 + +SDK1.8.9 +1. 增加音乐视频分享类型 + +SDK1.8.8 +1. 增加游戏直播消息类型 + +SDK1.8.7.1 +1. 修复Xcode11以下编译不通过 + +SDK1.8.7 +1. 修复iPadOS,未安装微信的情况下,因为UA问题无法授权登录 +2. 修复未安装微信的情况下, 适配了UIScene的App因为UIAlertView Crash +3. 增加Universal Link检测函数 + +SDK1.8.6.2 +1. 修改包含"UIWebView"字符的类名 + +SDK1.8.6.1 +1.短信授权登录使用的UIWebview切换成WKWebview + +SDK1.8.6 +1. 支持Universal Link拉起微信以及返回App +2. SDK移除MTA库 + +SDK1.8.5 +1. 更换MTA库:取消对剪切板的访问, 防止和其他SDK竞争导致crash +2. NSMutableArray的MTA分类方法改名,减少命名冲突 +3. 不含支付功能版本移除非税支付和医保支付接口 +4. 分享音乐支持填写歌词和高清封面图 + +SDK1.8.4 +1. 调整分享图片大小限制 +2. 新增openBusinessView接口 + +SDK1.8.3 +1. SDK增加调起微信刷卡支付接口 +2. SDK增加小程序订阅消息接口 +3. 修复小程序订阅消息接口没有resp的问题 + +SDK1.8.2 +1. SDK增加开发票授权 WXInvoiceAuthInsert +2. SDK增加非税接口 WXNontaxPay +3. SDK增加医保接口 WXPayInsurance +4. 更换MTA库 + +SDK1.8.1 +1. SDK打开小程序支持指定版本(体验,开发,正式版) +2. SDK分享小程序支持指定版本(体验,开发,正式版) +3. SDK支持输出log日志 + +SDK1.8.0 +1. SDK支持打开小程序 +2. SDK分享小程序支持shareTicket + +SDK1.7.9 +1. SDK订阅一次性消息 + +SDK1.7.8 +1 SDK分享小程序支持大图 + +SDK1.7.7 +1 增加SDK分享小程序 +2 增加选择发票接口 + +SDK1.7.6 +1. 提高稳定性 +1 修复mta崩溃 +2 新增接口支持开发者关闭mta数据统计上报 + +SDK1.7.5 +1. 提高稳定性 +2. 加快registerApp接口启动速度 + +SDK1.7.4 +1. 更新支持iOS启用 ATS(App Transport Security) +2. 需要在工程中链接CFNetwork.framework +3. 在工程配置中的”Other Linker Flags”中加入”-Objc -all_load” + +SDK1.7.3 +1. 增强稳定性,适配iOS10 +2. 修复小于32K的jpg格式缩略图设置失败的问题 + +SDK1.7.2 +1. 修复因CTTeleponyNetworkInfo引起的崩溃问题 + +SDK1.7.1 +1. 支持兼容ipv6(提升稳定性) +2. xCode Version 7.3.1 (7D1014) 编译 + +SDK1.7 +1. 支持兼容ipv6 +2. 修复若干问题增强稳定性 + +SDK1.6.3 +1. xCode7.2 构建的sdk包。 +2. 请使用xCode7.2进行编译。 +3. 需要在Build Phases中Link Security.framework +4. 修复若干小问题。 + +SDK1.6.2 +1、xCode7.1 构建的sdk包 +2、请使用xCode7.1进行编译 + +SDK1.6.1 +1、修复armv7s下,bitcode可能编译不过 +2、解决warning + +SDK1.6 +1、iOS 9系统策略更新,限制了http协议的访问,此外应用需要在“Info.plist”中将要使用的URL Schemes列为白名单,才可正常检查其他应用是否安装。 +受此影响,当你的应用在iOS 9中需要使用微信SDK的相关能力(分享、收藏、支付、登录等)时,需要在“Info.plist”里增加如下代码: +LSApplicationQueriesSchemes + +weixin + +NSAppTransportSecurity + +NSAllowsArbitraryLoads + + +2、开发者需要在工程中链接上 CoreTelephony.framework +3、解决bitcode编译不过问题 + +SDK1.5 +1、废弃safeSendReq:接口,使用sendReq:即可。 +2、新增+(BOOL) sendAuthReq:(SendAuthReq*) req viewController : (UIViewController*) viewController delegate:(id) delegate; +支持未安装微信情况下Auth,具体见WXApi.h接口描述 +3、微信开放平台新增了微信模块用户统计功能,便于开发者统计微信功能模块的用户使用和活跃情况。开发者需要在工程中链接上:SystemConfiguration.framework,libz.dylib,libsqlite3.0.dylib。 diff --git a/uni_modules/uni-payment-wxpay/utssdk/app-ios/Libs/WeChatSDK/WXApi.h b/uni_modules/uni-payment-wxpay/utssdk/app-ios/Libs/WeChatSDK/WXApi.h new file mode 100644 index 0000000000000000000000000000000000000000..879c505975ed7631ab68e46cc15db531e9d1fba3 --- /dev/null +++ b/uni_modules/uni-payment-wxpay/utssdk/app-ios/Libs/WeChatSDK/WXApi.h @@ -0,0 +1,231 @@ +// +// WXApi.h +// 所有Api接口 +// +// Created by Wechat on 12-2-28. +// Copyright (c) 2012年 Tencent. All rights reserved. +// + +#import +#import "WXApiObject.h" + +NS_ASSUME_NONNULL_BEGIN + + +typedef BOOL(^WXGrantReadPasteBoardPermissionCompletion)(void); + + +#pragma mark - WXApiDelegate +/*! @brief 接收并处理来自微信终端程序的事件消息 + * + * 接收并处理来自微信终端程序的事件消息,期间微信界面会切换到第三方应用程序。 + * WXApiDelegate 会在handleOpenURL:delegate:中使用并触发。 + */ +@protocol WXApiDelegate +@optional + +/*! @brief 收到一个来自微信的请求,第三方应用程序处理完后调用sendResp向微信发送结果 + * + * 收到一个来自微信的请求,异步处理完成后必须调用sendResp发送处理结果给微信。 + * 可能收到的请求有GetMessageFromWXReq、ShowMessageFromWXReq等。 + * @param req 具体请求内容,是自动释放的 + */ +- (void)onReq:(BaseReq*)req; + + + +/*! @brief 发送一个sendReq后,收到微信的回应 + * + * 收到一个来自微信的处理结果。调用一次sendReq后会收到onResp。 + * 可能收到的处理结果有SendMessageToWXResp、SendAuthResp等。 + * @param resp具体的回应内容,是自动释放的 + */ +- (void)onResp:(BaseResp*)resp; + +/* ! @brief 用于在iOS16以及以上系统上,控制OpenSDK是否读取剪切板中微信传递的数据以及读取的时机 + * 在iOS16以及以上系统,在SDK需要读取剪切板中微信写入的数据时,会回调该方法。没有实现默认会直接读取微信通过剪切板传递过来的数据 + * 注意: + * 1. 只在iOS16以及以上的系统版本上回调; + * 2. 不实现时,OpenSDK会直接调用读取剪切板接口,读取微信传递过来的数据; + * 3. 若实现该方法:开发者需要通过调用completion(), 支持异步,通知SDK允许读取剪切板中微信传递的数据, + * 不调用completion()则代表不授权OpenSDK读取剪切板,会导致收不到onReq:, onResp:回调,无法后续业务流程。请谨慎使用 + * 4. 不要长时间持有completion不释放,可能会导致内存泄漏。 + */ +- (void)onNeedGrantReadPasteBoardPermissionWithURL:(nonnull NSURL *)openURL completion:(nonnull WXGrantReadPasteBoardPermissionCompletion)completion; + +@end + +#pragma mark - WXApiLogDelegate + +@protocol WXApiLogDelegate + +- (void)onLog:(NSString*)log logLevel:(WXLogLevel)level; + +@end + + +#pragma mark - WXApi + +/*! @brief 微信Api接口函数类 + * + * 该类封装了微信终端SDK的所有接口 + */ +@interface WXApi : NSObject + +/*! @brief WXApi的成员函数,向微信终端程序注册第三方应用。 + * + * 需要在每次启动第三方应用程序时调用。 + * @attention 请保证在主线程中调用此函数 + * @param appid 微信开发者ID + * @param universalLink 微信开发者Universal Link + * @return 成功返回YES,失败返回NO。 + */ ++ (BOOL)registerApp:(NSString *)appid universalLink:(NSString *)universalLink; + + +/*! @brief 处理旧版微信通过URL启动App时传递的数据 + * + * 需要在 application:openURL:sourceApplication:annotation:或者application:handleOpenURL中调用。 + * @param url 微信启动第三方应用时传递过来的URL + * @param delegate WXApiDelegate对象,用来接收微信触发的消息。 + * @return 成功返回YES,失败返回NO。 + */ ++ (BOOL)handleOpenURL:(NSURL *)url delegate:(nullable id)delegate; + + +/*! @brief 处理微信通过Universal Link启动App时传递的数据 + * + * 需要在 application:continueUserActivity:restorationHandler:中调用。 + * @param userActivity 微信启动第三方应用时系统API传递过来的userActivity + * @param delegate WXApiDelegate对象,用来接收微信触发的消息。 + * @return 成功返回YES,失败返回NO。 + */ ++ (BOOL)handleOpenUniversalLink:(NSUserActivity *)userActivity delegate:(nullable id)delegate; + + +/*! @brief 检查微信是否已被用户安装 + * + * @return 微信已安装返回YES,未安装返回NO。 + */ ++ (BOOL)isWXAppInstalled; + + + +/*! @brief 判断当前微信的版本是否支持OpenApi + * + * @return 支持返回YES,不支持返回NO。 + */ ++ (BOOL)isWXAppSupportApi; + + +/*! @brief 判断当前微信的版本是否支持分享微信状态功能 + * + * @attention 需在工程LSApplicationQueriesSchemes配置中添加weixinStateAPI + * @return 支持返回YES,不支持返回NO。 + */ ++ (BOOL)isWXAppSupportStateAPI; + + +#ifndef BUILD_WITHOUT_PAY +/*! @brief 判断当前微信的版本是否支持二维码拉起微信支付 + * + * @attention 需在工程LSApplicationQueriesSchemes配置中添加weixinQRCodePayAPI + * @return 支持返回YES,不支持返回NO。 + */ ++ (BOOL)isWXAppSupportQRCodePayAPI; + +#endif + + +/*! @brief 获取微信的itunes安装地址 + * + * @return 微信的安装地址字符串。 + */ ++ (NSString *)getWXAppInstallUrl; + + + +/*! @brief 获取当前微信SDK的版本号 + * + * @return 返回当前微信SDK的版本号 + */ ++ (NSString *)getApiVersion; + + + +/*! @brief 打开微信 + * + * @return 成功返回YES,失败返回NO。 + */ ++ (BOOL)openWXApp; + + + +/*! @brief 发送请求到微信,等待微信返回onResp + * + * 函数调用后,会切换到微信的界面。第三方应用程序等待微信返回onResp。微信在异步处理完成后一定会调用onResp。支持以下类型 + * SendAuthReq、SendMessageToWXReq、PayReq等。 + * @param req 具体的发送请求。 + * @param completion 调用结果回调block + */ ++ (void)sendReq:(BaseReq *)req completion:(void (^ __nullable)(BOOL success))completion; + +/*! @brief 收到微信onReq的请求,发送对应的应答给微信,并切换到微信界面 + * + * 函数调用后,会切换到微信的界面。第三方应用程序收到微信onReq的请求,异步处理该请求,完成后必须调用该函数。可能发送的相应有 + * GetMessageFromWXResp、ShowMessageFromWXResp等。 + * @param resp 具体的应答内容 + * @param completion 调用结果回调block + */ ++ (void)sendResp:(BaseResp*)resp completion:(void (^ __nullable)(BOOL success))completion; + + +/*! @brief 发送Auth请求到微信,支持用户没安装微信,等待微信返回onResp + * + * 函数调用后,会切换到微信的界面。第三方应用程序等待微信返回onResp。微信在异步处理完成后一定会调用onResp。支持SendAuthReq类型。 + * @param req 具体的发送请求。 + * @param viewController 当前界面对象。 + * @param delegate WXApiDelegate对象,用来接收微信触发的消息。 + * @param completion 调用结果回调block + */ ++ (void)sendAuthReq:(SendAuthReq *)req viewController:(UIViewController*)viewController delegate:(nullable id)delegate completion:(void (^ __nullable)(BOOL success))completion; + + +/*! @brief 测试函数,用于排查当前App通过Universal Link方式分享到微信的流程 + 注意1: 调用自检函数之前必须要先调用registerApp:universalLink接口, 并确认调用成功 + 注意2: 自检过程中会有Log产生,可以先调用startLogByLevel函数,根据Log排查问题 + 注意3: 会多次回调block + 注意4: 仅用于新接入SDK时调试使用,请勿在正式环境的调用 + * + * 当completion回调的step为WXULCheckStepFinal时,表示检测通过,Universal Link接入成功 + * @param completion 回调Block + */ ++ (void)checkUniversalLinkReady:(nonnull WXCheckULCompletion)completion; + + +/*! @brief WXApi的成员函数,接受微信的log信息。byBlock + 注意1:SDK会强引用这个block,注意不要导致内存泄漏,注意不要导致内存泄漏 + 注意2:调用过一次startLog by block之后,如果再调用一次任意方式的startLoad,会释放上一次logBlock,不再回调上一个logBlock + * + * @param level 打印log的级别 + * @param logBlock 打印log的回调block + */ + ++ (void)startLogByLevel:(WXLogLevel)level logBlock:(WXLogBolock)logBlock; + +/*! @brief WXApi的成员函数,接受微信的log信息。byDelegate + 注意1:sdk会弱引用这个delegate,这里可加任意对象为代理,不需要与WXApiDelegate同一个对象 + 注意2:调用过一次startLog by delegate之后,再调用一次任意方式的startLoad,不会再回调上一个logDelegate对象 + * @param level 打印log的级别 + * @param logDelegate 打印log的回调代理, + */ ++ (void)startLogByLevel:(WXLogLevel)level logDelegate:(id)logDelegate; + +/*! @brief 停止打印log,会清理block或者delegate为空,释放block + * @param + */ ++ (void)stopLog; + +@end + +NS_ASSUME_NONNULL_END diff --git a/uni_modules/uni-payment-wxpay/utssdk/app-ios/Libs/WeChatSDK/WXApiObject.h b/uni_modules/uni-payment-wxpay/utssdk/app-ios/Libs/WeChatSDK/WXApiObject.h new file mode 100644 index 0000000000000000000000000000000000000000..85b645785dc7339a6ac477282b2e671266d2e00f --- /dev/null +++ b/uni_modules/uni-payment-wxpay/utssdk/app-ios/Libs/WeChatSDK/WXApiObject.h @@ -0,0 +1,1410 @@ +// +// MMApiObject.h +// Api对象,包含所有接口和对象数据定义 +// +// Created by Wechat on 12-2-28. +// Copyright (c) 2012年 Tencent. All rights reserved. +// + +#import +#import + +NS_ASSUME_NONNULL_BEGIN + +/*! @brief 错误码 + * + */ +enum WXErrCode { + WXSuccess = 0, /**< 成功 */ + WXErrCodeCommon = -1, /**< 普通错误类型 */ + WXErrCodeUserCancel = -2, /**< 用户点击取消并返回 */ + WXErrCodeSentFail = -3, /**< 发送失败 */ + WXErrCodeAuthDeny = -4, /**< 授权失败 */ + WXErrCodeUnsupport = -5, /**< 微信不支持 */ +}; + + + +/*! @brief 请求发送场景 + * + */ +enum WXScene { + WXSceneSession = 0, /**< 聊天界面 */ + WXSceneTimeline = 1, /**< 朋友圈 */ + WXSceneFavorite = 2, /**< 收藏 */ + WXSceneSpecifiedSession = 3, /**< 指定联系人 */ + WXSceneState = 4, /**< 状态 */ +}; + + +enum WXAPISupport { + WXAPISupportSession = 0, +}; + + + +/*! @brief 跳转profile类型 + * + */ +enum WXBizProfileType { + WXBizProfileType_Normal = 0, //**< 普通公众号 */ + WXBizProfileType_Device = 1, //**< 硬件公众号 */ +}; + +/*! @brief 分享小程序类型 + * + */ +typedef NS_ENUM(NSUInteger, WXMiniProgramType) { + WXMiniProgramTypeRelease = 0, //**< 正式版 */ + WXMiniProgramTypeTest = 1, //**< 开发版 */ + WXMiniProgramTypePreview = 2, //**< 体验版 */ +}; + +/*! @brief 跳转mp网页类型 + * + */ +enum WXMPWebviewType { + WXMPWebviewType_Ad = 0, /**< 广告网页 **/ +}; + +/*! @brief log的级别 + * + */ +typedef NS_ENUM(NSInteger,WXLogLevel) { + WXLogLevelNormal = 0, // 打印日常的日志 + WXLogLevelDetail = 1, // 打印详细的日志 +}; + + +/*! @brief 打印回调的block + * + */ +typedef void(^WXLogBolock)(NSString *log); + +/*! @brief 微信Universal Link检查函数 (WXApi#checkUniversalLinkReady:),检查步骤枚举值 + * + * WXULCheckStepParams 参数检测 + * WXULCheckStepSystemVersion 当前系统版本检测 + * WXULCheckStepWechatVersion 微信客户端版本检测 + * WXULCheckStepSDKInnerOperation 微信SDK内部操作检测 + * WXULCheckStepLaunchWechat App拉起微信检测 + * WXULCheckStepBackToCurrentApp 由微信返回当前App检测 + * WXULCheckStepFinal 最终结果 + */ +typedef NS_ENUM(NSInteger, WXULCheckStep) +{ + WXULCheckStepParams, + WXULCheckStepSystemVersion, + WXULCheckStepWechatVersion, + WXULCheckStepSDKInnerOperation, + WXULCheckStepLaunchWechat, + WXULCheckStepBackToCurrentApp, + WXULCheckStepFinal, +}; + + +#pragma mark - WXCheckULStepResult + +/*! @brief 该类为微信Universal Link检测函数结果类 +* +*/ +@interface WXCheckULStepResult : NSObject + +/** 是否成功 */ +@property(nonatomic, assign) BOOL success; +/** 当前错误信息 */ +@property(nonatomic, strong) NSString* errorInfo; +/** 修正建议 */ +@property(nonatomic, strong) NSString* suggestion; + +- (instancetype)initWithCheckResult:(BOOL)success errorInfo:(nullable NSString*)errorInfo suggestion:(nullable NSString*)suggestion; + +@end + + +/*! @brief 微信Universal Link检查函数 (WXApi#checkUniversalLinkReady:),回调Block + * + * @param step 当前检测步骤 + * @param result 检测结果 + */ +typedef void(^WXCheckULCompletion)(WXULCheckStep step, WXCheckULStepResult* result); + + +#pragma mark - BaseReq +/*! @brief 该类为微信终端SDK所有请求类的基类 + * + */ +@interface BaseReq : NSObject + +/** 请求类型 */ +@property (nonatomic, assign) int type; +/** 由用户微信号和AppID组成的唯一标识,需要校验微信用户是否换号登录时填写*/ +@property (nonatomic, copy) NSString *openID; + +@end + + + +#pragma mark - BaseResp +/*! @brief 该类为微信终端SDK所有响应类的基类 + * + */ +@interface BaseResp : NSObject +/** 错误码 */ +@property (nonatomic, assign) int errCode; +/** 错误提示字符串 */ +@property (nonatomic, copy) NSString *errStr; +/** 响应类型 */ +@property (nonatomic, assign) int type; + +@end + + + +#pragma mark - WXMediaMessage +@class WXMediaMessage; + +#ifndef BUILD_WITHOUT_PAY + +#pragma mark - PayReq +/*! @brief 第三方向微信终端发起支付的消息结构体 + * + * 第三方向微信终端发起支付的消息结构体,微信终端处理后会向第三方返回处理结果 + * @see PayResp + */ +@interface PayReq : BaseReq + +/** 商家向财付通申请的商家id */ +@property (nonatomic, copy) NSString *partnerId; +/** 预支付订单 */ +@property (nonatomic, copy) NSString *prepayId; +/** 随机串,防重发 */ +@property (nonatomic, copy) NSString *nonceStr; +/** 时间戳,防重发 */ +@property (nonatomic, assign) UInt32 timeStamp; +/** 商家根据财付通文档填写的数据和签名 */ +@property (nonatomic, copy) NSString *package; +/** 商家根据微信开放平台文档对数据做的签名 */ +@property (nonatomic, copy) NSString *sign; + +@end + + +#pragma mark - PayResp +/*! @brief 微信终端返回给第三方的关于支付结果的结构体 + * + * 微信终端返回给第三方的关于支付结果的结构体 + */ +@interface PayResp : BaseResp + +/** 财付通返回给商家的信息 */ +@property (nonatomic, copy) NSString *returnKey; + +@end + +#pragma mark - WXOfflinePay +/*! @brief 第三方向微信终端发起离线支付 + * + * 第三方向微信终端发起离线支付的消息结构体 + */ +@interface WXOfflinePayReq : BaseReq + +@end + +/*! @brief 第三方向微信终端发起离线支付返回 + * + * 第三方向微信终端发起离线支付返回的消息结构体 + */ +@interface WXOfflinePayResp : BaseResp + +@end + + +#pragma mark - WXNontaxPayReq +@interface WXNontaxPayReq:BaseReq + +@property (nonatomic, copy) NSString *urlString; + +@end + +#pragma mark - WXNontaxPayResp +@interface WXNontaxPayResp : BaseResp + +@property (nonatomic, copy) NSString *wxOrderId; + +@end + +#pragma mark - WXPayInsuranceReq +@interface WXPayInsuranceReq : BaseReq + +@property (nonatomic, copy) NSString *urlString; + +@end + +#pragma mark - WXPayInsuranceResp +@interface WXPayInsuranceResp : BaseResp + +@property (nonatomic, copy) NSString *wxOrderId; + +@end + + +#pragma mark - WXQRCodePayReq +@interface WXQRCodePayReq : BaseReq +/** 码内容 + * @note 必填,码长度必须大于0且小于10K + */ +@property (nonatomic, copy) NSString *codeContent; +/** 额外信息 + * @note 长度必须大于0且小于10K + */ +@property (nonatomic, copy) NSString *extraMsg; + +@end + +@interface WXQRCodePayResp : BaseResp +@end + +#endif + + +#pragma mark - SendAuthReq +/*! @brief 第三方程序向微信终端请求认证的消息结构 + * + * 第三方程序要向微信申请认证,并请求某些权限,需要调用WXApi的sendReq成员函数, + * 向微信终端发送一个SendAuthReq消息结构。微信终端处理完后会向第三方程序发送一个处理结果。 + * @see SendAuthResp + */ +@interface SendAuthReq : BaseReq +/** 第三方程序要向微信申请认证,并请求某些权限,需要调用WXApi的sendReq成员函数,向微信终端发送一个SendAuthReq消息结构。微信终端处理完后会向第三方程序发送一个处理结果。 + * @see SendAuthResp + * @note scope字符串长度不能超过1K + */ +@property (nonatomic, copy) NSString *scope; +/** 第三方程序本身用来标识其请求的唯一性,最后跳转回第三方程序时,由微信终端回传。 + * @note state字符串长度不能超过1K + */ +@property (nonatomic, copy) NSString *state; + +@property (nonatomic, assign) BOOL isOption1; + +/** 是否关闭自动授权 + * @note YES为关闭自动授权,每次登陆都需要用户手动授权;NO为允许自动授权 + */ +@property (nonatomic, assign) BOOL nonautomatic; + +@property (nonatomic, copy) NSString *extData; + +@end + +#pragma mark - SendAuthResp +/*! @brief 微信处理完第三方程序的认证和权限申请后向第三方程序回送的处理结果。 + * + * 第三方程序要向微信申请认证,并请求某些权限,需要调用WXApi的sendReq成员函数,向微信终端发送一个SendAuthReq消息结构。 + * 微信终端处理完后会向第三方程序发送一个SendAuthResp。 + * @see onResp + */ +@interface SendAuthResp : BaseResp +@property (nonatomic, copy, nullable) NSString *code; +/** 第三方程序发送时用来标识其请求的唯一性的标志,由第三方程序调用sendReq时传入,由微信终端回传 + * @note state字符串长度不能超过1K + * @note 在复杂度较高的应用程序中,可能会出现其他模块请求的响应对象被错误地回调到当前模块。 + * 为了避免影响其他模块,建议当前模块的开发者根据SendAuthResp的内容,采用白名单的方式进行处理。 + * 例如,SendAuthResp.state符合预期时,才对其进行处理。 + */ +@property (nonatomic, copy, nullable) NSString *state; +@property (nonatomic, copy, nullable) NSString *lang; +@property (nonatomic, copy, nullable) NSString *country; +@end + +#pragma mark - WXStateJumpInfo +/*! @brief 状态发表时的小尾巴跳转信息 + */ +@interface WXStateJumpInfo : NSObject + +@end + +#pragma mark - WXStateJumpUrlInfo +/*! @brief 状态小尾巴跳转指定url的信息 + */ +@interface WXStateJumpUrlInfo : WXStateJumpInfo +/** 跳转到指定的url + * @note 必填,url长度必须大于0且小于10K + */ +@property (nonatomic, copy) NSString *url; + +@end + +#pragma mark - WXStateJumpWXMiniProgramInfo +/*! @brief 状态小尾巴跳转指定小程序的信息 + */ +@interface WXStateJumpMiniProgramInfo : WXStateJumpInfo +/** 小程序username + * @note 必填 + */ +@property (nonatomic, copy) NSString *username; + +/** 小程序页面的路径 + * @attention 不填默认拉起小程序首页 + */ +@property (nonatomic, copy, nullable) NSString *path; + +/** 分享小程序的版本 + * @attention (正式,开发,体验) + */ +@property (nonatomic, assign) WXMiniProgramType miniProgramType; + +@end + + + +#pragma mark - WXStateJumpWXMiniProgramInfo +/*! @brief 状态小尾巴跳转指定视频号主页信息 + */ +@interface WXStateJumpChannelProfileInfo : WXStateJumpInfo +/** 视频号username + * @note 必填,username长度必须大于0且小于1K + */ +@property (nonatomic, copy) NSString *username; + + +@end + +#pragma mark - WXStateSceneDataObject +/*! @brief 场景类型额外参数基类 + */ +@interface WXSceneDataObject : NSObject + +@end + +#pragma mark - WXStateSceneDataObject +/*! @brief 状态场景类型 + * 用户填写WXStateSceneDataObject参数后,可以跳转到微信状态发表页 + */ +@interface WXStateSceneDataObject : WXSceneDataObject + +/** 状态标志的ID + * @note 选填,文本长度必须小于10K + */ +@property (nonatomic, copy) NSString *stateId; +/** 状态发表时附带的文本描述 + * @note 选填,文本长度必须小于10K + */ +@property (nonatomic, copy) NSString *stateTitle; +/** 后台校验token + * @note 选填,文本长度必须小于10K + */ +@property (nonatomic, copy) NSString *token; +/** 小尾巴跳转所需的信息 + * @note 必填,目前仅支持url跳转 + */ +@property (nonatomic, strong) WXStateJumpInfo *stateJumpDataInfo; + +@end + +#pragma mark - SendMessageToWXReq +/*! @brief 第三方程序发送消息至微信终端程序的消息结构体 + * + * 第三方程序向微信发送信息需要传入SendMessageToWXReq结构体,信息类型包括文本消息和多媒体消息, + * 分别对应于text和message成员。调用该方法后,微信处理完信息会向第三方程序发送一个处理结果。 + * @see SendMessageToWXResp + */ +@interface SendMessageToWXReq : BaseReq +/** 发送消息的文本内容 + * @note 文本长度必须大于0且小于10K + */ +@property (nonatomic, copy) NSString *text; +/** 发送消息的多媒体内容 + * @see WXMediaMessage + */ +@property (nonatomic, strong) WXMediaMessage *message; +/** 发送消息的类型,包括文本消息和多媒体消息两种,两者只能选择其一,不能同时发送文本和多媒体消息 */ +@property (nonatomic, assign) BOOL bText; +/** 发送的目标场景,可以选择发送到会话(WXSceneSession)或者朋友圈(WXSceneTimeline)。 默认发送到会话。 + * @see WXScene + */ +@property (nonatomic, assign) int scene; +/** 指定发送消息的人 + * @note WXSceneSpecifiedSession时有效 + */ +@property (nonatomic, copy, nullable) NSString *toUserOpenId; +/** 目标场景附带信息 + * @note 目前只针对状态场景 + */ +@property (nonatomic, strong) WXSceneDataObject *sceneDataObject; + +@end + +#pragma mark - SendMessageToWXResp +/*! @brief 微信终端向第三方程序返回的SendMessageToWXReq处理结果。 + * + * 第三方程序向微信终端发送SendMessageToWXReq后,微信发送回来的处理结果,该结果用SendMessageToWXResp表示。 + */ +@interface SendMessageToWXResp : BaseResp +@property(nonatomic, copy) NSString *lang; +@property(nonatomic, copy) NSString *country; +@end + +#pragma mark - GetMessageFromWXReq +/*! @brief 微信终端向第三方程序请求提供内容的消息结构体。 + * + * 微信终端向第三方程序请求提供内容,微信终端会向第三方程序发送GetMessageFromWXReq消息结构体, + * 需要第三方程序调用sendResp返回一个GetMessageFromWXResp消息结构体。 + */ +@interface GetMessageFromWXReq : BaseReq +@property (nonatomic, strong) NSString *lang; +@property (nonatomic, strong) NSString *country; +@end + + + +#pragma mark - GetMessageFromWXResp +/*! @brief 微信终端向第三方程序请求提供内容,第三方程序向微信终端返回的消息结构体。 + * + * 微信终端向第三方程序请求提供内容,第三方程序调用sendResp向微信终端返回一个GetMessageFromWXResp消息结构体。 + */ +@interface GetMessageFromWXResp : BaseResp +/** 向微信终端提供的文本内容 + @note 文本长度必须大于0且小于10K + */ +@property (nonatomic, strong) NSString *text; +/** 向微信终端提供的多媒体内容。 + * @see WXMediaMessage + */ +@property (nonatomic, strong) WXMediaMessage *message; +/** 向微信终端提供内容的消息类型,包括文本消息和多媒体消息两种,两者只能选择其一,不能同时发送文本和多媒体消息 */ +@property (nonatomic, assign) BOOL bText; +@end + + + +#pragma mark - ShowMessageFromWXReq +/*! @brief 微信通知第三方程序,要求第三方程序显示的消息结构体。 + * + * 微信需要通知第三方程序显示或处理某些内容时,会向第三方程序发送ShowMessageFromWXReq消息结构体。 + * 第三方程序处理完内容后调用sendResp向微信终端发送ShowMessageFromWXResp。 + */ +@interface ShowMessageFromWXReq : BaseReq +/** 微信终端向第三方程序发送的要求第三方程序处理的多媒体内容 + * @see WXMediaMessage + */ +@property (nonatomic, strong) WXMediaMessage *message; +@property (nonatomic, copy) NSString *lang; +@property (nonatomic, copy) NSString *country; +@end + + + +#pragma mark - ShowMessageFromWXResp +/*! @brief 微信通知第三方程序,要求第三方程序显示或处理某些消息,第三方程序处理完后向微信终端发送的处理结果。 + * + * 微信需要通知第三方程序显示或处理某些内容时,会向第三方程序发送ShowMessageFromWXReq消息结构体。 + * 第三方程序处理完内容后调用sendResp向微信终端发送ShowMessageFromWXResp。 + */ +@interface ShowMessageFromWXResp : BaseResp +@end + + +#pragma mark - LaunchFromWXReq +/*! @brief 微信终端打开第三方程序携带的消息结构体 + * + * 微信向第三方发送的结构体,第三方不需要返回 + */ +@interface LaunchFromWXReq : BaseReq +@property (nonatomic, strong) WXMediaMessage *message; +@property (nonatomic, copy) NSString *lang; +@property (nonatomic, copy) NSString *country; +@end + + +#pragma mark - OpenWebviewReq +/* ! @brief 第三方通知微信启动内部浏览器,打开指定网页 + * + * 第三方通知微信启动内部浏览器,打开指定Url对应的网页 + */ +@interface OpenWebviewReq : BaseReq +/** 需要打开的网页对应的Url + * @attention 长度不能超过1024 + */ +@property(nonatomic, copy) NSString *url; + +@end + +#pragma mark - OpenWebviewResp +/*! @brief 微信终端向第三方程序返回的OpenWebviewReq处理结果 + * + * 第三方程序向微信终端发送OpenWebviewReq后,微信发送回来的处理结果,该结果用OpenWebviewResp表示 + */ +@interface OpenWebviewResp : BaseResp + +@end + + + +#pragma mark - WXOpenBusinessWebViewReq +/*! @brief 第三方通知微信启动内部浏览器,打开指定业务的网页 + * + * + */ +@interface WXOpenBusinessWebViewReq : BaseReq + +/** 网页业务类型 + * @attention + */ +@property (nonatomic, assign) UInt32 businessType; + +/** 网页业务参数 + * @attention + */ +@property (nonatomic, strong, nullable) NSDictionary *queryInfoDic; + +@end + +#pragma mark - WXOpenBusinessWebViewResp +/*! @brief 微信终端向第三方程序返回的WXOpenBusinessWebViewResp处理结果。 + * + * 第三方程序向微信终端发送WXOpenBusinessWebViewReq后,微信发送回来的处理结果,该结果用WXOpenBusinessWebViewResp表示。 + */ +@interface WXOpenBusinessWebViewResp : BaseResp +/** 第三方程序自定义简单数据,微信终端会回传给第三方程序处理 + * @attention 长度不能超过2k + */ +@property (nonatomic, copy) NSString *result; + +/** 网页业务类型 + * @attention + */ +@property (nonatomic, assign) UInt32 businessType; + +@end + + +#pragma mark - OpenRankListReq +/* ! @brief 第三方通知微信,打开硬件排行榜 + * + * 第三方通知微信,打开硬件排行榜 + */ +@interface OpenRankListReq : BaseReq + +@end + +#pragma mark - OpenRanklistResp +/*! @brief 微信终端向第三方程序返回的OpenRankListReq处理结果。 + * + * 第三方程序向微信终端发送OpenRankListReq后,微信发送回来的处理结果,该结果用OpenRankListResp表示。 + */ +@interface OpenRankListResp : BaseResp + +@end + + +#pragma mark - WXCardItem + +@interface WXCardItem : NSObject +/** 卡id + * @attention 长度不能超过1024字节 + */ +@property (nonatomic, copy) NSString *cardId; +/** ext信息 + * @attention 长度不能超过2024字节 + */ +@property (nonatomic, copy, nullable) NSString *extMsg; +/** + * @attention 卡的状态,req不需要填。resp:0为未添加,1为已添加。 + */ +@property (nonatomic, assign) UInt32 cardState; +/** + * @attention req不需要填,chooseCard返回的。 + */ +@property (nonatomic, copy) NSString *encryptCode; +/** + * @attention req不需要填,chooseCard返回的。 + */ +@property (nonatomic, copy) NSString *appID; +@end; + +#pragma mark - WXInvoiceItem + +@interface WXInvoiceItem : NSObject +/** 卡id + * @attention 长度不能超过1024字节 + */ +@property (nonatomic, copy) NSString *cardId; +/** ext信息 + * @attention 长度不能超过2024字节 + */ +@property (nonatomic, copy, nullable) NSString *extMsg; +/** + * @attention 卡的状态,req不需要填。resp:0为未添加,1为已添加。 + */ +@property (nonatomic, assign) UInt32 cardState; +/** + * @attention req不需要填,chooseCard返回的。 + */ +@property (nonatomic, copy) NSString *encryptCode; +/** + * @attention req不需要填,chooseCard返回的。 + */ +@property (nonatomic, copy) NSString *appID; + +@end + +#pragma mark - AddCardToWXCardPackageReq +/* ! @brief 请求添加卡券至微信卡包 + * + */ + +@interface AddCardToWXCardPackageReq : BaseReq +/** 卡列表 + * @attention 个数不能超过40个 类型WXCardItem + */ +@property (nonatomic, strong) NSArray *cardAry; + +@end + + +#pragma mark - AddCardToWXCardPackageResp +/** ! @brief 微信返回第三方添加卡券结果 + * + */ + +@interface AddCardToWXCardPackageResp : BaseResp +/** 卡列表 + * @attention 个数不能超过40个 类型WXCardItem + */ +@property (nonatomic, strong) NSArray *cardAry; +@end + +#pragma mark - WXChooseCardReq +/* ! @brief 请求从微信选取卡券 + * + */ + +@interface WXChooseCardReq : BaseReq +@property (nonatomic, copy) NSString *appID; +@property (nonatomic, assign) UInt32 shopID; +@property (nonatomic, assign) UInt32 canMultiSelect; +@property (nonatomic, copy) NSString *cardType; +@property (nonatomic, copy) NSString *cardTpID; +@property (nonatomic, copy) NSString *signType; +@property (nonatomic, copy) NSString *cardSign; +@property (nonatomic, assign) UInt32 timeStamp; +@property (nonatomic, copy) NSString *nonceStr; +@end + + +#pragma mark - WXChooseCardResp +/** ! @brief 微信返回第三方请求选择卡券结果 + * + */ + +@interface WXChooseCardResp : BaseResp +@property (nonatomic, strong ) NSArray* cardAry; +@end + + +#pragma mark - WXChooseInvoiceReq +/* ! @brief 请求从微信选取发票 + * + */ +@interface WXChooseInvoiceReq : BaseReq +@property (nonatomic, copy) NSString *appID; +@property (nonatomic, assign) UInt32 shopID; +@property (nonatomic, copy) NSString *signType; +@property (nonatomic, copy) NSString *cardSign; +@property (nonatomic, assign) UInt32 timeStamp; +@property (nonatomic, copy) NSString *nonceStr; +@end + +#pragma mark - WXChooseInvoiceResp +/** ! @brief 微信返回第三方请求选择发票结果 + * + */ +@interface WXChooseInvoiceResp : BaseResp +@property (nonatomic, strong) NSArray* cardAry; +@end + +#pragma mark - WXSubscriptionReq +@interface WXSubscribeMsgReq : BaseReq +@property (nonatomic, assign) UInt32 scene; +@property (nonatomic, copy) NSString *templateId; +@property (nonatomic, copy, nullable) NSString *reserved; +@end + +#pragma mark - WXSubscriptionReq +@interface WXSubscribeMsgResp : BaseResp + +@property (nonatomic, copy) NSString *templateId; +@property (nonatomic, assign) UInt32 scene; +@property (nonatomic, copy) NSString *action; +@property (nonatomic, copy) NSString *reserved; +@property (nonatomic, copy, nullable) NSString *openId; + +@end + +#pragma mark - WXSubscribeMiniProgramMsg +/** ! @brief 第三方请求订阅小程序消息 + * + */ +@interface WXSubscribeMiniProgramMsgReq : BaseReq +@property (nonatomic, copy) NSString *miniProgramAppid; +@end + +#pragma mark - WXSubscriptionReq +@interface WXSubscribeMiniProgramMsgResp : BaseResp + +@property(nonatomic, copy) NSString *openId; // 小程序openid +@property(nonatomic, copy) NSString *unionId; // unionId +@property(nonatomic, copy) NSString *nickName; // 用户昵称 + +@end + +#pragma mark - WXinvoiceAuthInsertReq +@interface WXInvoiceAuthInsertReq : BaseReq + +@property (nonatomic, copy) NSString *urlString; + +@end + +#pragma mark - WXinvoiceAuthInsertResp + +@interface WXInvoiceAuthInsertResp : BaseResp + +@property (nonatomic, copy) NSString *wxOrderId; + +@end + +#pragma mark - WXMediaMessage + +/*! @brief 多媒体消息结构体 + * + * 用于微信终端和第三方程序之间传递消息的多媒体消息内容 + */ +@interface WXMediaMessage : NSObject + ++ (WXMediaMessage *)message; + +/** 标题 + * @note 长度不能超过512字节 + */ +@property (nonatomic, copy) NSString *title; +/** 描述内容 + * @note 长度不能超过1K + */ +@property (nonatomic, copy) NSString *description; +/** 缩略图数据 + * @note 大小不能超过64K + */ +@property (nonatomic, strong, nullable) NSData *thumbData; +/** + * @note 长度不能超过64字节 + */ +@property (nonatomic, copy, nullable) NSString *mediaTagName; +/** + * + */ +@property (nonatomic, copy, nullable) NSString *messageExt; +@property (nonatomic, copy, nullable) NSString *messageAction; +/** + * 多媒体数据对象,可以为WXImageObject,WXMusicObject,WXVideoObject,WXWebpageObject等。 + */ +@property (nonatomic, strong) id mediaObject; + +/** 缩略图的hash值 + * @note 使用sha256得到,用于计算签名 + */ +@property (nonatomic, copy, nullable) NSString *thumbDataHash; + +/** 消息签名 + * @note 用于校验消息体是否被篡改过 + */ +@property (nonatomic, copy, nullable) NSString *msgSignature; + + +/*! @brief 设置消息缩略图的方法 + * + * @param image 缩略图 + * @note 大小不能超过256K + */ +- (void)setThumbImage:(UIImage *)image; + +@end + + + +#pragma mark - WXImageObject +/*! @brief 多媒体消息中包含的图片数据对象 + * + * 微信终端和第三方程序之间传递消息中包含的图片数据对象。 + * @note imageData成员不能为空 + * @see WXMediaMessage + */ +@interface WXImageObject : NSObject +/*! @brief 返回一个WXImageObject对象 + * + * @note 返回的WXImageObject对象是自动释放的 + */ ++ (WXImageObject *)object; + +/** 图片真实数据内容 + * @note 大小不能超过25M + */ +@property (nonatomic, strong) NSData *imageData; + +/** 图片数据的hash值 + * @note 使用sha256得到,用于计算签名 + */ +@property (nonatomic, copy, nullable) NSString *imgDataHash; + +/** 分享的图片消息是否要带小程序入口,若 'entranceMiniProgramUsername' 非空则显示 + * 仅部分小程序类目可用 + * @note 本字段为空则发送普通app图片消息 + */ +@property (nonatomic, copy, nullable) NSString *entranceMiniProgramUsername; + +/** 分享的图片消息显示的小程序入口可以跳转的小程序路径 + * 仅当 'entranceMiniProgramUsername' 非空时生效 + */ +@property (nonatomic, copy, nullable) NSString *entranceMiniProgramPath; + +@end + + +#pragma mark - WXMusicObject +/*! @brief 多媒体消息中包含的音乐数据对象 + * + * 微信终端和第三方程序之间传递消息中包含的音乐数据对象。 + * @note musicUrl和musicLowBandUrl成员不能同时为空。 + * @see WXMediaMessage + */ +@interface WXMusicObject : NSObject +/*! @brief 返回一个WXMusicObject对象 + * + * @note 返回的WXMusicObject对象是自动释放的 + */ ++ (WXMusicObject *)object; + +/** 音乐网页的url地址 + * @note 长度不能超过10K + */ +@property (nonatomic, copy) NSString *musicUrl; +/** 音乐lowband网页的url地址 + * @note 长度不能超过10K + */ +@property (nonatomic, copy) NSString *musicLowBandUrl; +/** 音乐数据url地址 + * @note 长度不能超过10K + */ +@property (nonatomic, copy) NSString *musicDataUrl; + +/**音乐lowband数据url地址 + * @note 长度不能超过10K + */ +@property (nonatomic, copy) NSString *musicLowBandDataUrl; + +/**音乐封面图Url + * @note 长度不能超过10K + */ +@property (nonatomic, copy) NSString *songAlbumUrl; + +/**歌词信息 LRC格式 + * @note 长度不能超过32K + */ +@property (nonatomic, copy, nullable) NSString *songLyric; +@end + + + +#pragma mark - WXMusicVideoObject + +@interface WXMusicVipInfo : NSObject + +/**付费歌曲的id + * @note 长度不能超过32K + */ +@property (nonatomic, copy) NSString *musicId; + +@end + + +@interface WXMusicVideoObject : NSObject + +/*! @brief 返回一个WXMusicVideoObject对象 + * + * @note 返回的WXMusicVideoObject对象是自动释放的 + */ ++ (WXMusicVideoObject *)object; + +/** 音乐网页的url地址 + * @note 长度不能超过10K,不能为空 + */ +@property (nonatomic, copy) NSString *musicUrl; + +/** 音乐数据url地址 + * @note 长度不能超过10K,不能为空 + */ +@property (nonatomic, copy) NSString *musicDataUrl; + +/**歌手名 + * @note 长度不能超过1k,不能为空 + */ +@property (nonatomic, copy) NSString *singerName; + +/** + * @note 音乐时长, 单位毫秒 + */ +@property (nonatomic, assign) UInt32 duration; + +/**歌词信息 LRC格式 + * @note 长度不能超过32K + */ +@property (nonatomic, copy) NSString *songLyric; + +/**高清封面图 + * @note 大小不能超过1M + */ +@property (nonatomic, strong) NSData *hdAlbumThumbData; + +/** 高清封面图数据的hash值 + * @note 使用sha256得到,用于计算签名 + */ +@property (nonatomic, copy, nullable) NSString *hdAlbumThumbFileHash; + +/**音乐专辑名称 + * @note 长度不能超过1k + */ +@property (nonatomic, copy, nullable) NSString *albumName; + +/**音乐流派 + * @note 长度不能超过1k + */ +@property (nonatomic, copy, nullable) NSString *musicGenre; + +/**发行时间 + * @note Unix时间戳,单位为秒 + */ +@property (nonatomic, assign) UInt64 issueDate; + +/**音乐标识符 + * @note 长度不能超过1K,从微信跳回应用时会带上 + */ +@property (nonatomic, copy, nullable) NSString *identification; + +/**运营H5地址 + * @note 选填,建议填写,用户进入歌曲详情页将展示内嵌的运营H5,可展示该歌曲的相关评论、歌曲推荐等内容,不可诱导下载、分享等。 + */ +@property (nonatomic, copy, nullable) NSString *musicOperationUrl; + +/** 付费歌曲相关信息 + * @note 选填,如果歌曲是需要付费的,那么将付费歌曲id等信息封装在内。 + */ +@property (nonatomic, strong) WXMusicVipInfo *musicVipInfo; + +@end + + + +#pragma mark - WXVideoObject +/*! @brief 多媒体消息中包含的视频数据对象 + * + * 微信终端和第三方程序之间传递消息中包含的视频数据对象。 + * @note videoUrl和videoLowBandUrl不能同时为空。 + * @see WXMediaMessage + */ +@interface WXVideoObject : NSObject +/*! @brief 返回一个WXVideoObject对象 + * + * @note 返回的WXVideoObject对象是自动释放的 + */ ++ (WXVideoObject *)object; + +/** 视频网页的url地址 + * @note 长度不能超过10K + */ +@property (nonatomic, copy) NSString *videoUrl; +/** 视频lowband网页的url地址 + * @note 长度不能超过10K + */ +@property (nonatomic, copy) NSString *videoLowBandUrl; + +@end + + + +#pragma mark - WXWebpageObject +/*! @brief 多媒体消息中包含的网页数据对象 + * + * 微信终端和第三方程序之间传递消息中包含的网页数据对象。 + * @see WXMediaMessage + */ +@interface WXWebpageObject : NSObject +/*! @brief 返回一个WXWebpageObject对象 + * + * @note 返回的WXWebpageObject对象是自动释放的 + */ ++ (WXWebpageObject *)object; + +/** 网页的url地址 + * @note 不能为空且长度不能超过10K + */ +@property (nonatomic, copy) NSString *webpageUrl; + +/**是否是私密消息 + */ +@property (nonatomic, assign) BOOL isSecretMessage; + +/** 业务所需的额外信息 */ +@property (nonatomic, strong, nullable) NSDictionary *extraInfoDic; + +@end + + + +#pragma mark - WXAppExtendObject +/*! @brief 多媒体消息中包含的App扩展数据对象 + * + * 第三方程序向微信终端发送包含WXAppExtendObject的多媒体消息, + * 微信需要处理该消息时,会调用该第三方程序来处理多媒体消息内容。 + * @note url,extInfo和fileData不能同时为空 + * @see WXMediaMessage + */ +@interface WXAppExtendObject : NSObject +/*! @brief 返回一个WXAppExtendObject对象 + * + * @note 返回的WXAppExtendObject对象是自动释放的 + */ ++ (WXAppExtendObject *)object; + +/** 若第三方程序不存在,微信终端会打开该url所指的App下载地址 + * @note 长度不能超过10K + */ +@property (nonatomic, copy) NSString *url; +/** 第三方程序自定义简单数据,微信终端会回传给第三方程序处理 + * @note 长度不能超过2K + */ +@property (nonatomic, copy, nullable) NSString *extInfo; +/** App文件数据,该数据发送给微信好友,微信好友需要点击后下载数据,微信终端会回传给第三方程序处理 + * @note 大小不能超过10M + */ +@property (nonatomic, strong, nullable) NSData *fileData; + +@end + + + +#pragma mark - WXEmoticonObject +/*! @brief 多媒体消息中包含的表情数据对象 + * + * 微信终端和第三方程序之间传递消息中包含的表情数据对象。 + * @see WXMediaMessage + */ +@interface WXEmoticonObject : NSObject + +/*! @brief 返回一个WXEmoticonObject对象 + * + * @note 返回的WXEmoticonObject对象是自动释放的 + */ ++ (WXEmoticonObject *)object; + +/** 表情真实数据内容 + * @note 大小不能超过10M + */ +@property (nonatomic, strong) NSData *emoticonData; + +@end + + + +#pragma mark - WXFileObject +/*! @brief 多媒体消息中包含的文件数据对象 + * + * @see WXMediaMessage + */ +@interface WXFileObject : NSObject + +/*! @brief 返回一个WXFileObject对象 + * + * @note 返回的WXFileObject对象是自动释放的 + */ ++ (WXFileObject *)object; + +/** 文件后缀名 + * @note 长度不超过64字节 + */ +@property (nonatomic, copy) NSString *fileExtension; + +/** 文件真实数据内容 + * @note 大小不能超过10M + */ +@property (nonatomic, strong) NSData *fileData; + +@end + + +#pragma mark - WXLocationObject +/*! @brief 多媒体消息中包含的地理位置数据对象 + * + * 微信终端和第三方程序之间传递消息中包含的地理位置数据对象。 + * @see WXMediaMessage + */ +@interface WXLocationObject : NSObject + +/*! @brief 返回一个WXLocationObject对象 + * + * @note 返回的WXLocationObject对象是自动释放的 + */ ++ (WXLocationObject *)object; + +/** 地理位置信息 + * @note 经纬度 + */ +@property (nonatomic, assign) double lng; //经度 +@property (nonatomic, assign) double lat; //纬度 + +@end + +#pragma mark - WXTextObject +/*! @brief 多媒体消息中包含的文本数据对象 + * + * 微信终端和第三方程序之间传递消息中包含的文本数据对象。 + * @see WXMediaMessage + */ +@interface WXTextObject : NSObject + +/*! @brief 返回一个WXTextObject对象 + * + * @note 返回的WXTextObject对象是自动释放的 + */ ++ (WXTextObject *)object; + +/** 地理位置信息 + * @note 文本内容 + */ +@property (nonatomic, copy) NSString *contentText; + +@end + +#pragma mark - WXMiniProgramObject + +@interface WXMiniProgramObject : NSObject + +/*! @brief WXMiniProgramObject对象 + * + * @note 返回的WXMiniProgramObject对象是自动释放的 + */ ++ (WXMiniProgramObject *)object; + +/** 低版本网页链接 + * @attention 长度不能超过1024字节 + */ +@property (nonatomic, copy) NSString *webpageUrl; + +/** 小程序username */ +@property (nonatomic, copy) NSString *userName; + +/** 小程序页面的路径 + * @attention 不填默认拉起小程序首页 + */ +@property (nonatomic, copy, nullable) NSString *path; + +/** 小程序新版本的预览图 + * @attention 大小不能超过128k + */ +@property (nonatomic, strong, nullable) NSData *hdImageData; + +/** 是否使用带 shareTicket 的转发 */ +@property (nonatomic, assign) BOOL withShareTicket; + +/** 分享小程序的版本 + * @attention (正式,开发,体验) + */ +@property (nonatomic, assign) WXMiniProgramType miniProgramType; + +/** 是否禁用转发 */ +@property (nonatomic, assign) BOOL disableForward; + +@property (nonatomic, assign) BOOL isUpdatableMessage; + +@property (nonatomic, assign) BOOL isSecretMessage; + + +/** 业务所需的额外信息 */ +@property (nonatomic, strong, nullable) NSDictionary *extraInfoDic; + +@end + +#pragma mark - WXGameLiveObject + +/*! @brief WXGameLiveObject对象 + * + * @note 游戏直播消息类型 + */ + +@interface WXGameLiveObject : NSObject + ++ (WXGameLiveObject *)object; + +/** 业务所需的额外信息 */ +@property (nonatomic, strong, nullable) NSDictionary *extraInfoDic; + +@end + +@interface WXNativeGamePageObject : NSObject + +/** 是否为视频类型 + */ +@property (nonatomic, assign) BOOL isVideo; + +/** 视频时长 + @note 当为视频类型时,必填;单位为秒 + */ +@property (nonatomic, assign) UInt32 videoDuration; + +/** 透传字段 + @note 长度限制为100K + */ +@property (nonatomic, copy) NSString *shareData; + +/** 缩略图 + @note 大小限制为256K + */ +@property (nonatomic, strong) NSData *gameThumbData; + ++ (WXNativeGamePageObject *)object; + +@end + +#pragma mark - WXLaunchMiniProgramReq + +/*! @brief WXLaunchMiniProgramReq对象, 可实现通过sdk拉起微信小程序 + * + * @note 返回的WXLaunchMiniProgramReq对象是自动释放的 + */ +@interface WXLaunchMiniProgramReq : BaseReq + ++ (WXLaunchMiniProgramReq *)object; + +/** 小程序username */ +@property (nonatomic, copy) NSString *userName; + +/** 小程序页面的路径 + * @attention 不填默认拉起小程序首页 + */ +@property (nonatomic, copy, nullable) NSString *path; + +/** 分享小程序的版本 + * @attention (正式,开发,体验) + */ +@property (nonatomic, assign) WXMiniProgramType miniProgramType; + +/** ext信息 + * @attention json格式 + */ +@property (nonatomic, copy, nullable) NSString *extMsg; + +/** extDic + * @attention 字典,可存放图片等比较大的数据 + */ +@property (nonatomic, copy, nullable) NSDictionary *extDic; + +@end + +#pragma mark - WXLaunchMiniProgramResp +/*! @brief 微信终端向第三方程序返回的WXLaunchMiniProgramReq处理结果。 + * + * 第三方程序向微信终端发送WXLaunchMiniProgramReq后,微信发送回来的处理结果,该结果用WXLaunchMiniProgramResp表示。 + */ +@interface WXLaunchMiniProgramResp : BaseResp + +@property (nonatomic, copy, nullable) NSString *extMsg; + +@end + + +#pragma mark - WXOpenBusinessViewReq +/*! @brief WXOpenBusinessViewReq对象, 可实现第三方通知微信启动,打开业务页面 + * + * @note 返回的WXOpenBusinessViewReq对象是自动释放的 + */ + +@interface WXOpenBusinessViewReq : BaseReq + ++ (WXOpenBusinessViewReq *)object; + +/** 业务类型 + */ +@property (nonatomic, copy) NSString *businessType; + +/** 业务参数 + */ +@property (nonatomic, copy, nullable) NSString *query; + +/** ext信息 + * @note 选填,json格式 + */ +@property (nonatomic, copy, nullable) NSString *extInfo; + +/** extData数据 + * @note + */ +@property (nonatomic, strong, nullable) NSData *extData; +@end + + +@interface WXOpenBusinessViewResp : BaseResp + +/** 业务类型 + */ +@property (nonatomic, copy) NSString *businessType; + +/** 业务返回数据 + */ +@property (nonatomic, copy, nullable) NSString *extMsg; + +@end + +#pragma mark - WXOpenCustomerServiceReq +@interface WXOpenCustomerServiceReq : BaseReq + ++ (WXOpenCustomerServiceReq *)object; + +/**企微客服发起流程 url + */ +@property (nonatomic, copy, nullable) NSString *url; + +/**企业 id + */ +@property (nonatomic, copy, nullable) NSString *corpid; + +@end + +@interface WXOpenCustomerServiceResp : BaseResp + +/** 业务返回数据 + */ +@property (nonatomic, copy, nullable) NSString *extMsg; + +@end + + +#pragma mark - WXChannelStartLiveReq + +@interface WXChannelStartLiveReq : BaseReq + ++ (WXChannelStartLiveReq *)object; + +/** 必填,直播业务数据(json格式) + */ +@property (nonatomic, copy) NSString *liveJsonInfo; + +@end + +@interface WXChannelStartLiveResp : BaseResp + +/** 业务返回数据 + */ +@property (nonatomic, copy, nullable) NSString *extMsg; + +@end + +NS_ASSUME_NONNULL_END diff --git a/uni_modules/uni-payment-wxpay/utssdk/app-ios/Libs/WeChatSDK/WechatAuthSDK.h b/uni_modules/uni-payment-wxpay/utssdk/app-ios/Libs/WeChatSDK/WechatAuthSDK.h new file mode 100644 index 0000000000000000000000000000000000000000..308aaea1af9ac61ae73e63695ab23a2f890a89fe --- /dev/null +++ b/uni_modules/uni-payment-wxpay/utssdk/app-ios/Libs/WeChatSDK/WechatAuthSDK.h @@ -0,0 +1,68 @@ +// +// WechatAuthSDK.h +// WechatAuthSDK +// +// Created by 李凯 on 13-11-29. +// Copyright (c) 2013年 Tencent. All rights reserved. +// + +#import +#import + +NS_ASSUME_NONNULL_BEGIN + +enum AuthErrCode { + WechatAuth_Err_Ok = 0, //Auth成功 + WechatAuth_Err_NormalErr = -1, //普通错误 + WechatAuth_Err_NetworkErr = -2, //网络错误 + WechatAuth_Err_GetQrcodeFailed = -3, //获取二维码失败 + WechatAuth_Err_Cancel = -4, //用户取消授权 + WechatAuth_Err_Timeout = -5, //超时 +}; + +@protocol WechatAuthAPIDelegate +@optional + +- (void)onAuthGotQrcode:(UIImage *)image; //得到二维码 +- (void)onQrcodeScanned; //二维码被扫描 +- (void)onAuthFinish:(int)errCode AuthCode:(nullable NSString *)authCode; //成功登录 + +@end + +@interface WechatAuthSDK : NSObject{ + NSString *_sdkVersion; + __weak id _delegate; +} + +@property(nonatomic, weak, nullable) id delegate; +@property(nonatomic, readonly) NSString *sdkVersion; //authSDK版本号 + +/*! @brief 发送登录请求,等待WechatAuthAPIDelegate回调 + * + * @param appId 微信开发者ID + * @param nonceStr 一个随机的尽量不重复的字符串,用来使得每次的signature不同 + * @param timeStamp 时间戳 + * @param scope 应用授权作用域,拥有多个作用域用逗号(,)分隔 + * @param signature 签名 + * @param schemeData 会在扫码后拼在scheme后 + * @return 成功返回YES,失败返回NO + 注:该实现只保证同时只有一个Auth在运行,Auth未完成或未Stop再次调用Auth接口时会返回NO。 + */ + +- (BOOL)Auth:(NSString *)appId + nonceStr:(NSString *)nonceStr + timeStamp:(NSString *)timeStamp + scope:(NSString *)scope + signature:(NSString *)signature + schemeData:(nullable NSString *)schemeData; + + +/*! @brief 暂停登录请求 + * + * @return 成功返回YES,失败返回NO。 + */ +- (BOOL)StopAuth; + +@end + +NS_ASSUME_NONNULL_END diff --git a/uni_modules/uni-payment-wxpay/utssdk/app-ios/Libs/WeChatSDK/libWeChatSDK.a b/uni_modules/uni-payment-wxpay/utssdk/app-ios/Libs/WeChatSDK/libWeChatSDK.a new file mode 100644 index 0000000000000000000000000000000000000000..845272b30a870c55806464a7de0d3167e57871cd Binary files /dev/null and b/uni_modules/uni-payment-wxpay/utssdk/app-ios/Libs/WeChatSDK/libWeChatSDK.a differ diff --git a/uni_modules/uni-payment-wxpay/utssdk/app-ios/UTS.entitlements b/uni_modules/uni-payment-wxpay/utssdk/app-ios/UTS.entitlements new file mode 100644 index 0000000000000000000000000000000000000000..314291360d66c665eca2d5f432d4e2fcc9db0da9 --- /dev/null +++ b/uni_modules/uni-payment-wxpay/utssdk/app-ios/UTS.entitlements @@ -0,0 +1,8 @@ + + + + + com.apple.developer.associated-domains + + + diff --git a/uni_modules/uni-payment-wxpay/utssdk/app-ios/config.json b/uni_modules/uni-payment-wxpay/utssdk/app-ios/config.json index 59db4269c476123234dc2e4ff2c84fa48edc1d48..8456495b88aa865a7c6d61766c13895510331b46 100644 --- a/uni_modules/uni-payment-wxpay/utssdk/app-ios/config.json +++ b/uni_modules/uni-payment-wxpay/utssdk/app-ios/config.json @@ -1,9 +1,30 @@ -{ - "frameworks": [ - "CoreGraphics.framework", - "WebKit.framework", - "Security.framework" - ], - "deploymentTarget": "12.0" -} - +{ + "frameworks": [ + "CoreGraphics.framework", + "WebKit.framework", + "Security.framework" + ], + "deploymentTarget": "12.0", + "parameters": { + "appid": { + "des": "请填写微信开发者平台对应app的APPID" + }, + "universalLink": { + "des": "请填写能唤起当前应用的Universal Links路径(https开头,以“/”结尾,建议带path,比如“https://your_domain/app/”),在实际调用SDK时,会校验Universal Links是否匹配" + } + }, + "plists": { + "CFBundleURLTypes": [{ + "CFBundleTypeRole": "Editor", + "CFBundleURLName": "WeChat", + "CFBundleURLSchemes": [ + "{$appid}" + ] + }], + "LSApplicationQueriesSchemes": ["weixin", "weixinULAPI", "weixinURLParamsAPI"], + "WeChat": { + "appid": "{$appid}", + "universalLink": "{$universalLink}" + } + } +} \ No newline at end of file diff --git a/uni_modules/uni-payment-wxpay/utssdk/app-ios/index.uts b/uni_modules/uni-payment-wxpay/utssdk/app-ios/index.uts index 05ab1bb0345edb446754d7a06a3ee13646d21518..b52ef5fea442c9b3ec167c8d93a827b6ee918a56 100644 --- a/uni_modules/uni-payment-wxpay/utssdk/app-ios/index.uts +++ b/uni_modules/uni-payment-wxpay/utssdk/app-ios/index.uts @@ -1,5 +1,193 @@ -import { Wxpay } from "./Wxpay"; +import { UTSiOSHookProxy } from "DCloudUniappRuntime"; +import { UIApplication } from "UIKit"; +import { URL, NSUserActivity } from "Foundation"; -export const requestPayment : RequestPayment = function (options : RequestPaymentOptions) { - new Wxpay().requestPayment(options) -}; \ No newline at end of file +const wxDefaultErrorCode : number = 700000 + +const wxErrorCodeMap : Map = new Map([ + [-1, 701100], + [-2, 700601] +]) + +export class UniPaymentWxpayProvider implements UniPaymentProvider { + + id: string + + override description: string = "wechat" + + isAppExist: boolean + + requestPayment(options : RequestPaymentOptions) { + Wxpay.requestPayment(options) + } + + checkAppExist() { + this.isAppExist = Wxpay.share.isWXAppInstalled() + } + + constructor() { + this.id = "wxpay" + this.isAppExist = Wxpay.share.isWXAppInstalled() + } +} + +export class WxpayHookProxy implements UTSiOSHookProxy { + // 应用正常启动时 (不包括已在后台转到前台的情况)的回调函数。 + applicationDidFinishLaunchingWithOptions(application : UIApplication | null, launchOptions : Map | null = null) : boolean { + Wxpay.share.registerApp() + return false + } + + // 通过 url scheme 方式唤起 app 时的回调函数。 + applicationOpenURLOptions(app : UIApplication | null, url : URL, options : Map | null = null) : boolean { + Wxpay.share.handleOpen(url) + return true + } + + // 当应用程序接收到与用户活动相关的数据时调用此方法,例如,当用户使用 Universal Link 唤起应用时。 + applicationContinueUserActivityRestorationHandler(application : UIApplication | null, userActivity : NSUserActivity | null, restorationHandler : ((res : [any] | null) => void) | null = null) : boolean { + Wxpay.share.handleOpenUniversalLink(userActivity) + return true + } +} + +export class Wxpay implements WXApiDelegate { + static share = new Wxpay() + + private options ?: RequestPaymentOptions + + @UTSiOS.keyword("fileprivate") + registerApp() { + const scheme = Wxpay.share.getApplicationScheme() + const universalLink = Wxpay.share.getApplicationUniversalLink() + if (scheme != null && universalLink != null) { + WXApi.registerApp(scheme!, universalLink = universalLink!) + } + } + + @UTSiOS.keyword("fileprivate") + handleOpen(url : URL) { + WXApi.handleOpen(url, delegate = this) + } + + @UTSiOS.keyword("fileprivate") + handleOpenUniversalLink(userActivity : NSUserActivity | null) { + if (userActivity != null) { + WXApi.handleOpenUniversalLink(userActivity!, delegate = this) + } + } + + private getApplicationScheme() : string | null { + let scheme : string | null = null + const infoDictionary = Bundle.main.infoDictionary + if (infoDictionary != null) { + const bundleURLTypes = infoDictionary!['CFBundleURLTypes'] as Map[] | null + if (bundleURLTypes != null) { + bundleURLTypes!.forEach((value, key) => { + const urlIdentifier = value['CFBundleURLName'] as string | null + if (urlIdentifier != null && urlIdentifier!.toLowerCase() == "wechat") { + const urlSchemes = value['CFBundleURLSchemes'] as string[] + scheme = urlSchemes[0] + } + }) + } + } + return scheme + } + + private getApplicationUniversalLink() : string | null { + let universalLink : string | null = null + const infoDictionary = Bundle.main.infoDictionary + if (infoDictionary != null) { + const wechat = infoDictionary!['WeChat'] as Map | null + if (wechat != null) { + universalLink = wechat!['universalLink'] as string | null + } + } + return universalLink + } + + //@brief 检查微信是否已被用户安装 + @UTSiOS.keyword("fileprivate") + isWXAppInstalled() : boolean { + return WXApi.isWXAppInstalled() + } + + //@brief 发送一个sendReq后,收到微信的回应 + onResp(resp : BaseResp) { + if (resp.errCode == 0) { + let res : RequestPaymentSuccess = { + data: resp + } + this.options?.success?.(res) + this.options?.complete?.(res) + } else { + const errCode = resp.errCode as number + let code = wxErrorCodeMap[errCode]; + if (code == null) { + code = wxDefaultErrorCode + } + let err = new RequestPaymentFailImpl(code!); + this.options?.fail?.(err) + this.options?.complete?.(err) + } + } + + static requestPayment(options : RequestPaymentOptions) { + Wxpay.share.options = options + + if (Wxpay.share.isWXAppInstalled() == false) { + let err = new RequestPaymentFailImpl(wxDefaultErrorCode); + Wxpay.share.options?.fail?.(err) + Wxpay.share.options?.complete?.(err) + return + } + + if (Wxpay.share.getApplicationScheme() == null) { + let err = new RequestPaymentFailImpl(700800); + Wxpay.share.options?.fail?.(err) + Wxpay.share.options?.complete?.(err) + return + } + + if (Wxpay.share.getApplicationUniversalLink() == null) { + let err = new RequestPaymentFailImpl(700801); + Wxpay.share.options?.fail?.(err) + Wxpay.share.options?.complete?.(err) + return + } + + if (Wxpay.share.options != null) { + const params = JSON.parse(Wxpay.share.options!.orderInfo) as UTSJSONObject + const partnerId = params.getString("partnerid") + const prepayId = params.getString("prepayid") + const packageV = params.getString("package") + const nonceStr = params.getString("noncestr") + const timeStamp = params.getNumber("timestamp") + const sign = params.getString("sign") + + let request = new PayReq(); + if (partnerId != null) { + request.partnerId = partnerId! + } + if (prepayId != null) { + request.prepayId = prepayId! + } + if (packageV != null) { + request.package = packageV! + } + if (nonceStr != null) { + request.nonceStr = nonceStr! + } + if (timeStamp != null) { + request.timeStamp = timeStamp!.toUInt32() + } + if (sign != null) { + request.sign = sign! + } + + //函数调用后,会切换到微信的界面。第三方应用程序等待微信返回onResp。微信在异步处理完成后一定会调用onResp + WXApi.send(request); + } + } +} \ No newline at end of file diff --git a/uni_modules/uni-payment/utssdk/app-android/index.uts b/uni_modules/uni-payment/utssdk/app-android/index.uts index bf64aeec30e2131076ddfc52f08dd073eab76663..f3e95cf4a00cea4eb50c23c4473c65e307acf4be 100644 --- a/uni_modules/uni-payment/utssdk/app-android/index.uts +++ b/uni_modules/uni-payment/utssdk/app-android/index.uts @@ -3,11 +3,11 @@ import { RequestPaymentFailImpl } from '../unierror.uts' export const requestPayment : RequestPayment = function (options : RequestPaymentOptions) { //获取provider实例,hx自动生成,其中UniPaymentProvider为在interface中定义的接口 - const provider = UTSAndroid.getExtApiProvider("payment", options.provider) + const provider = UTSAndroid.getProvider("payment", options.provider) if (provider != null) { provider.requestPayment(options) } else { - let err = new RequestPaymentFailImpl(700716); + let err = new RequestPaymentFailImpl(700000); options.fail?.(err) options.complete?.(err) } diff --git a/uni_modules/uni-payment/utssdk/app-ios/index.uts b/uni_modules/uni-payment/utssdk/app-ios/index.uts index ffaefa5d7ff4840db0b982f75766f88c0c48d1e0..eb4c2d952e187519615d6a243e2d49a9c62a3acf 100644 --- a/uni_modules/uni-payment/utssdk/app-ios/index.uts +++ b/uni_modules/uni-payment/utssdk/app-ios/index.uts @@ -1,14 +1,14 @@ import { UniPaymentProvider, RequestPayment, RequestPaymentOptions} from "../interface.uts"; import { RequestPaymentFailImpl } from '../unierror.uts'; import { UTSiOS } from "DCloudUTSFoundation"; - + export const requestPayment : RequestPayment = function (options : RequestPaymentOptions) { - const provider = UTSiOS.getExtApiProvider("payment", options.provider) + const provider = UTSiOS.getProvider("payment", options.provider, UniPaymentProvider.self) if(provider != null){ provider!.requestPayment(options) } else { - const err = new RequestPaymentFailImpl(700716); + const err = new RequestPaymentFailImpl(700000); options.fail?.(err) options.complete?.(err) - } + } }; diff --git a/uni_modules/uni-payment/utssdk/interface.uts b/uni_modules/uni-payment/utssdk/interface.uts index 151a34e1558cb95839f4ce40dc478d9caa0b60e5..91d3c21d56f06f0e5409a1b46a07510d87173e13 100644 --- a/uni_modules/uni-payment/utssdk/interface.uts +++ b/uni_modules/uni-payment/utssdk/interface.uts @@ -1,7 +1,7 @@ import { RequestPaymentFailImpl as RequestPaymentFailImplement } from './unierror.uts' export type RequestPaymentFailImpl = RequestPaymentFailImplement -export type UniPaymentProvider = Uni +export interface UniPaymentProvider extends Uni{} export interface Uni { /** * @description 请求支付 @@ -27,7 +27,7 @@ export interface Uni { * "ios": { * "osVer": "9.0", * "uniVer": "√", - * "unixVer": "x" + * "unixVer": "4.18" * } * }, * "web": { @@ -40,15 +40,18 @@ export interface Uni { } /** * 错误码 - * - 700710 正在处理中,支付结果未知(有可能已经支付成功),请查询商家订单列表中订单的支付状态 - * - 700711 订单支付失败。 - * - 700712 重复请求。 - * - 700713 用户中途取消。 - * - 700714 网络连接出错。 - * - 700715 支付结果未知(有可能已经支付成功),请查询商家订单列表中订单的支付状态。 - * - 700716 其它支付错误。 + * - 700600 正在处理中,支付结果未知(有可能已经支付成功),请查询商家订单列表中订单的支付状态 + * - 701100 订单支付失败。 + * - 701110 重复请求。 + * - 700601 用户中途取消。 + * - 700602 网络连接出错。 + * - 700603 支付结果未知(有可能已经支付成功),请查询商家订单列表中订单的支付状态。 + * - 700000 其它支付错误。 + * - 700604 微信没有安装。 + * - 700800 没有配置对应的URL Scheme。 + * - 700801 没有配置对应的universal Link。 */ -export type RequestPaymentErrorCode = 700710 | 700711 | 700712 | 700713 | 700714 | 700715 | 700716; +export type RequestPaymentErrorCode = 700600 | 701100 | 701110 | 700601 | 700602 | 700603 | 700000 | 700604 | 700800 | 700801; export type RequestPayment = (options : RequestPaymentOptions) => void; export type RequestPaymentSuccess = { diff --git a/uni_modules/uni-payment/utssdk/unierror.uts b/uni_modules/uni-payment/utssdk/unierror.uts index 4c2a035bdf0ca16f3b32c9370c26215c47d173d7..703e79a7371d6e35b2348548253ef25be3972f48 100644 --- a/uni_modules/uni-payment/utssdk/unierror.uts +++ b/uni_modules/uni-payment/utssdk/unierror.uts @@ -12,36 +12,40 @@ const RequestPaymentUniErrors : Map = new Map([ /** * 正在处理中,支付结果未知(有可能已经支付成功),请查询商家订单列表中订单的支付状态。 */ - [700710, 'The payment result is unknown (it may have been successfully paid). Please check the payment status of the order in the merchant order list.'], + [700600, 'The payment result is unknown (it may have been successfully paid). Please check the payment status of the order in the merchant order list.'], /** * 订单支付失败。 */ - [700711, 'Order payment failure.'], + [701100, 'Order payment failure.'], /** * 重复请求。 */ - [700712, 'Repeat the request.'], + [701110, 'Repeat the request.'], /** * 用户中途取消。 */ - [700713, 'The user canceled midway.'], + [700601, 'The user canceled midway.'], /** * 网络连接出错。 */ - [700714, 'Network connection error.'], + [700602, 'Network connection error.'], /** * 支付结果未知(有可能已经支付成功),请查询商家订单列表中订单的支付状态。 */ - [700715, 'Payment result unknown (may have been successfully paid), please check the payment status of the order in the merchant order list.'], + [700603, 'Payment result unknown (may have been successfully paid), please check the payment status of the order in the merchant order list.'], /** * 其它支付错误。 */ - [700716, 'Other payment errors.'], + [700000, 'Other payment errors.'], /** * 微信没有安装 */ - [700717, 'Wechat is not installed.'] + [700604, 'Wechat is not installed.'], + /** + * iOS 没有配置对应的URL Scheme + */ + [700718, 'URL Scheme is not configured.'] ]); diff --git a/uni_modules/uni-prompt/utssdk/app-android/res/layout/uni_prompt_ac_recyclerview_layout_top.xml b/uni_modules/uni-prompt/utssdk/app-android/res/layout/uni_prompt_ac_recyclerview_layout_top.xml index 47e9e85ba465929fb401914fbfeffcd4443e3c58..92dfa564ad6688c87f2ec3420bce9ecfb30624aa 100644 --- a/uni_modules/uni-prompt/utssdk/app-android/res/layout/uni_prompt_ac_recyclerview_layout_top.xml +++ b/uni_modules/uni-prompt/utssdk/app-android/res/layout/uni_prompt_ac_recyclerview_layout_top.xml @@ -9,17 +9,28 @@ android:id="@+id/line_bottom" android:layout_width="match_parent" android:layout_height="0dp" +<<<<<<<< HEAD:uni_modules/uni-prompt/utssdk/app-android/res/layout/uni_prompt_ac_recyclerview_layout_top_night.xml + android:background="@color/uni_prompt_night_bg_hair_line_night" +======== android:background="@color/uni_prompt_night_bg_hair_line" +>>>>>>>> alpha:uni_modules/uni-prompt/utssdk/app-android/res/layout/uni_prompt_ac_recyclerview_layout_top.xml android:orientation="vertical" /> >>>>>>> alpha:uni_modules/uni-prompt/utssdk/app-android/res/layout/uni_prompt_ac_recyclerview_layout_top.xml android:textSize="16dp" /> diff --git a/uni_modules/uni-prompt/utssdk/app-android/res/layout/uni_prompt_ac_recyclerview_layout_top_night.xml b/uni_modules/uni-prompt/utssdk/app-android/res/layout/uni_prompt_ac_recyclerview_layout_top_night.xml index ddcb2253f5d38d89cd7464439e6b6cf7013223fe..c66f06ba31b27c3941dd89a0f16c61e992fbcf91 100644 --- a/uni_modules/uni-prompt/utssdk/app-android/res/layout/uni_prompt_ac_recyclerview_layout_top_night.xml +++ b/uni_modules/uni-prompt/utssdk/app-android/res/layout/uni_prompt_ac_recyclerview_layout_top_night.xml @@ -9,7 +9,11 @@ android:id="@+id/line_bottom" android:layout_width="match_parent" android:layout_height="0dp" +<<<<<<<< HEAD:uni_modules/uni-prompt/utssdk/app-android/res/layout/uni_prompt_ac_recyclerview_layout_top.xml + android:background="@color/uni_prompt_night_bg_hair_line" +======== android:background="@color/uni_prompt_night_bg_hair_line_night" +>>>>>>>> alpha:uni_modules/uni-prompt/utssdk/app-android/res/layout/uni_prompt_ac_recyclerview_layout_top_night.xml android:orientation="vertical" /> >>>>>>> alpha:uni_modules/uni-prompt/utssdk/app-android/res/layout/uni_prompt_ac_recyclerview_layout_top_night.xml android:textSize="16dp" /> diff --git a/uni_modules/uni-prompt/utssdk/app-android/showToast.uts b/uni_modules/uni-prompt/utssdk/app-android/showToast.uts index ebd9c1278fff29b8db2590e055d84762a39d2b4b..f626c610f491ed057749e9d4074f31584bbd5d74 100644 --- a/uni_modules/uni-prompt/utssdk/app-android/showToast.uts +++ b/uni_modules/uni-prompt/utssdk/app-android/showToast.uts @@ -46,10 +46,23 @@ export function hideLoadingImpl() { closeToast("loading") } + +// 全局存储 +// #ifdef UNI-APP-X +const onReadyToast = new Map() +// #endif + function closeToast(type : string | null) { if (type != null && type !== toastType) { return } + // #ifdef UNI-APP-X + let pages = getCurrentPages(); + if (pages.length > 0) { + let page = pages[pages.length - 1]; + onReadyToast.remove(page) + } + // #endif if (timeout != null && (timeout as number) > 0) { clearTimeout(timeout as number) timeout = null @@ -125,10 +138,17 @@ function makeLoading(style : ShowLoadingOptions, type : string, errMsg : string) toast = alert alert?.showWaiting(); } else { + onReadyToast.set(page,options) onReady(() => { - const alert = new WaitingView(UTSAndroid.getTopPageActivity(), options) - toast = alert - alert?.showWaiting(); + if(onReadyToast.containsKey(page)){ + options = onReadyToast.get(page) as UTSJSONObject; + + const alert = new WaitingView(UTSAndroid.getTopPageActivity(), options) + toast = alert + alert?.showWaiting(); + + onReadyToast.remove(page) + } }, instance) } @@ -250,10 +270,17 @@ function makeToast(style : ShowToastOptions, type : string, errMsg : string) { toast = alert alert?.showWaiting(); } else { + onReadyToast.set(page,options) onReady(() => { - const alert = new WaitingView(UTSAndroid.getTopPageActivity(), options) - toast = alert - alert?.showWaiting(); + if(onReadyToast.containsKey(page)){ + options = onReadyToast.get(page) as UTSJSONObject; + + const alert = new WaitingView(UTSAndroid.getTopPageActivity(), options) + toast = alert + alert?.showWaiting(); + + onReadyToast.remove(page) + } }, instance) } diff --git a/uni_modules/uni-route/utssdk/app-android/navigateBack.uts b/uni_modules/uni-route/utssdk/app-android/navigateBack.uts index 45407866a40549636664a3c977ed1ac756e370a0..f3cc399873af070382d65e6abdd7a3a6d65991cc 100644 --- a/uni_modules/uni-route/utssdk/app-android/navigateBack.uts +++ b/uni_modules/uni-route/utssdk/app-android/navigateBack.uts @@ -14,6 +14,7 @@ import { import { NavigateBackOptions, NavigateBackSuccess } from '../interface.uts' import { DEFAULT_ANIMATION_DURATION, + DEFAULT_ANIMATION_NAVIGATE_BACK, DEFAULT_ANIMATION_OUT, } from '../constants.uts' import { NavigateBackFailImpl } from '../unierror.uts' @@ -71,7 +72,7 @@ export const _navigateBack = ( new Map([ [ ANIMATION_TYPE, - options?.animationType ?? DEFAULT_ANIMATION_OUT, + options?.animationType ?? DEFAULT_ANIMATION_NAVIGATE_BACK, ], [ ANIMATION_DURATION, diff --git a/uni_modules/uni-route/utssdk/constants.uts b/uni_modules/uni-route/utssdk/constants.uts index f003008e6c888d94e3719252a462bb0ffd15fe28..a4fd092ace8ccfb78d4279d322214f1cf34f2504 100644 --- a/uni_modules/uni-route/utssdk/constants.uts +++ b/uni_modules/uni-route/utssdk/constants.uts @@ -1,6 +1,7 @@ export const DEFAULT_ANIMATION_IN = 'pop-in' export const DEFAULT_ANIMATION_OUT = 'pop-out' export const DEFAULT_ANIMATION_DURATION = 300 +export const DEFAULT_ANIMATION_NAVIGATE_BACK = 'auto' export const ANIMATION_IN = [ 'slide-in-right', diff --git a/uni_modules/uni-route/utssdk/interface.uts b/uni_modules/uni-route/utssdk/interface.uts index 4cf893e5ce95347a1c03061b5c5faac6e925a28a..eace7d9b042faaf09c4831c3aa9b2f473caaf97d 100644 --- a/uni_modules/uni-route/utssdk/interface.uts +++ b/uni_modules/uni-route/utssdk/interface.uts @@ -100,7 +100,7 @@ export type NavigateToOptions = { * "android": { * "osVer": "5.0", * "uniVer": "√", - * "unixVer": "x" + * "unixVer": "4.18" * }, * "ios": { * "osVer": "12.0", @@ -151,8 +151,8 @@ export type NavigateToOptions = { * } * }, * "web": { - * "uniVer": "√", - * "unixVer": "4.0" + * "uniVer": "x", + * "unixVer": "x" * } * } */ @@ -215,8 +215,8 @@ export type NavigateToOptions = { * } * }, * "web": { - * "uniVer": "√", - * "unixVer": "4.0" + * "uniVer": "x", + * "unixVer": "x" * } * } */ @@ -1369,7 +1369,7 @@ export type NavigateBackOptions = { * "android": { * "osVer": "5.0", * "uniVer": "√", - * "unixVer": "x" + * "unixVer": "4.18" * }, * "ios": { * "osVer": "12.0", @@ -1420,8 +1420,8 @@ export type NavigateBackOptions = { * } * }, * "web": { - * "uniVer": "√", - * "unixVer": "4.0" + * "uniVer": "x", + * "unixVer": "x" * } * } */ @@ -1484,8 +1484,8 @@ export type NavigateBackOptions = { * } * }, * "web": { - * "uniVer": "√", - * "unixVer": "4.0" + * "uniVer": "x", + * "unixVer": "x" * } * } */ diff --git a/uni_modules/uni-storage/utssdk/interface.uts b/uni_modules/uni-storage/utssdk/interface.uts index 8706a39fdcca508c43cb0c9ed222069218a3c1e4..34fc0989b1cb471957a4666a57cd00c9da9068a7 100644 --- a/uni_modules/uni-storage/utssdk/interface.uts +++ b/uni_modules/uni-storage/utssdk/interface.uts @@ -26,7 +26,7 @@ export type SetStorageOptions = { */ key: string, /** - * 需要存储的内容,只支持原生类型、及能够通过 JSON.stringify 序列化的对象 + * 需要存储的内容,只支持能通过 JSON.stringify 序列化的对象 */ data: any, /** @@ -275,7 +275,7 @@ export interface Uni { * 将 data 存储在本地storage存储中指定的 key 中,会覆盖掉原来该 key 对应的内容,这是一个同步接口。 * * @param {string} key 本地storage存储中的指定的 key - * @param {any} data 需要存储的内容,只支持原生类型、及能够通过 JSON.stringify 序列化的对象 + * @param {any} data 需要存储的内容,只支持能通过 JSON.stringify 序列化的对象 * @tutorial https://uniapp.dcloud.net.cn/api/storage/storage.html#setstoragesync * @uniPlatform { * "app": { diff --git a/uni_modules/uni-tabBar/utssdk/app-android/index.uts b/uni_modules/uni-tabBar/utssdk/app-android/index.uts index ca6420b77e4f9fddc3db0004309c2c657e272ad2..9ae114f3f488c10337ac84e37ff7b5b17b44f2a3 100644 --- a/uni_modules/uni-tabBar/utssdk/app-android/index.uts +++ b/uni_modules/uni-tabBar/utssdk/app-android/index.uts @@ -107,7 +107,11 @@ export const setTabBarStyle = defineAsyncApi< ['backgroundImage', options.backgroundImage], ['backgroundRepeat', options.backgroundRepeat], ]) - if (isString(options.borderStyle)) { + if (isString(options.borderColor)) { + style.set( + 'borderStyle', options.borderColor as string, + ) + } else if (isString(options.borderStyle)) { style.set( 'borderStyle', getTabBarBorderStyle(options.borderStyle as string), diff --git a/uni_modules/uni-tabBar/utssdk/interface.uts b/uni_modules/uni-tabBar/utssdk/interface.uts index 463538c0a7b134fde8427aa75c2981ecc05eca1b..1e432db0c9daa232735c501642b8e12b8109038b 100644 --- a/uni_modules/uni-tabBar/utssdk/interface.uts +++ b/uni_modules/uni-tabBar/utssdk/interface.uts @@ -235,10 +235,33 @@ export type SetTabBarStyleOptions = { * - no-repeat: 背景图片在垂直方向和水平方向都拉伸 */ backgroundRepeat?: 'repeat' | 'repeat-x' | 'repeat-y' | 'no-repeat' + /** + * tabbar上边框的颜色(优先级高于 borderStyle) + * @tutorial https://doc.dcloud.net.cn/uni-app-x/api/set-tabbar.html#settabbarstyle + * @uniPlatform { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "x", + * "unixVer": "x" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "x", + * "unixVer": "4.23" + * } + * }, + * "web": { + * "uniVer": "x", + * "unixVer": "4.23" + * } + * } + */ + borderColor?: string | string.ColorString /** * tabbar上边框的颜色 */ - borderStyle?: string + borderStyle?: 'black' | 'white' /** * tabbar 中间按钮 仅在 list 项为偶数时有效 * @internal @@ -917,10 +940,70 @@ export interface Uni { hideTabBarRedDot( options: HideTabBarRedDotOptions, ): Promise | null - // /** - // * 监听中间按钮的点击事件 - // * - // * @tutorial https://doc.dcloud.net.cn/uni-app-x/tabbar?id=ontabbarmidbuttontap - // */ - // onTabBarMidButtonTap(options: OnTabBarMidButtonTapCallback): void + /** + * 监听中间按钮的点击事件 + * + * @tutorial https://doc.dcloud.net.cn/uni-app-x/api/on-tab-bar-mid-button-tap.html + * @uniPlatform { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "x" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "x" + * } + * }, + * "mp": { + * "weixin": { + * "hostVer": "x", + * "uniVer": "x", + * "unixVer": "x" + * }, + * "alipay": { + * "hostVer": "x", + * "uniVer": "x", + * "unixVer": "x" + * }, + * "baidu": { + * "hostVer": "x", + * "uniVer": "x", + * "unixVer": "x" + * }, + * "toutiao": { + * "hostVer": "√", + * "uniVer": "√", + * "unixVer": "x" + * }, + * "lark": { + * "hostVer": "x", + * "uniVer": "x", + * "unixVer": "x" + * }, + * "qq": { + * "hostVer": "√", + * "uniVer": "√", + * "unixVer": "x" + * }, + * "kuaishou": { + * "hostVer": "x", + * "uniVer": "x", + * "unixVer": "x" + * }, + * "jd": { + * "hostVer": "x", + * "uniVer": "x", + * "unixVer": "x" + * } + * }, + * "web": { + * "uniVer": "√", + * "unixVer": "4.0" + * } + * } + */ + onTabBarMidButtonTap(options: OnTabBarMidButtonTapCallback): void } diff --git a/uni_modules/uni-theme/changelog.md b/uni_modules/uni-theme/changelog.md new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/uni_modules/uni-theme/package.json b/uni_modules/uni-theme/package.json new file mode 100644 index 0000000000000000000000000000000000000000..6b306e38973d021487e8a64aead4f8ec54b17f35 --- /dev/null +++ b/uni_modules/uni-theme/package.json @@ -0,0 +1,126 @@ +{ + "id": "uni-theme", + "displayName": "uni-theme", + "version": "1.0.0", + "description": "uni-theme", + "keywords": [ + "uni-theme" + ], + "repository": "", + "engines": { + "HBuilderX": "^3.6.8" + }, + "dcloudext": { + "type": "uts", + "sale": { + "regular": { + "price": "0.00" + }, + "sourcecode": { + "price": "0.00" + } + }, + "contact": { + "qq": "" + }, + "declaration": { + "ads": "", + "data": "", + "permissions": "" + }, + "npmurl": "" + }, + "uni_modules": { + "dependencies": [], + "uni-ext-api": { + "uni": { + "onOsThemeChange": { + "name": "onOsThemeChange", + "app": { + "js": false, + "kotlin": true, + "swift": true + } + }, + "offOsThemeChange": { + "name": "offOsThemeChange", + "app": { + "js": false, + "kotlin": true, + "swift": true + } + }, + "setAppTheme": { + "name": "setAppTheme", + "app": { + "js": false, + "kotlin": true, + "swift": true + } + }, + "onAppThemeChange": { + "name": "onAppThemeChange", + "app": { + "js": false, + "kotlin": true, + "swift": true + } + }, + "offAppThemeChange": { + "name": "offAppThemeChange", + "app": { + "js": false, + "kotlin": true, + "swift": true + } + } + } + }, + "encrypt": [], + "platforms": { + "cloud": { + "tcb": "u", + "aliyun": "u", + "alipay": "u" + }, + "client": { + "Vue": { + "vue2": "u", + "vue3": "u" + }, + "App": { + "app-android": "u", + "app-ios": "u" + }, + "H5-mobile": { + "Safari": "u", + "Android Browser": "u", + "微信浏览器(Android)": "u", + "QQ浏览器(Android)": "u" + }, + "H5-pc": { + "Chrome": "u", + "IE": "u", + "Edge": "u", + "Firefox": "u", + "Safari": "u" + }, + "小程序": { + "微信": "u", + "阿里": "u", + "百度": "u", + "字节跳动": "u", + "QQ": "u", + "钉钉": "u", + "快手": "u", + "飞书": "u", + "京东": "u" + }, + "快应用": { + "华为": "u", + "联盟": "u" + } + } + } + } +} \ No newline at end of file diff --git a/uni_modules/uni-theme/readme.md b/uni_modules/uni-theme/readme.md new file mode 100644 index 0000000000000000000000000000000000000000..be154a4a1b0e1c67c39f972693708ead0fb33169 --- /dev/null +++ b/uni_modules/uni-theme/readme.md @@ -0,0 +1,6 @@ +# uni-theme +### 开发文档 +[UTS 语法](https://uniapp.dcloud.net.cn/tutorial/syntax-uts.html) +[UTS API插件](https://uniapp.dcloud.net.cn/plugin/uts-plugin.html) +[UTS 组件插件](https://uniapp.dcloud.net.cn/plugin/uts-component.html) +[Hello UTS](https://gitcode.net/dcloud/hello-uts) \ No newline at end of file diff --git a/uni_modules/uni-theme/utssdk/app-android/config.json b/uni_modules/uni-theme/utssdk/app-android/config.json new file mode 100644 index 0000000000000000000000000000000000000000..7bb39c1e8a1b78d69862081fdfab5f65b2dfee32 --- /dev/null +++ b/uni_modules/uni-theme/utssdk/app-android/config.json @@ -0,0 +1,3 @@ +{ + "minSdkVersion": "21" +} \ No newline at end of file diff --git a/uni_modules/uni-theme/utssdk/app-android/index.uts b/uni_modules/uni-theme/utssdk/app-android/index.uts new file mode 100644 index 0000000000000000000000000000000000000000..c6b1caca0ba62811a99f98cb09f4c061024f8d4f --- /dev/null +++ b/uni_modules/uni-theme/utssdk/app-android/index.uts @@ -0,0 +1,45 @@ +import { OnOsThemeChange, OnOsThemeChangeCallback, OffOsThemeChange, SetAppTheme, SetAppThemeOptions, SetAppThemeSuccessResult, OnAppThemeChangeCallback, OnAppThemeChange, OffAppThemeChange, OsThemeChangeResult, AppThemeChangeResult} from "../interface.uts"; +import { AppThemeFailImpl } from '../unierror.uts'; + + +export const onOsThemeChange: OnOsThemeChange = function(callback : OnOsThemeChangeCallback): number{ + return UTSAndroid.onOsThemeChanged(function(res: UTSJSONObject) { + let result = { + osTheme : res["osTheme"] as string + } as OsThemeChangeResult + callback(result) + }) +} + +export const offOsThemeChange: OffOsThemeChange = function(id: number) { + UTSAndroid.offOsThemeChanged(id) +} + +export const setAppTheme: SetAppTheme = function(options : SetAppThemeOptions) { + if(options.theme == "auto" || options.theme == "dark" || options.theme == "light") { + UTSAndroid.setAppTheme(options.theme) + let result = { + theme : options.theme + } as SetAppThemeSuccessResult + options.success?.(result) + options.complete?.(result) + } else { + let error = new AppThemeFailImpl(702001) + options.fail?.(error) + options.complete?.(error) + } + +} + +export const onAppThemeChange: OnAppThemeChange = function(callback : OnAppThemeChangeCallback): number{ + return UTSAndroid.onAppThemeChanged(function(res: UTSJSONObject) { + let result = { + appTheme : res["appTheme"] as string + } as AppThemeChangeResult + callback(result) + }) +} + +export const offAppThemeChange: OffAppThemeChange = function(id: number) { + UTSAndroid.offAppThemeChanged(id) +} diff --git a/uni_modules/uni-theme/utssdk/app-ios/config.json b/uni_modules/uni-theme/utssdk/app-ios/config.json new file mode 100644 index 0000000000000000000000000000000000000000..55c96e4376170b6e408a85ca1368936eab9ecef2 --- /dev/null +++ b/uni_modules/uni-theme/utssdk/app-ios/config.json @@ -0,0 +1,3 @@ +{ + "deploymentTarget": "12" +} \ No newline at end of file diff --git a/uni_modules/uni-theme/utssdk/app-ios/index.uts b/uni_modules/uni-theme/utssdk/app-ios/index.uts new file mode 100644 index 0000000000000000000000000000000000000000..98bd1d3d57ca18e1ca3c7702cbc725c404837555 --- /dev/null +++ b/uni_modules/uni-theme/utssdk/app-ios/index.uts @@ -0,0 +1,74 @@ +import { + OnOsThemeChange, + OffOsThemeChange, + OnOsThemeChangeCallback, + OsThemeChangeResult, + SetAppTheme, + SetAppThemeOptions, + SetAppThemeSuccessResult, + OnAppThemeChange, + OnAppThemeChangeCallback, + AppThemeChangeResult +} from '../interface.uts' + +import { AppThemeFailImpl } from '../unierror.uts' + +/** + * 监听系统主题变化 +*/ +export const onOsThemeChange : OnOsThemeChange = function (callback : OnOsThemeChangeCallback) : number { + return UTSiOS.onOsThemeChange((theme : string) : void => { + let result : OsThemeChangeResult = { + osTheme: theme + } + callback(result) + }) +} + +/** + * 取消监听系统主题变化 +*/ +export const offOsThemeChange : OffOsThemeChange = function (id : number) : void { + UTSiOS.offOsThemeChange(id) +} + +/** + * 设置应用主题 +*/ +export const setAppTheme : SetAppTheme = function (options : SetAppThemeOptions) : void { + + if (options.theme == 'light' || options.theme == 'dark' || options.theme == 'auto') { + UTSiOS.setAppTheme(options.theme) + } else { + let error = new AppThemeFailImpl(702001) + options.fail?.(error) + options.complete?.(error) + return + } + + let result : SetAppThemeSuccessResult = { + theme: options.theme + } + options.success?.(result) + options.complete?.(result) +} + +/** + * 监听应用主题变化 +*/ +export const onAppThemeChange: OnAppThemeChange = function (callback: OnAppThemeChangeCallback) : number { + return UTSiOS.onAppThemeChange((theme : string) : void => { + let result : AppThemeChangeResult = { + appTheme: theme + } + callback(result) + }) +} + +/** + * 取消监听应用主题变化 +*/ +export const offAppThemeChange = function (id : number) : void { + UTSiOS.offAppThemeChange(id) +} + diff --git a/uni_modules/uni-theme/utssdk/interface.uts b/uni_modules/uni-theme/utssdk/interface.uts new file mode 100644 index 0000000000000000000000000000000000000000..e4ca9c13553a3aa4105c8f33337f9b02c23fdad0 --- /dev/null +++ b/uni_modules/uni-theme/utssdk/interface.uts @@ -0,0 +1,466 @@ +export interface Uni { + /** + * @description + * 开启监听系统主题变化 + * + * @param {OnOsThemeChangeCallback} callback + * @return {number} + * @tutorial + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "x", + * "unixVer": "4.18" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "x", + * "unixVer": "4.18" + * } + * }, + * "web": { + * "uniVer": "x", + * "unixVer": "x" + * } + * } + * @example + ```typescript + const id = uni.onOsThemeChange((res) => { + console.log(res.osTheme) + }) + ``` + */ + onOsThemeChange(callback : OnOsThemeChangeCallback): number + + /** + * @description + * 取消监听系统主题变化 + * + * @param {number} id + * @return {void} + * @tutorial + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "x", + * "unixVer": "4.18" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "x", + * "unixVer": "4.18" + * } + * }, + * "web": { + * "uniVer": "x", + * "unixVer": "x" + * } + * } + * @example + ```typescript + uni.offOsThemeChange(id) + ``` + */ + offOsThemeChange(id : number): void + + /** + * @description + * 设置应用主题 + * + * @param {SetAppThemeOptions} options + * @return {void} + * @tutorial + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "x", + * "unixVer": "4.18" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "x", + * "unixVer": "4.18" + * } + * }, + * "web": { + * "uniVer": "x", + * "unixVer": "x" + * } + * } + * @example + ```typescript + uni.setAppTheme({ + theme: 'dark', + success: (res) => { + console.log('success') + }, + fail: (err) => { + console.log(err) + }, + complete: (res) => { + console.log('complete') + } + }) + ``` + */ + setAppTheme(options : SetAppThemeOptions): void + + /** + * @description + * 开启监听应用主题变化 + * + * @param {OnAppThemeChangeCallback} callback + * @return {number} + * @tutorial + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "x", + * "unixVer": "4.18" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "x", + * "unixVer": "4.18" + * } + * }, + * "web": { + * "uniVer": "x", + * "unixVer": "x" + * } + * } + * @example + ```typescript + const id = uni.onAppThemeChange((res) => { + console.log(res.appTheme) + }) + ``` + */ + onAppThemeChange(callback : OnAppThemeChangeCallback): number + + /** + * @description + * 取消监听应用主题变化 + * + * @param {number} id + * @return {void} + * @tutorial + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "x", + * "unixVer": "4.18" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "x", + * "unixVer": "4.18" + * } + * }, + * "web": { + * "uniVer": "x", + * "unixVer": "x" + * } + * } + * @example + ```typescript + uni.offAppThemeChange(id) + ``` + */ + offAppThemeChange(id : number): void +} + +/** + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "x", + * "unixVer": "4.18" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "x", + * "unixVer": "4.18" + * } + * }, + * "web": { + * "uniVer": "x", + * "unixVer": "x" + * } + * } + */ +export type OsThemeChangeResult = { + /** + * 系统主题 + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "x", + * "unixVer": "4.18" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "x", + * "unixVer": "4.18" + * } + * }, + * "web": { + * "uniVer": "x", + * "unixVer": "x" + * } + * } + */ + osTheme : string +} + +/** + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "x", + * "unixVer": "4.18" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "x", + * "unixVer": "4.18" + * } + * }, + * "web": { + * "uniVer": "x", + * "unixVer": "x" + * } + * } + */ +export type AppThemeChangeResult = { + /** + * 应用主题 + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "x", + * "unixVer": "4.18" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "x", + * "unixVer": "4.18" + * } + * }, + * "web": { + * "uniVer": "x", + * "unixVer": "x" + * } + * } + */ + appTheme : string +} + +/* + * 系统主题相关类型定义 + */ +export type OnOsThemeChangeCallback = (res : OsThemeChangeResult) => void +export type OnOsThemeChange = (callback : OnOsThemeChangeCallback) => number +export type OffOsThemeChange = (id : number) => void + +/* + * 应用主题相关类型定义 + */ +export type SetAppTheme = (options : SetAppThemeOptions) => void +export type OnAppThemeChangeCallback = (res : AppThemeChangeResult) => void +export type OnAppThemeChange = (callback : OnAppThemeChangeCallback) => number +export type OffAppThemeChange = (id : number) => void +export type SetAppThemeSuccessResult = { + theme : string +} +export type SetAppThemeSuccessCallback = (result : SetAppThemeSuccessResult) => void; +export type SetAppThemeFailCallback = (result : AppThemeFail) => void; +export type SetAppThemeCompleteCallback = (result : any) => void; + +/** + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "x", + * "unixVer": "4.18" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "x", + * "unixVer": "4.18" + * } + * }, + * "web": { + * "uniVer": "x", + * "unixVer": "x" + * } + * } + */ +export type SetAppThemeOptions = { + /** + * 主题 + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "x", + * "unixVer": "4.18" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "x", + * "unixVer": "4.18" + * } + * }, + * "web": { + * "uniVer": "x", + * "unixVer": "x" + * } + * } + */ + theme : 'light' | 'dark' | 'auto' + /** + * 接口调用成功的回调函数 + * @defaultValue null + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "x", + * "unixVer": "4.18" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "x", + * "unixVer": "4.18" + * } + * }, + * "web": { + * "uniVer": "x", + * "unixVer": "x" + * } + * } + */ + success? : SetAppThemeSuccessCallback + /** + * 接口调用失败的回调函数 + * @defaultValue null + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "x", + * "unixVer": "4.18" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "x", + * "unixVer": "4.18" + * } + * }, + * "web": { + * "uniVer": "x", + * "unixVer": "x" + * } + * } + */ + fail? : SetAppThemeFailCallback + /** + * 接口调用结束的回调函数(调用成功、失败都会执行) + * @defaultValue null + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "x", + * "unixVer": "4.18" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "x", + * "unixVer": "4.18" + * } + * }, + * "web": { + * "uniVer": "x", + * "unixVer": "x" + * } + * } + */ + complete? : SetAppThemeCompleteCallback +} + +/** + * 错误码 + * - 702001 参数错误 + * - 2002000 未知错误 + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "x", + * "unixVer": "4.18" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "x", + * "unixVer": "4.18" + * } + * }, + * "web": { + * "uniVer": "x", + * "unixVer": "x" + * } + * } + */ +export type AppThemeErrorCode = 702001 | 2002000; +export type AppThemeFail = IAppThemeFail; +/** + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "x", + * "unixVer": "4.18" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "x", + * "unixVer": "4.18" + * } + * }, + * "web": { + * "uniVer": "x", + * "unixVer": "x" + * } + * } + */ +export interface IAppThemeFail extends IUniError { + errCode : AppThemeErrorCode +}; \ No newline at end of file diff --git a/uni_modules/uni-theme/utssdk/unierror.uts b/uni_modules/uni-theme/utssdk/unierror.uts new file mode 100644 index 0000000000000000000000000000000000000000..6d38dd06189a4807bd6bd33f2699848c5f8dc50c --- /dev/null +++ b/uni_modules/uni-theme/utssdk/unierror.uts @@ -0,0 +1,24 @@ +import { AppThemeErrorCode, IAppThemeFail } from "./interface.uts" + +/** + * 错误主题 + */ +export const AppThemeUniErrorSubject = 'uni-theme'; + +/** + * 错误码 + * @UniError + */ +export const AppThemeUniErrors : Map = new Map([ + [702001, 'invalid parameter'], + [2002000, 'unknown error'] +]); + +export class AppThemeFailImpl extends UniError implements IAppThemeFail { + constructor(errCode : AppThemeErrorCode) { + super(); + this.errSubject = AppThemeUniErrorSubject; + this.errCode = errCode; + this.errMsg = AppThemeUniErrors.get(errCode) ?? ""; + } +} \ No newline at end of file diff --git a/uni_modules/uni-usercapturescreen/utssdk/interface.uts b/uni_modules/uni-usercapturescreen/utssdk/interface.uts index 660ba251923808031b0eea043efa8a33fe862ad5..90b89cf58ed2e5991399b5d75f89eb03447e551e 100644 --- a/uni_modules/uni-usercapturescreen/utssdk/interface.uts +++ b/uni_modules/uni-usercapturescreen/utssdk/interface.uts @@ -63,11 +63,11 @@ export type SetUserCaptureScreenOptions = { */ // complete : SetUserCaptureScreenSuccessCallback | SetUserCaptureScreenFailCallback | null complete ?: SetUserCaptureScreenCompleteCallback -} - +} + /** * 错误码 - * - 12001 "setUserCaptureScreen:system not support" + * - 12001 "setUserCaptureScreen:system not support" * - 12010 "setUserCaptureScreen:system internal error" */ export type SetUserCaptureScreenErrorCode = 12001 | 12010; @@ -80,76 +80,91 @@ export interface SetUserCaptureScreenFail extends IUniError { export type SetUserCaptureScreen = (options : SetUserCaptureScreenOptions) => void -export interface Uni { - /** - * 开启截屏监听 - * - * @param {UserCaptureScreenCallback} callback - * @tutorial https://uniapp.dcloud.net.cn/api/system/capture-screen.html#onusercapturescreen - * @uniPlatform { - * "app": { - * "android": { - * "osVer": "4.4.4", - * "uniVer": "3.7.7", - * "unixVer": "3.9.0" - * }, - * "ios": { - * "osVer": "12.0", - * "uniVer": "3.7.7", - * "unixVer": "4.11" - * } - * } - * } - * @uniVersion 3.7.7 +export interface Uni { + /** + * 开启截屏监听 + * + * @param {UserCaptureScreenCallback} callback + * @tutorial https://uniapp.dcloud.net.cn/api/system/capture-screen.html#onusercapturescreen + * @uniPlatform { + * "app": { + * "android": { + * "osVer": "4.4.4", + * "uniVer": "3.7.7", + * "unixVer": "3.9.0" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "3.7.7", + * "unixVer": "4.11" + * }, + * "harmony": { + * "osVer": "x", + * "uniVer": "x", + * "unixVer": "x" + * } + * } + * } + * @uniVersion 3.7.7 * @uniVueVersion 2,3 //支持的vue版本 - * @autotest { expectCallback: true } + * @autotest { expectCallback: true } */ - onUserCaptureScreen(callback : UserCaptureScreenCallback | null) : void, - /** - * 关闭截屏监听 - * - * @param {UserCaptureScreenCallback} callback - * @tutorial https://uniapp.dcloud.net.cn/api/system/capture-screen.html#offusercapturescreen - * @uniPlatform { - * "app": { - * "android": { - * "osVer": "4.4.4", - * "uniVer": "3.7.7", - * "unixVer": "3.9.0" - * }, - * "ios": { - * "osVer": "12.0", - * "uniVer": "3.7.7", - * "unixVer": "4.11" - * } - * } - * } - * @uniVersion 3.7.7 + onUserCaptureScreen(callback : UserCaptureScreenCallback | null) : void, + /** + * 关闭截屏监听 + * + * @param {UserCaptureScreenCallback} callback + * @tutorial https://uniapp.dcloud.net.cn/api/system/capture-screen.html#offusercapturescreen + * @uniPlatform { + * "app": { + * "android": { + * "osVer": "4.4.4", + * "uniVer": "3.7.7", + * "unixVer": "3.9.0" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "3.7.7", + * "unixVer": "4.11" + * }, + * "harmony": { + * "osVer": "x", + * "uniVer": "x", + * "unixVer": "x" + * } + * } + * } + * @uniVersion 3.7.7 * @uniVueVersion 2,3 //支持的vue版本 - * @autotest { expectCallback: true } + * @autotest { expectCallback: true } */ - offUserCaptureScreen(callback : UserCaptureScreenCallback | null) : void, - /** - * 设置防截屏 - * - * @param {SetUserCaptureScreenOptions} options - * @tutorial https://uniapp.dcloud.net.cn/api/system/capture-screen.html#setusercapturescreen - * @uniPlatform { - * "app": { - * "android": { - * "osVer": "4.4.4", - * "uniVer": "3.7.7", - * "unixVer": "3.9.0" - * }, - * "ios": { - * "osVer": "13.0", - * "uniVer": "3.7.7", - * "unixVer": "4.11" - * } - * } - * } - * @uniVersion 3.7.7 - * @uniVueVersion 2,3 //支持的vue版本 + offUserCaptureScreen(callback : UserCaptureScreenCallback | null) : void, + /** + * 设置防截屏 + * + * @param {SetUserCaptureScreenOptions} options + * @tutorial https://uniapp.dcloud.net.cn/api/system/capture-screen.html#setusercapturescreen + * @uniPlatform { + * "app": { + * "android": { + * "osVer": "4.4.4", + * "uniVer": "3.7.7", + * "unixVer": "3.9.0" + * }, + * "ios": { + * "osVer": "13.0", + * "uniVer": "3.7.7", + * "unixVer": "4.11" + * }, + * "harmony": { + * "osVer": "x", + * "uniVer": "x", + * "unixVer": "x" + * } + * } + * } + * @uniVersion 3.7.7 + * @uniVueVersion 2,3 //支持的vue版本 */ setUserCaptureScreen(options : SetUserCaptureScreenOptions) : void -} +} diff --git a/uni_modules/uni-websocket/utssdk/app-ios/websocket/WebsockerClient.uts b/uni_modules/uni-websocket/utssdk/app-ios/websocket/WebsockerClient.uts index e0db98b90fd2a3a73d6acbb254c5c16b7fdc1238..0a12561928deaf5b5e03012edf3ce43081f1803c 100644 --- a/uni_modules/uni-websocket/utssdk/app-ios/websocket/WebsockerClient.uts +++ b/uni_modules/uni-websocket/utssdk/app-ios/websocket/WebsockerClient.uts @@ -138,8 +138,8 @@ class RunnableTask { public execute() { if (this.looper == null || this.looper!.currentMode == null) { this.callback?.(); - } else { - this.looper?.perform(() => { + } else { + this.looper?.perform(inModes = [RunLoop.Mode.common], block = () => { this.callback?.(); }) } diff --git a/uni_modules/uni-websocket/utssdk/interface.uts b/uni_modules/uni-websocket/utssdk/interface.uts index fd19440cde02b8fbf2c350e72d1f7d4d00e06dfd..dc22e70da955a0e45670c01a0dbda1b7396d722e 100644 --- a/uni_modules/uni-websocket/utssdk/interface.uts +++ b/uni_modules/uni-websocket/utssdk/interface.uts @@ -266,16 +266,61 @@ type ConnectSocketCompleteCallback = (result: ConnectSocketComplete) => void; export type ConnectSocketOptions = { /** * 开发者服务器接口地址 + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * } + * } */ url: string, /** * HTTP 请求 Header,header 中不能设置 Referer * @defaultValue null + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * } + * } */ header?: UTSJSONObject | null, /** * 子协议数组 * @defaultValue null + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * } + * } */ protocols?: (string[]) | null, /** @@ -318,6 +363,21 @@ export type SendSocketMessageOptions = { * 需要发送的内容 * @type string | ArrayBuffer * @type {SocketDataOptions} + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * } + * } */ data: any, /** @@ -340,11 +400,41 @@ export type CloseSocketOptions = { /** * 一个数字值表示关闭连接的状态号,表示连接被关闭的原因。如果这个参数没有被指定,默认的取值是1000 (表示正常连接关闭) * @defaultValue 1000 + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * } + * } */ code?: number | null, /** * 一个可读的字符串,表示连接被关闭的原因。这个字符串必须是不长于123字节的UTF-8 文本(不是字符) * @defaultValue "" + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * } + * } */ reason?: string | null, /** @@ -366,6 +456,21 @@ export type CloseSocketOptions = { export type OnSocketOpenCallbackResult = { /** * 连接成功的 HTTP 响应 Header + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * } + * } */ header: any }; @@ -373,6 +478,21 @@ export type OnSocketMessageCallbackResult = { /** * 服务器返回的消息 * @type {SocketDataOptions} + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * } + * } */ data: any }; @@ -594,11 +714,41 @@ export type OnSocketMessage = (callback: OnSocketMessageCallback) => void; export type CloseSocket = (options: CloseSocketOptions) => void; export type OnSocketCloseCallbackResult = { /** - * 一个数字值表示关闭连接的状态号,表示连接被关闭的原因。 + * 一个数字值表示关闭连接的状态号,表示连接被关闭的原因。 + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * } + * } */ code: number, /** * 一个可读的字符串,表示连接被关闭的原因。 + * @uniPlatform + * { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "√", + * "unixVer": "4.11" + * } + * } + * } */ reason: string }; diff --git a/uni_modules/uts-progressNotification/changelog.md b/uni_modules/uts-progressNotification/changelog.md index 332470475bb5475b7d3b24b633c91917f4dce414..8f90d3db3a3a9fd5b32e117277c7a6c6cd056b86 100644 --- a/uni_modules/uts-progressNotification/changelog.md +++ b/uni_modules/uts-progressNotification/changelog.md @@ -1,3 +1,9 @@ +## 1.1.0(2024-03-08) +修复uniapp打包报错问题 +## 1.0.9(2024-02-29) +去除代码过时警告 +## 1.0.8(2023-12-21) +去除app-ios目录 ## 1.0.7(2023-12-11) 去除无用代码 ## 1.0.6(2023-12-11) diff --git a/uni_modules/uts-progressNotification/package.json b/uni_modules/uts-progressNotification/package.json index 09e670999813e2e6271cbfd74dfbcbd43fe344a5..d3a6dcc4d6ffb91fea1be40fe92438d782d33e8d 100644 --- a/uni_modules/uts-progressNotification/package.json +++ b/uni_modules/uts-progressNotification/package.json @@ -1,7 +1,7 @@ { "id": "uts-progressNotification", "displayName": "uts-progressNotification", - "version": "1.0.7", + "version": "1.1.0", "description": "uts-progressNotification", "keywords": [ "uts-progressNotification" diff --git a/uni_modules/uts-progressNotification/utssdk/app-android/TransparentActivity.uts b/uni_modules/uts-progressNotification/utssdk/app-android/TransparentActivity.uts index 283e01db3035765dd294f3f40e0d9f52e037da08..19678999897061ac5dcba439fadd51d26e109551 100644 --- a/uni_modules/uts-progressNotification/utssdk/app-android/TransparentActivity.uts +++ b/uni_modules/uts-progressNotification/utssdk/app-android/TransparentActivity.uts @@ -4,15 +4,16 @@ import Build from 'android.os.Build'; import View from 'android.view.View'; import Color from 'android.graphics.Color'; import WindowManager from 'android.view.WindowManager'; -import { globalNotificationProgressFinishCallBack, globalNotificationProgressCallBack } from './index.uts'; +import { globalNotificationProgressFinishCallBack, globalNotificationProgressCallBack } from './callbacks.uts'; import { ACTION_DOWNLOAD_FINISH, ACTION_DOWNLOAD_PROGRESS } from "./constant.uts" export class TransparentActivity extends Activity { constructor() { super() - } + } + @Suppress("DEPRECATION") override onCreate(savedInstanceState : Bundle | null) { super.onCreate(savedInstanceState) this.fullScreen(this) @@ -58,4 +59,4 @@ export class TransparentActivity extends Activity { } } } -} \ No newline at end of file +} diff --git a/uni_modules/uts-progressNotification/utssdk/app-android/callbacks.uts b/uni_modules/uts-progressNotification/utssdk/app-android/callbacks.uts new file mode 100644 index 0000000000000000000000000000000000000000..23781894a9c8c7d27b4cdba5a76578b6f027d105 --- /dev/null +++ b/uni_modules/uts-progressNotification/utssdk/app-android/callbacks.uts @@ -0,0 +1,4 @@ + + +export let globalNotificationProgressCallBack : (() => void) | null = () => { } +export let globalNotificationProgressFinishCallBack = () => { } diff --git a/uni_modules/uts-progressNotification/utssdk/app-android/index.uts b/uni_modules/uts-progressNotification/utssdk/app-android/index.uts index 39d14cd58fb17e0adf913bbd6995e5849345e313..0782f616b86ca2b45e0a2674bc02d909dfa88e2f 100644 --- a/uni_modules/uts-progressNotification/utssdk/app-android/index.uts +++ b/uni_modules/uts-progressNotification/utssdk/app-android/index.uts @@ -8,7 +8,8 @@ import ComponentName from 'android.content.ComponentName'; import PendingIntent from 'android.app.PendingIntent'; import { CreateNotificationProgressOptions, FinishNotificationProgressOptions } from '../interface.uts'; import { ACTION_DOWNLOAD_FINISH, ACTION_DOWNLOAD_PROGRESS } from "./constant.uts" - + +import { globalNotificationProgressFinishCallBack, globalNotificationProgressCallBack } from './callbacks.uts'; export { TransparentActivity } from './TransparentActivity.uts'; @@ -26,8 +27,7 @@ let histroyProgress = 0 let isProgress = false -export let globalNotificationProgressCallBack : (() => void) | null = () => { } -export let globalNotificationProgressFinishCallBack = () => { } + export function createNotificationProgress(options : CreateNotificationProgressOptions) : void { const { content, progress, onClick } = options @@ -156,4 +156,4 @@ function getAppName(context : Context) : string { e.printStackTrace() } return appName -} \ No newline at end of file +} diff --git a/uni_modules/uts-progressNotification/utssdk/app-ios/config.json b/uni_modules/uts-progressNotification/utssdk/app-ios/config.json deleted file mode 100644 index d6281248a698f70985f2fd54722b527135d860d6..0000000000000000000000000000000000000000 --- a/uni_modules/uts-progressNotification/utssdk/app-ios/config.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "deploymentTarget": "9" -} \ No newline at end of file diff --git a/uni_modules/uts-progressNotification/utssdk/app-ios/index.uts b/uni_modules/uts-progressNotification/utssdk/app-ios/index.uts deleted file mode 100644 index e45e1e4d3ea5281d36178987e4edaa428cd6ce15..0000000000000000000000000000000000000000 --- a/uni_modules/uts-progressNotification/utssdk/app-ios/index.uts +++ /dev/null @@ -1,85 +0,0 @@ -/** - * 引用 iOS 系统库,示例如下: - * import { UIDevice } from "UIKit"; - * [可选实现,按需引入] - */ - -/* 引入 interface.uts 文件中定义的变量 */ -import { MyApiOptions, MyApiResult, MyApi, MyApiSync } from '../interface.uts'; - -/* 引入 unierror.uts 文件中定义的变量 */ -import { MyApiFailImpl } from '../unierror'; - -/** - * 引入三方库 - * [可选实现,按需引入] - * - * 在 iOS 平台引入三方库有以下两种方式: - * 1、通过引入三方库framework 或者.a 等方式,需要将 .framework 放到 ./Frameworks 目录下,将.a 放到 ./Libs 目录下。更多信息[详见](https://uniapp.dcloud.net.cn/plugin/uts-plugin.html#ios-平台原生配置) - * 2、通过 cocoaPods 方式引入,将要引入的 pod 信息配置到 config.json 文件下的 dependencies-pods 字段下。详细配置方式[详见](https://uniapp.dcloud.net.cn/plugin/uts-ios-cocoapods.html) - * - * 在通过上述任意方式依赖三方库后,使用时需要在文件中 import: - * 示例:import { LottieLoopMode } from 'Lottie' - */ - -/** - * UTSiOS 为平台内置对象,不需要 import 可直接调用其API,[详见](https://uniapp.dcloud.net.cn/uts/utsios.html) - */ - -/** - * 异步方法 - * - * uni-app项目中(vue/nvue)调用示例: - * 1、引入方法声明 import { myApi } from "@/uni_modules/uts-api" - * 2、方法调用 - * myApi({ - * paramA: false, - * complete: (res) => { - * console.log(res) - * } - * }); - * - */ -export const myApi : MyApi = function (options : MyApiOptions) { - - if (options.paramA == true) { - // 返回数据 - const res : MyApiResult = { - fieldA: 85, - fieldB: true, - fieldC: 'some message' - }; - options.success?.(res); - options.complete?.(res); - - } else { - // 返回错误 - let failResult = new MyApiFailImpl(9010001); - options.fail?.(failResult) - options.complete?.(failResult) - } - -} - -/** - * 同步方法 - * - * uni-app项目中(vue/nvue)调用示例: - * 1、引入方法声明 import { myApiSync } from "@/uni_modules/uts-api" - * 2、方法调用 - * myApiSync(true); - * - */ -export const myApiSync : MyApiSync = function (paramA : boolean) : MyApiResult { - // 返回数据,根据插件功能获取实际的返回值 - const res : MyApiResult = { - fieldA: 85, - fieldB: paramA, - fieldC: 'some message' - }; - return res; -} - -/** - * 更多插件开发的信息详见:https://uniapp.dcloud.net.cn/plugin/uts-plugin.html - */