提交 24f0ec42 编写于 作者: DCloud-yyl's avatar DCloud-yyl

同步代码@HBuilderX4.21

上级 d38d3d80
......@@ -61,14 +61,16 @@ export interface Uni {
* "android": {
* "osVer": "5.0",
* "uniVer": "3.8.15",
* "uniUtsPlugin": "3.9.0",
* "unixVer": "3.9.0",
* "utsPlugin": "3.9.0"
* "unixUtsPlugin": "3.9.0"
* },
* "ios": {
* "osVer": "x",
* "uniVer": "x",
* "uniUtsPlugin": "x",
* "unixVer": "x",
* "utsPlugin": "x"
* "unixUtsPlugin": "x"
* }
* },
* "web": {
......
......@@ -37,7 +37,7 @@
"getFileSystemManager": {
"name": "getFileSystemManager",
"app": {
"js": false,
"js": true,
"kotlin": true,
"swift": false
}
......
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<string, File> = 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);
......
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,12 +1727,31 @@ 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 (_) {
let is:InputStream;
let targetPath = UTSAndroid.convert2AbsFullPath(options.targetPath)
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 UniError(UniErrorSubject, 1300013, UniErrors.get(1300013)! + ":" + options.zipFilePath);
let err = new FileSystemManagerFailImpl(1300013);
options.fail?.(err)
options.complete?.(err)
}, null)
......@@ -1743,19 +1763,18 @@ class AndroidFileSystemManager implements FileSystemManager {
* 文件不存在
*/
currentDispatcher.async(function (_) {
let err = new UniError(UniErrorSubject, 1300002, UniErrors.get(1300002)! + ":" + options.zipFilePath);
let err = new FileSystemManagerFailImpl(1300002);
options.fail?.(err)
options.complete?.(err)
}, null)
return
}
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);
let err = new FileSystemManagerFailImpl(1300013);
options.fail?.(err)
options.complete?.(err)
}, null)
......@@ -1764,18 +1783,17 @@ class AndroidFileSystemManager implements FileSystemManager {
}
if (!targetFile.exists() || !targetFile.isDirectory()) {
currentDispatcher.async(function (_) {
let err = new UniError(UniErrorSubject, 1300002, UniErrors.get(1300002)! + ":" + options.zipFilePath);
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,15 +1949,35 @@ class AndroidFileSystemManager implements FileSystemManager {
readCompressedFile(options : ReadCompressedFileOptions) {
let currentDispatcher = UTSAndroid.getDispatcher("main")
UTSAndroid.getDispatcher('io').async(function (_) {
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 UniError(UniErrorSubject, 1300002, UniErrors.get(1300002)! + ":" + filePath);
let err = new FileSystemManagerFailImpl(1300002);
options.fail?.(err)
options.complete?.(err)
}, null)
......@@ -1947,22 +1985,22 @@ class AndroidFileSystemManager implements FileSystemManager {
}
if (options.compressionAlgorithm != 'br') {
currentDispatcher.async(function (_) {
let err = new UniError(UniErrorSubject, 1301111, UniErrors.get(1301111)! + ":" + filePath);
let err = new FileSystemManagerFailImpl(1301111);
options.fail?.(err)
options.complete?.(err)
}, null)
return
}
let success : ReadCompressedFileResult = {
data: ""
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 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(UniErrorSubject, 1300002, msgPrefix + UniErrors.get(1300002)!)
throw new UniError(FileSystemManagerUniErrorSubject, 1300002, msgPrefix + FileSystemManagerUniErrors.get(1300002)!)
}
if (compressionAlgorithm != 'br') {
throw new UniError(UniErrorSubject, 1301111, msgPrefix + UniErrors.get(1301111)!)
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)
}
......
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)
})
......
......@@ -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,
/**
......@@ -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 {
......@@ -1782,3 +1809,25 @@ export interface Uni {
*/
getFileSystemManager() : FileSystemManager
}
/**
* 错误码
* - 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
};
import { FileSystemManagerErrorCode,IFileSystemManagerFail } from "./interface.uts"
/**
* 错误主题
*/
export const UniErrorSubject = 'uni-fileSystemManager';
export const FileSystemManagerUniErrorSubject = 'uni-fileSystemManager';
/**
* 错误码
* @UniError
*/
export const UniErrors : Map<number, string> = new Map([
export const FileSystemManagerUniErrors : Map<FileSystemManagerErrorCode, string> = new Map([
[1200002, 'type error. only support base64 / utf-8'],
[1300002, 'no such file or directory'],
......@@ -23,3 +25,11 @@ export const UniErrors : Map<number, string> = new Map([
[1302003, 'invalid flag'],
[1300009, 'bad file descriptor']
]);
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
......@@ -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,7 +89,7 @@ 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
* {
......@@ -112,7 +113,7 @@ 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
* {
......@@ -135,7 +136,7 @@ export type GetAppAuthorizeSettingResult = {
* 定位准确度。
* - reduced: 模糊定位
* - full: 精准定位
* - unsupported: 不支持(包括用户拒绝定位权限和没有在 `manifest.json -> App模块配置` 中配置 `Geolocation(定位)` 模块
* - unsupported: 不支持(包括用户拒绝定位权限和没有包含定位权限描述
* @type 'reduced' | 'full' | 'unsupported'
* @uniPlatform
* {
......@@ -179,7 +180,7 @@ 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
* {
......@@ -203,7 +204,7 @@ 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
* {
......@@ -227,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
* {
......@@ -251,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
* {
......@@ -275,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
* {
......
......@@ -39,7 +39,8 @@ export const getAppBaseInfo : GetAppBaseInfo = (config : GetAppBaseInfoOptions |
"uniCompilerVersionCode",
"uniRuntimeVersionCode",
"packageName",
"signature"
"signature",
"appTheme",
];
filter = defaultFilter;
}
......@@ -136,6 +137,10 @@ function getBaseInfo(filterArray : Array<string>) : GetAppBaseInfoResult {
result.signature = AppBaseInfoDeviceUtil.getAppSignatureSHA1(activity);
}
if (filterArray.indexOf("appTheme") != -1) {
result.appTheme = UTSAndroid.getAppTheme();
}
return result;
}
......
......@@ -35,7 +35,8 @@ export const getAppBaseInfo : GetAppBaseInfo = (config : GetAppBaseInfoOptions |
"uniPlatform",
"uniRuntimeVersion",
"uniCompilerVersionCode",
"uniRuntimeVersionCode"
"uniRuntimeVersionCode",
"appTheme",
];
filter = defaultFilter;
}
......@@ -117,6 +118,10 @@ function getBaseInfo(filterArray : Array<string>) : GetAppBaseInfoResult {
result.uniRuntimeVersionCode = AppBaseInfoConvertVersionCode(UTSiOS.getRuntimeVersion());
}
if (filterArray.indexOf("appTheme") != -1) {
result.appTheme = UTSiOS.getAppTheme();
}
return result;
}
......
......@@ -22,6 +22,10 @@ export type GetAppBaseInfoResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -42,6 +46,10 @@ export type GetAppBaseInfoResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -62,6 +70,10 @@ export type GetAppBaseInfoResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -82,6 +94,10 @@ export type GetAppBaseInfoResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -102,6 +118,10 @@ export type GetAppBaseInfoResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -122,6 +142,10 @@ export type GetAppBaseInfoResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -143,6 +167,10 @@ export type GetAppBaseInfoResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "x",
* "unixVer": "x"
* }
* }
*/
......@@ -331,6 +359,10 @@ export type GetAppBaseInfoResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "x",
* "unixVer": "4.18"
* }
* }
*/
......@@ -353,6 +385,10 @@ export type GetAppBaseInfoResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "x",
* "unixVer": "x"
* }
* }
*/
......@@ -375,8 +411,8 @@ export type GetAppBaseInfoResult = {
* }
* },
* "web": {
* "uniVer": "",
* "unixVer": "4.0"
* "uniVer": "x",
* "unixVer": "4.18"
* }
* }
*/
......@@ -397,6 +433,10 @@ export type GetAppBaseInfoResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -417,6 +457,10 @@ export type GetAppBaseInfoResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "x",
* "unixVer": "4.18"
* }
* }
*/
......@@ -438,6 +482,10 @@ export type GetAppBaseInfoResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "x",
* "unixVer": "x"
* }
* }
*/
......@@ -460,8 +508,8 @@ export type GetAppBaseInfoResult = {
* }
* },
* "web": {
* "uniVer": "",
* "unixVer": "4.0"
* "uniVer": "x",
* "unixVer": "4.18"
* }
* }
*/
......@@ -482,6 +530,10 @@ export type GetAppBaseInfoResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "x",
* "unixVer": "x"
* }
* }
*/
......@@ -559,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,
}
/**
......
......@@ -216,6 +216,15 @@ export class DeviceUtil {
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 ?? "";
}
/**
* 是否为平板 不是太准确
......
......@@ -89,12 +89,7 @@ function getBaseInfo(filterArray : Array<string>) : GetDeviceInfoResult {
result.osLanguage = UTSiOS.getOsLanguage();
}
if (filterArray.indexOf("osTheme") != -1) {
let osTheme = 'light'
if(UTSiOS.available("iOS 13, *")){
let currentTraitCollection = UIApplication.shared.keyWindow?.traitCollection
osTheme = currentTraitCollection?.userInterfaceStyle == UIUserInterfaceStyle.dark ? "dark" : "light"
}
result.osTheme = osTheme;
result.osTheme = UTSiOS.getOsTheme();
}
if (filterArray.indexOf("romName") != -1) {
result.romName = "ios"
......
......@@ -3,9 +3,9 @@ export type GetDeviceInfoOptions = {
* @description 过滤字段的字符串数组,假如要获取指定字段,传入此数组。
*/
filter: Array<string>
}
}
export type GetDeviceInfoResult = {
export type GetDeviceInfoResult = {
/**
* 设备品牌
* @deprecated 已废弃,仅为了向下兼容保留
......@@ -23,6 +23,10 @@ export type GetDeviceInfoResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "x",
* "unixVer": "x"
* }
* }
*/
......@@ -43,6 +47,10 @@ export type GetDeviceInfoResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "x",
* "unixVer": "x"
* }
* }
*/
......@@ -63,6 +71,10 @@ export type GetDeviceInfoResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -84,6 +96,10 @@ export type GetDeviceInfoResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -104,6 +120,10 @@ export type GetDeviceInfoResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -124,6 +144,10 @@ export type GetDeviceInfoResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -144,6 +168,10 @@ export type GetDeviceInfoResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -164,6 +192,10 @@ export type GetDeviceInfoResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -184,6 +216,10 @@ export type GetDeviceInfoResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -204,12 +240,16 @@ export type GetDeviceInfoResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
platform?: string,
/**
* 是否root
* 是否root。iOS 为是否越狱
*
* @uniPlatform
* {
......@@ -224,6 +264,10 @@ export type GetDeviceInfoResult = {
* "uniVer": "x",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "x",
* "unixVer": "x"
* }
* }
*/
......@@ -244,6 +288,10 @@ export type GetDeviceInfoResult = {
* "uniVer": "x",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "x",
* "unixVer": "x"
* }
* }
*/
......@@ -264,20 +312,192 @@ export type GetDeviceInfoResult = {
* "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 type GetDeviceInfo = (options?: GetDeviceInfoOptions | null) => GetDeviceInfoResult;
export interface Uni {
export interface Uni {
/**
* GetDeviceInfo(Object object)
* @description
......@@ -312,4 +532,5 @@ export interface Uni {
```
*/
getDeviceInfo(options?: GetDeviceInfoOptions | null): GetDeviceInfoResult;
}
}
\ No newline at end of file
......@@ -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
......
......@@ -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
}
......@@ -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);
......
export type GetProviderSuccess = {
/**
* 服务类型
* - oauth: 授权登录
* - share: 分享
* - payment: 支付
* - push: 推送
* - location: 定位
* @type 'oauth' | 'share' | 'payment' | 'push' | 'location'
* @type 'payment'
*/
service: 'oauth' | 'share' | 'payment' | 'push' | 'location',
service : 'payment',
/**
* 得到的服务供应商
* @type PlusShareShareService['id'][] | PlusPushClientInfo['id'][] | PlusOauthAuthService['id'][] | PlusPaymentPaymentChannel['id'][]
*/
provider: string[],
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
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'
* 服务类型,可取值“payment”
* - payment: 支付 (Alipay、Wxpay)
* @type 'payment'
*/
service: 'oauth' | 'share' | 'payment' | 'push' | 'location',
service : 'payment',
/**
* 接口调用成功的回调
*/
success?: GetProviderSuccessCallback | null,
success ?: GetProviderSuccessCallback | null,
/**
* 接口调用失败的回调函数
*/
fail?: GetProviderFailCallback | null,
fail ?: GetProviderFailCallback | null,
/**
* 接口调用结束的回调函数(调用成功、失败都会执行)
*/
complete?: GetProviderCompleteCallback | null
complete ?: GetProviderCompleteCallback | null
};
export type GetProvider = (options: GetProviderOptions) => void;
export type GetProvider = (options : GetProviderOptions) => void;
export interface Uni {
/**
......@@ -67,12 +81,12 @@ export interface Uni {
* "ios": {
* "osVer": "9.0",
* "uniVer": "√",
* "unixVer": "x"
* "unixVer": "4.18"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.05"
* "uniVer": "x",
* "unixVer": "x"
* }
* }
* @example
......@@ -80,5 +94,5 @@ export interface Uni {
uni.getProvider({service: ''})
```
*/
getProvider(options: GetProviderOptions) : void;
getProvider(options : GetProviderOptions) : void;
}
......@@ -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) {
......
......@@ -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;
}
......
......@@ -126,6 +126,10 @@ export type SafeArea = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -146,6 +150,10 @@ export type SafeArea = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -166,6 +174,10 @@ export type SafeArea = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -186,6 +198,10 @@ export type SafeArea = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -206,6 +222,10 @@ export type SafeArea = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -226,6 +246,10 @@ export type SafeArea = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -233,7 +257,7 @@ export type SafeArea = {
};
export type SafeAreaInsets = {
/**
* 安全区域左侧插入位置,单位为px
* 安全区域左侧插入位置(距离左边边界距离),单位为px
*
* @uniPlatform
* {
......@@ -248,12 +272,16 @@ export type SafeAreaInsets = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
left: number,
/**
* 安全区域右侧插入位置,单位为px
* 安全区域右侧插入位置(距离右边边界距离),单位为px
*
* @uniPlatform
* {
......@@ -268,12 +296,16 @@ export type SafeAreaInsets = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
right: number,
/**
* 安全区顶部插入位置,单位为px
* 安全区顶部插入位置(距离顶部边界距离),单位为px
*
* @uniPlatform
* {
......@@ -288,12 +320,16 @@ export type SafeAreaInsets = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
top: number,
/**
* 安全区域底部插入位置,单位为px
* 安全区域底部插入位置(距离底部边界距离),单位为px
*
* @uniPlatform
* {
......@@ -308,6 +344,10 @@ export type SafeAreaInsets = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -330,6 +370,10 @@ export type GetSystemInfoResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "x",
* "unixVer": "x"
* }
* }
*/
......@@ -350,6 +394,10 @@ export type GetSystemInfoResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -370,6 +418,10 @@ export type GetSystemInfoResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -390,6 +442,10 @@ export type GetSystemInfoResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -410,6 +466,10 @@ export type GetSystemInfoResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -430,6 +490,10 @@ export type GetSystemInfoResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -450,6 +514,10 @@ export type GetSystemInfoResult = {
* "uniVer": "√",
* "unixVer": "x"
* }
* },
* "web": {
* "uniVer": "x",
* "unixVer": "x"
* }
* }
*/
......@@ -471,6 +539,10 @@ export type GetSystemInfoResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "x",
* "unixVer": "x"
* }
* }
*/
......@@ -491,6 +563,10 @@ export type GetSystemInfoResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -511,6 +587,10 @@ export type GetSystemInfoResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -531,6 +611,10 @@ export type GetSystemInfoResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -551,6 +635,10 @@ export type GetSystemInfoResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -571,6 +659,10 @@ export type GetSystemInfoResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -591,6 +683,10 @@ export type GetSystemInfoResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -611,6 +707,10 @@ export type GetSystemInfoResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -632,6 +732,10 @@ export type GetSystemInfoResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -653,6 +757,10 @@ export type GetSystemInfoResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -674,6 +782,10 @@ export type GetSystemInfoResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -694,10 +806,14 @@ export type GetSystemInfoResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
osName: 'ios' | 'android' | 'mac' | 'windows' | 'linux',
osName: 'ios' | 'android' | 'macos' | 'windows' | 'linux',
/**
* 操作系统版本。如 ios 版本,andriod 版本
*
......@@ -714,6 +830,10 @@ export type GetSystemInfoResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -734,6 +854,10 @@ export type GetSystemInfoResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -754,6 +878,10 @@ export type GetSystemInfoResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "x",
* "unixVer": "x"
* }
* }
*/
......@@ -775,6 +903,10 @@ export type GetSystemInfoResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -796,6 +928,10 @@ export type GetSystemInfoResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -816,6 +952,10 @@ export type GetSystemInfoResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -836,6 +976,10 @@ export type GetSystemInfoResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -856,6 +1000,10 @@ export type GetSystemInfoResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -877,6 +1025,10 @@ export type GetSystemInfoResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -897,6 +1049,10 @@ export type GetSystemInfoResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -917,6 +1073,10 @@ export type GetSystemInfoResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -937,6 +1097,10 @@ export type GetSystemInfoResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -958,6 +1122,10 @@ export type GetSystemInfoResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -978,6 +1146,10 @@ export type GetSystemInfoResult = {
* "uniVer": "x",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "x",
* "unixVer": "4.18"
* }
* }
*/
......@@ -998,6 +1170,10 @@ export type GetSystemInfoResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -1018,6 +1194,10 @@ export type GetSystemInfoResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -1039,6 +1219,10 @@ export type GetSystemInfoResult = {
* "uniVer": "x",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -1059,6 +1243,10 @@ export type GetSystemInfoResult = {
* "uniVer": "x",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "x",
* "unixVer": "4.18"
* }
* }
*/
......@@ -1079,6 +1267,10 @@ export type GetSystemInfoResult = {
* "uniVer": "x",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -1100,6 +1292,10 @@ export type GetSystemInfoResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -1120,6 +1316,10 @@ export type GetSystemInfoResult = {
* "uniVer": "x",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "x",
* "unixVer": "x"
* }
* }
*/
......@@ -1140,6 +1340,10 @@ export type GetSystemInfoResult = {
* "uniVer": "x",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "x",
* "unixVer": "x"
* }
* }
*/
......@@ -1160,6 +1364,10 @@ export type GetSystemInfoResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -1180,6 +1388,10 @@ export type GetSystemInfoResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -1200,6 +1412,10 @@ export type GetSystemInfoResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -1220,6 +1436,10 @@ export type GetSystemInfoResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -1240,10 +1460,38 @@ export type GetSystemInfoResult = {
* "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"
* }
* }
*/
osAndroidAPILevel?: number | null
appTheme?: 'light' | 'dark' | 'auto' | null,
};
export type GetSystemInfoSuccessCallback = (result: GetSystemInfoResult) => void;
type GetSystemInfoFail = UniError;
......@@ -1285,6 +1533,10 @@ export type GetWindowInfoResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -1305,6 +1557,10 @@ export type GetWindowInfoResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -1325,6 +1581,10 @@ export type GetWindowInfoResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -1345,6 +1605,10 @@ export type GetWindowInfoResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -1385,6 +1649,10 @@ export type GetWindowInfoResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -1405,6 +1673,10 @@ export type GetWindowInfoResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -1425,12 +1697,16 @@ export type GetWindowInfoResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
windowBottom: number,
/**
* 在竖屏正方向下的安全区域
* 安全区域在屏幕中的位置信息
*
* @uniPlatform
* {
......@@ -1445,12 +1721,16 @@ export type GetWindowInfoResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
safeArea: SafeArea,
/**
* 在竖屏正方向下的安全区域插入位置
* 安全区域插入位置(与屏幕边界的距离)信息
*
* @uniPlatform
* {
......@@ -1465,6 +1745,10 @@ export type GetWindowInfoResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -1485,6 +1769,10 @@ export type GetWindowInfoResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......
......@@ -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<string> = [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)
......
import { ChooseImageOptions, ChooseVideoOptions } from "./interface.uts"
import { ChooseImageOptions, ChooseVideoOptions } from "../../interface.uts"
import {
UniError_ChooseImage, UniError_ChooseVideo, MediaErrorImpl
} from "./unierror.uts"
} from "../../unierror.uts"
export const CODE_CAMERA_ERROR = 11;
export const CODE_GALLERY_ERROR = 12;
export const CODE_GET_IMAGE_INFO_CODE = 13
......
......@@ -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';
......
......@@ -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)
......
......@@ -8,32 +8,32 @@
<key>BinaryPath</key>
<string>DCloudMediaPicker.framework/DCloudMediaPicker</string>
<key>LibraryIdentifier</key>
<string>ios-arm64</string>
<string>ios-arm64_x86_64-simulator</string>
<key>LibraryPath</key>
<string>DCloudMediaPicker.framework</string>
<key>SupportedArchitectures</key>
<array>
<string>arm64</string>
<string>x86_64</string>
</array>
<key>SupportedPlatform</key>
<string>ios</string>
<key>SupportedPlatformVariant</key>
<string>simulator</string>
</dict>
<dict>
<key>BinaryPath</key>
<string>DCloudMediaPicker.framework/DCloudMediaPicker</string>
<key>LibraryIdentifier</key>
<string>ios-arm64_x86_64-simulator</string>
<string>ios-arm64</string>
<key>LibraryPath</key>
<string>DCloudMediaPicker.framework</string>
<key>SupportedArchitectures</key>
<array>
<string>arm64</string>
<string>x86_64</string>
</array>
<key>SupportedPlatform</key>
<string>ios</string>
<key>SupportedPlatformVariant</key>
<string>simulator</string>
</dict>
</array>
<key>CFBundlePackageType</key>
......
......@@ -28,6 +28,10 @@
<data>
nghJYGVbKFhvAi/+2XYvdy408is=
</data>
<key>PrivacyInfo.xcprivacy</key>
<data>
L50owgIQfV6zTzg7T11NlSDYSZU=
</data>
</dict>
<key>files2</key>
<dict>
......@@ -86,6 +90,17 @@
M9nMA2y1DqhJFLOymGCa66mNVw5qDN8J1QzcxQD3H/w=
</data>
</dict>
<key>PrivacyInfo.xcprivacy</key>
<dict>
<key>hash</key>
<data>
L50owgIQfV6zTzg7T11NlSDYSZU=
</data>
<key>hash2</key>
<data>
NOpzMYrYXZEAI4Xdo9XJX+tflymAvdW2UHdZwen1+iU=
</data>
</dict>
</dict>
<key>rules</key>
<dict>
......
......@@ -3,12 +3,14 @@ import {
PreviewImageOptions, PreviewImage, PreviewImageSuccess,
ClosePreviewImage, ClosePreviewImageSuccess, ClosePreviewImageOptions,
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<string, any> = 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<AnyHashable, any>) : 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<AnyHashable, any>) : void => {
if (this.mediaAlbum == null){
this.mediaAlbum = new DCloudMediaAlbum();
}
this.mediaAlbum?.start(options, success = (response : Map<AnyHashable, any>) : 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<string, any> = 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<AnyHashable, any>) : 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<string, any> = 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<AnyHashable, any>) : void => {
if (this.mediaCamera == null){
this.mediaCamera = new DCloudMediaCamera();
}
this.mediaCamera?.start(options, success = (response : Map<AnyHashable, any>) : 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,7 +336,10 @@ 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 }
......@@ -196,6 +348,23 @@ class DCUniMediaPicker {
}
}
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) {
let cameraAuthorized = AVCaptureDevice.authorizationStatus(for=AVMediaType.video)
......@@ -335,3 +504,34 @@ export const saveImageToPhotosAlbum : SaveImageToPhotosAlbum = function (options
}
})
}
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
......@@ -5,8 +5,10 @@
<key>NSCameraUsageDescription</key>
<string>APP需要您的同意,才能使用摄像头,以便于相机拍摄</string>
<key>NSPhotoLibraryAddUsageDescription</key>
<string>APP需要您的同意,才能访问相册,以便于保存图</string>
<string>APP需要您的同意,才能访问相册,以便于保存图</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>APP需要您的同意,才能访问相册,以便于图片选取</string>
<string>APP需要您的同意,才能访问相册,以便于图像选取</string>
<key>NSMicrophoneUsageDescription</key>
<string>APP需要您的同意,才能使用麦克风,以便于录制音频</string>
</dict>
</plist>
\ No newline at end of file
......@@ -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,6 +794,10 @@ export interface Uni {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
* @uniVueVersion 2,3
......@@ -721,10 +821,14 @@ 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
......@@ -754,7 +858,7 @@ export interface Uni {
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "4.4",
* "osVer": "5.0",
* "uniVer": "√",
* "unixVer": "3.9+"
* },
......@@ -763,6 +867,10 @@ export interface Uni {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "x",
* "unixVer": "x"
* }
* }
* @uniVueVersion 2,3
......@@ -792,10 +900,14 @@ 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
......@@ -826,10 +938,19 @@ 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
......@@ -851,10 +972,14 @@ 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
......@@ -877,10 +1002,19 @@ 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
......@@ -903,10 +1037,14 @@ 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
......
......@@ -23,9 +23,6 @@ export const setNavigationBarColor = defineAsyncApi<
}
const appPage = page.$nativePage
appPage!.updateStyle(
new Map<string, any | null>([
[
'navigationBar',
new Map<string, any | null>([
[
'navigationBarTextStyle',
......@@ -36,8 +33,6 @@ export const setNavigationBarColor = defineAsyncApi<
options.backgroundColor,
],
]),
],
]),
)
res.resolve(null)
},
......@@ -56,14 +51,9 @@ export const setNavigationBarTitle = defineAsyncApi<
}
const appPage = page.$nativePage
appPage!.updateStyle(
new Map<string, any | null>([
[
'navigationBar',
new Map<string, any | null>([
['navigationBarTitleText', options.title],
]),
],
]),
)
res.resolve(null)
},
......
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<T> extends NetworkRequestListener {
private param : RequestOptions<T> | null = null;
private headers : Map<string, any> | null = null;
private received : number = 0;
private data : Data = new Data();
constructor(param : RequestOptions) {
constructor(param : RequestOptions<T>) {
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<T>({
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);
......@@ -108,13 +117,15 @@ 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")) {
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<Any>.Type") {
if (parseType != null && parseType!.contains("json")) {
if (dataStr == null || dataStr!.length == 0) {
return {};
}
return this.parseJson(dataStr!);
} else if (type == 'jsonp') {
return JSON.parse(dataStr!);
} else if (parseType == 'jsonp') {
if (dataStr == null || dataStr!.length == 0) {
return {};
}
......@@ -125,7 +136,7 @@ class SimpleNetworkListener extends NetworkRequestListener {
}
start += 1;
let tmp = dataStr!.slice(start, end);
return this.parseJson(tmp);
return JSON.parse(tmp);
} else {
//dataStr如果解码失败是空的时候,还需要继续尝试解码。极端情况,服务器不是utf8的,所以字符解码会出现乱码,所以特殊处理一下非utf8的字符。
if (data == null) {
......@@ -141,17 +152,22 @@ class SimpleNetworkListener extends NetworkRequestListener {
// }
// }
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;
}
} else {
if (dataStr == null || dataStr!.length == 0) {
return null;
}
return JSON.parse<T>(dataStr!)
}
private parseJson(str : string) : any | null {
return JSON.parse(str);
}
private parseCookie(header : Map<string, any> | null) : string[] {
......@@ -293,11 +309,11 @@ class DownloadNetworkListener implements NetworkDownloadFileListener {
}
}
onFinished(response : HTTPURLResponse, filePath: string) : void {
onFinished(response : HTTPURLResponse, filePath : string) : void {
try {
let kParam = this.options;
let tmp : DownloadFileSuccess = {
tempFilePath:filePath,
tempFilePath: filePath,
statusCode: response.statusCode
};
let success = kParam?.success;
......@@ -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<T>(options : RequestOptions<T>, _t : T.Type) : RequestTask {
return NetworkManager.getInstance().request(options, new SimpleNetworkListener<T>(options));
}
export const uploadFile : UploadFile = (options : UploadFileOptions) : UploadTask => {
return NetworkManager.getInstance().uploadFile(options, new UploadNetworkListener(options));
}
......
export type Request = (param: RequestOptions) => RequestTask;
export type Request<T> = (param: RequestOptions<T>) => RequestTask;
/**
* 网络请求参数
*/
export type RequestOptions = {
export type RequestOptions<T> = {
/**
* 开发者服务器接口地址
*/
......@@ -80,7 +80,7 @@ export type RequestOptions = {
* 网络请求成功回调。
* @defaultValue null
*/
success?: RequestSuccessCallback | null,
success?: RequestSuccessCallback<T> | null,
/**
* 网络请求失败回调。
* @defaultValue null
......@@ -93,12 +93,12 @@ export type RequestOptions = {
complete?: RequestCompleteCallback | null
}
export type RequestSuccess = {
export type RequestSuccess<T> = {
/**
* 开发者服务器返回的数据
* @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<T> = (option: RequestSuccess<T>) => 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<T>(param: RequestOptions<T>): 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;
}
......@@ -60,7 +60,7 @@ class NetworkManager implements URLSessionDataDelegate {
}
public request(param : RequestOptions, listener : NetworkRequestListener) : RequestTask {
public request<T>(param : RequestOptions<T>, listener : NetworkRequestListener) : RequestTask {
let request = this.createRequest(param);
if (request == null) {
let error = new NSError(domain = "invalid URL", code = 600009);
......@@ -91,8 +91,9 @@ class NetworkManager implements URLSessionDataDelegate {
}
public createRequest(param : RequestOptions) : URLRequest | null {
let url = new URL(string = param.url);
public createRequest<T>(param : RequestOptions<T>) : URLRequest | null {
const encodeUrl = this.percentEscapedString(param.url)
let url = new URL(string = encodeUrl);
if (url == null) {
return null
}
......@@ -150,8 +151,8 @@ class NetworkManager implements URLSessionDataDelegate {
json = data as UTSJSONObject;
}
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;
}
}
......@@ -239,6 +240,11 @@ class NetworkManager implements URLSessionDataDelegate {
return newUrl;
}
private percentEscapedString(str: string): string {
//如果url已经有部分经过encode,那么需要先decode再encode。
return str.removingPercentEncoding?.addingPercentEncoding(withAllowedCharacters= CharacterSet.urlQueryAllowed) ?? str
}
//mark --- URLSessionDataDelegate
......
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";
......@@ -66,7 +66,8 @@ export class DownloadController implements URLSessionDownloadDelegate {
}
private createDownloadRequest(options : DownloadFileOptions, listener : NetworkDownloadFileListener) : URLRequest | null {
let url = new URL(string = options.url);
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);
......@@ -99,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 {
const strData = param.data(using = String.Encoding.utf8)!
let digest = new Array<UInt8>(repeating = 0, count = new Int(CC_MD5_DIGEST_LENGTH))
......
......@@ -68,7 +68,8 @@ class UploadController implements URLSessionDataDelegate {
private createRequest(param : UploadFileOptions, listener : NetworkUploadFileListener, boundary : string) : URLRequest | null {
let url = new URL(string = param.url);
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);
......@@ -157,6 +158,12 @@ class UploadController implements URLSessionDataDelegate {
}
private percentEscapedString(str: string): string {
//如果url已经有部分经过encode,那么需要先decode再encode。
return str.removingPercentEncoding?.addingPercentEncoding(withAllowedCharacters= CharacterSet.urlQueryAllowed) ?? str
}
private fillTextPart(body : NSMutableData, boundary : string, key : string, value : string) {
body.append(`--${boundary}\r\n`.data(using = String.Encoding.utf8)!)
body.append(`Content-Disposition: form-data; name=\"${key}\"\r\n`.data(using = String.Encoding.utf8)!)
......
......@@ -20,6 +20,10 @@ export type RequestOptions<T> = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -41,6 +45,10 @@ export type RequestOptions<T> = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -61,6 +69,10 @@ export type RequestOptions<T> = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -83,6 +95,10 @@ export type RequestOptions<T> = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -168,6 +184,10 @@ export type RequestOptions<T> = {
* "uniVer": "√",
* "unixVer": "x"
* }
* },
* "web": {
* "uniVer": "x",
* "unixVer": "x"
* }
* }
*/
......@@ -206,6 +226,10 @@ export type RequestSuccess<T> = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -225,6 +249,10 @@ export type RequestSuccess<T> = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -244,6 +272,10 @@ export type RequestSuccess<T> = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -263,6 +295,10 @@ export type RequestSuccess<T> = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "x",
* "unixVer": "x"
* }
* }
*/
......@@ -363,6 +399,10 @@ export type UploadFileOptionFiles = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -382,6 +422,10 @@ export type UploadFileOptionFiles = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "x",
* "unixVer": "x"
* }
* }
*/
......@@ -426,6 +470,10 @@ export type UploadFileSuccess = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -445,6 +493,10 @@ export type UploadFileSuccess = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -476,6 +528,10 @@ export type UploadFileOptions = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -496,6 +552,10 @@ export type UploadFileOptions = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -516,6 +576,10 @@ export type UploadFileOptions = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -536,6 +600,10 @@ export type UploadFileOptions = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -556,6 +624,10 @@ export type UploadFileOptions = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -576,6 +648,10 @@ export type UploadFileOptions = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -596,6 +672,10 @@ export type UploadFileOptions = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -632,6 +712,10 @@ export type OnProgressUpdateResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -651,6 +735,10 @@ export type OnProgressUpdateResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -670,6 +758,10 @@ export type OnProgressUpdateResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -771,6 +863,10 @@ export type DownloadFileSuccess = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -790,6 +886,10 @@ export type DownloadFileSuccess = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -821,6 +921,10 @@ export type DownloadFileOptions = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -866,6 +970,10 @@ export type DownloadFileOptions = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -886,6 +994,10 @@ export type DownloadFileOptions = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -922,6 +1034,10 @@ export type OnProgressDownloadResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -941,6 +1057,10 @@ export type OnProgressDownloadResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......@@ -960,6 +1080,10 @@ export type OnProgressDownloadResult = {
* "uniVer": "√",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
......
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<number, number> = 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) {
......
import { Alipay } from './Alipay.uts'
export const requestPayment : RequestPayment = function (options : RequestPaymentOptions) {
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)
};
\ No newline at end of file
}
}
import { UTSiOSHookProxy } from "DCloudUniappRuntime";
import { UIApplication } from "UIKit"
import { AlipaySDK } from "AlipaySDK"
import { URL, NSUserActivity, NSUserActivityTypeBrowsingWeb } from "Foundation"
const defaultErrorCode : number = 700716;
const errorCodeMap : Map<string, number> = new Map([
['8000', 700710],
['4000', 700711],
['5000', 700712],
['6001', 700713],
['6002', 700714],
['6004', 700715]
]);
export class Alipay implements UTSiOSHookProxy {
options ?: RequestPaymentOptions
// 通过 url scheme 方式唤起 app 时的回调函数。
applicationOpenURLOptions(app : UIApplication | null, url : URL, options : Map<UIApplication.OpenURLOptionsKey, any> | null = null) : boolean {
if (url.host == 'safepay') {
AlipaySDK.defaultService().processOrder(withPaymentResult = url, standbyCallback = (resultDic ?: Map<AnyHashable, any>) : void => {
this.handlePaymentResult(resultDic)
})
}
return true
}
// 当应用程序接收到与用户活动相关的数据时调用此方法,例如,当用户使用 Universal Link 唤起应用时。
applicationContinueUserActivityRestorationHandler(application : UIApplication | null, userActivity : NSUserActivity | null, restorationHandler : ((res : [any] | null) => void) | null = null) : boolean {
if (userActivity?.activityType == NSUserActivityTypeBrowsingWeb) {
AlipaySDK.defaultService().handleOpenUniversalLink(userActivity, standbyCallback = (resultDic ?: Map<AnyHashable, any>) : void => {
this.handlePaymentResult(resultDic)
})
}
return true
}
requestPayment(options : RequestPaymentOptions) {
this.options = options
AlipaySDK.defaultService().payOrder(options.orderInfo, fromScheme = "uniAlipay", fromUniversalLink = "", callback = (resultDic ?: Map<AnyHashable, any>) : void => {
this.handlePaymentResult(resultDic)
})
}
handlePaymentResult(resultDic ?: Map<AnyHashable, any>) {
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
}
this.options?.success?.(res)
this.options?.complete?.(res)
} else {
let code = errorCodeMap[resultStatus];
if (code == null) {
code = defaultErrorCode
}
let err = new RequestPaymentFailImpl(code!);
this.options?.fail?.(err)
this.options?.complete?.(err)
}
}
}
\ No newline at end of file
......@@ -12,6 +12,26 @@
"CFNetwork.framework",
"CoreMotion.framework"
],
"deploymentTarget": "12.0"
"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
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<string, number> = 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<UIApplication.OpenURLOptionsKey, any> | 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<AnyHashable, any>) : void => {
this.handlePaymentResult(resultDic)
})
}
}
@UTSiOS.keyword("fileprivate")
handleOpenUniversalLink(userActivity : NSUserActivity | null) {
if (userActivity?.activityType == NSUserActivityTypeBrowsingWeb) {
AlipaySDK.defaultService().handleOpenUniversalLink(userActivity, standbyCallback = (resultDic ?: Map<AnyHashable, any>) : void => {
this.handlePaymentResult(resultDic)
})
}
}
private payOrder() {
AlipaySDK.defaultService().payOrder(this.options?.orderInfo, fromScheme = this.getApplicationScheme(), fromUniversalLink = this.getApplicationUniversalLink(), callback = (resultDic ?: Map<AnyHashable, any>) : 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<string, any>[] | 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<string, any> | null
if (alipay != null) {
universalLink = alipay!['universalLink'] as string | null
}
}
return universalLink
}
private handlePaymentResult(resultDic ?: Map<AnyHashable, any>) {
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
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>uniAlipay</string>
</array>
</dict>
</array>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>alipays</string>
</array>
</dict>
</plist>
\ No newline at end of file
import { Wxpay } from "./src/Wxpay";
import PackageManager from 'android.content.pm.PackageManager';
export * from './src/WXPayEntryActivity.uts'
export const requestPayment : RequestPayment = function (options : RequestPaymentOptions) {
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)
};
\ No newline at end of file
}
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
......@@ -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<number, number> = new Map([
[-1, 700711],
[-2, 700713]
[-1, 701100],
[-2, 700601]
])
export class WXPayEntryActivity extends Activity implements IWXAPIEventHandler {
constructor() {
......
......@@ -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
......
重要!
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”里增加如下代码:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>weixin</string>
</array>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
2、开发者需要在工程中链接上 CoreTelephony.framework
3、解决bitcode编译不过问题
SDK1.5
1、废弃safeSendReq:接口,使用sendReq:即可。
2、新增+(BOOL) sendAuthReq:(SendAuthReq*) req viewController : (UIViewController*) viewController delegate:(id<WXApiDelegate>) delegate;
支持未安装微信情况下Auth,具体见WXApi.h接口描述
3、微信开放平台新增了微信模块用户统计功能,便于开发者统计微信功能模块的用户使用和活跃情况。开发者需要在工程中链接上:SystemConfiguration.framework,libz.dylib,libsqlite3.0.dylib。
//
// WXApi.h
// 所有Api接口
//
// Created by Wechat on 12-2-28.
// Copyright (c) 2012年 Tencent. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "WXApiObject.h"
NS_ASSUME_NONNULL_BEGIN
typedef BOOL(^WXGrantReadPasteBoardPermissionCompletion)(void);
#pragma mark - WXApiDelegate
/*! @brief 接收并处理来自微信终端程序的事件消息
*
* 接收并处理来自微信终端程序的事件消息,期间微信界面会切换到第三方应用程序。
* WXApiDelegate 会在handleOpenURL:delegate:中使用并触发。
*/
@protocol WXApiDelegate <NSObject>
@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 <NSObject>
- (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<WXApiDelegate>)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<WXApiDelegate>)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<WXApiDelegate>)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<WXApiLogDelegate>)logDelegate;
/*! @brief 停止打印log,会清理block或者delegate为空,释放block
* @param
*/
+ (void)stopLog;
@end
NS_ASSUME_NONNULL_END
//
// MMApiObject.h
// Api对象,包含所有接口和对象数据定义
//
// Created by Wechat on 12-2-28.
// Copyright (c) 2012年 Tencent. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
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
//
// WechatAuthSDK.h
// WechatAuthSDK
//
// Created by 李凯 on 13-11-29.
// Copyright (c) 2013年 Tencent. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
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<NSObject>
@optional
- (void)onAuthGotQrcode:(UIImage *)image; //得到二维码
- (void)onQrcodeScanned; //二维码被扫描
- (void)onAuthFinish:(int)errCode AuthCode:(nullable NSString *)authCode; //成功登录
@end
@interface WechatAuthSDK : NSObject{
NSString *_sdkVersion;
__weak id<WechatAuthAPIDelegate> _delegate;
}
@property(nonatomic, weak, nullable) id<WechatAuthAPIDelegate> 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
import { WXApi, WXApiDelegate, BaseReq, PayReq, PayResp } from "WechatOpenSDK";
import { UTSiOSHookProxy } from "DCloudUniappRuntime";
import { UIApplication } from "UIKit";
import { URL, NSUserActivity } from "Foundation";
const defaultErrorCode : number = 700716
const errorCodeMap : Map<number, number> = new Map([
[-1, 700711],
[-2, 700713]
])
export class Wxpay implements UTSiOSHookProxy, WXApiDelegate {
options ?: RequestPaymentOptions
// 应用正常启动时 (不包括已在后台转到前台的情况)的回调函数。
applicationDidFinishLaunchingWithOptions(application : UIApplication | null, launchOptions : Map<UIApplication.LaunchOptionsKey, any> | null = null) : boolean {
WXApi.registerApp('wxd930ea5d5a258f4f', universalLink = 'YourUniversionLink')
return false
}
// 通过 url scheme 方式唤起 app 时的回调函数。
applicationOpenURLOptions(app : UIApplication | null, url : URL, options : Map<UIApplication.OpenURLOptionsKey, any> | null = null) : boolean {
WXApi.handleOpen(url, delegate = this)
return true
}
// 当应用程序接收到与用户活动相关的数据时调用此方法,例如,当用户使用 Universal Link 唤起应用时。
applicationContinueUserActivityRestorationHandler(application : UIApplication | null, userActivity : NSUserActivity | null, restorationHandler : ((res : [any] | null) => void) | null = null) : boolean {
if (userActivity != null) {
WXApi.handleOpenUniversalLink(userActivity!, delegate = this)
}
return true
}
//@brief 收到一个来自微信的请求,第三方应用程序处理完后调用sendResp向微信发送结果
onReq(req : BaseReq) {
//TODO
}
//@brief 发送一个sendReq后,收到微信的回应
onResp(resp : BaseReq) {
const payResp :PayResp | null = resp as PayResp
if (payResp != null) {
if (payResp!.errCode == 0) {
let res : RequestPaymentSuccess = {
data: payResp!
}
this.options?.success?.(res)
this.options?.complete?.(res)
} else {
const errCode = payResp!.errCode as number
let code = errorCodeMap[errCode];
if (code == null) {
code = defaultErrorCode
}
let err = new RequestPaymentFailImpl(code!);
this.options?.fail?.(err)
this.options?.complete?.(err)
}
}
}
requestPayment(options : RequestPaymentOptions) {
this.options = options
if (this.isWXAppInstalled() == true) {
let err = new RequestPaymentFailImpl(defaultErrorCode);
options.fail?.(err)
options.complete?.(err)
return
}
const params = JSON.parse(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);
}
//@brief 检查微信是否已被用户安装
isWXAppInstalled() : boolean {
return WXApi.isWXAppInstalled()
}
}
\ No newline at end of file
......@@ -4,6 +4,27 @@
"WebKit.framework",
"Security.framework"
],
"deploymentTarget": "12.0"
"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
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<number, number> = 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<UIApplication.LaunchOptionsKey, any> | null = null) : boolean {
Wxpay.share.registerApp()
return false
}
// 通过 url scheme 方式唤起 app 时的回调函数。
applicationOpenURLOptions(app : UIApplication | null, url : URL, options : Map<UIApplication.OpenURLOptionsKey, any> | 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<string, any>[] | 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<string, any> | 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
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>wxd930ea5d5a258f4f</string>
</array>
</dict>
</array>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>weixin</string>
<string>weixinULAPI</string>
<string>weixinURLParamsAPI</string>
</array>
</dict>
</plist>
\ No newline at end of file
......@@ -3,11 +3,11 @@ import { RequestPaymentFailImpl } from '../unierror.uts'
export const requestPayment : RequestPayment = function (options : RequestPaymentOptions) {
//获取provider实例,hx自动生成,其中UniPaymentProvider为在interface中定义的接口
const provider = UTSAndroid.getExtApiProvider<UniPaymentProvider>("payment", options.provider)
const provider = UTSAndroid.getProvider<UniPaymentProvider>("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)
}
......
......@@ -3,11 +3,11 @@ import { RequestPaymentFailImpl } from '../unierror.uts';
import { UTSiOS } from "DCloudUTSFoundation";
export const requestPayment : RequestPayment = function (options : RequestPaymentOptions) {
const provider = UTSiOS.getExtApiProvider<UniPaymentProvider>("payment", options.provider)
const provider = UTSiOS.getProvider<UniPaymentProvider>("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)
}
......
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 = {
......
......@@ -12,36 +12,40 @@ const RequestPaymentUniErrors : Map<RequestPaymentErrorCode, string> = 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.']
]);
......
......@@ -9,26 +9,17 @@
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"
>>>>>>>> dev:uni_modules/uni-prompt/utssdk/app-android/res/layout/uni_prompt_ac_recyclerview_layout_top_night.xml
android:orientation="vertical" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/tvName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/uni_prompt_actionsheet_button_select_total_night_top"
android:gravity="center"
android:padding="17dp"
<<<<<<<< HEAD:uni_modules/uni-prompt/utssdk/app-android/res/layout/uni_prompt_ac_recyclerview_layout_top.xml
android:textColor="@color/uni_prompt_dialog_title_text"
android:background="@drawable/uni_prompt_actionsheet_button_select_total_top"
========
android:textColor="@color/uni_prompt_dialog_title_text_night"
>>>>>>>> dev:uni_modules/uni-prompt/utssdk/app-android/res/layout/uni_prompt_ac_recyclerview_layout_top_night.xml
android:textSize="16dp" />
......
......@@ -9,28 +9,17 @@
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"
>>>>>>>> dev:uni_modules/uni-prompt/utssdk/app-android/res/layout/uni_prompt_ac_recyclerview_layout_top.xml
android:orientation="vertical" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/tvName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
<<<<<<<< HEAD:uni_modules/uni-prompt/utssdk/app-android/res/layout/uni_prompt_ac_recyclerview_layout_top_night.xml
android:background="@drawable/uni_prompt_actionsheet_button_select_total_night_top"
android:gravity="center"
android:padding="17dp"
android:textColor="@color/uni_prompt_dialog_title_text_night"
========
android:gravity="center"
android:padding="17dp"
android:textColor="@color/uni_prompt_dialog_title_text"
android:background="@drawable/uni_prompt_actionsheet_button_select_total_top"
>>>>>>>> dev:uni_modules/uni-prompt/utssdk/app-android/res/layout/uni_prompt_ac_recyclerview_layout_top.xml
android:textSize="16dp" />
......
......@@ -46,10 +46,23 @@ export function hideLoadingImpl() {
closeToast("loading")
}
// 全局存储
// #ifdef UNI-APP-X
const onReadyToast = new Map<ComponentPublicInstance,UTSJSONObject>()
// #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(() => {
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(() => {
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)
}
......
......@@ -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<string, any | null>([
[
ANIMATION_TYPE,
options?.animationType ?? DEFAULT_ANIMATION_OUT,
options?.animationType ?? DEFAULT_ANIMATION_NAVIGATE_BACK,
],
[
ANIMATION_DURATION,
......
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',
......
......@@ -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"
* }
* }
*/
......
......@@ -917,10 +917,70 @@ export interface Uni {
hideTabBarRedDot(
options: HideTabBarRedDotOptions,
): Promise<HideTabBarRedDotSuccess> | 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
}
{
"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
# 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
{
"minSdkVersion": "21"
}
\ No newline at end of file
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)
}
{
"deploymentTarget": "12"
}
\ No newline at end of file
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)
}
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
import { AppThemeErrorCode, IAppThemeFail } from "./interface.uts"
/**
* 错误主题
*/
export const AppThemeUniErrorSubject = 'uni-theme';
/**
* 错误码
* @UniError
*/
export const AppThemeUniErrors : Map<AppThemeErrorCode, string> = 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
......@@ -139,7 +139,7 @@ class RunnableTask {
if (this.looper == null || this.looper!.currentMode == null) {
this.callback?.();
} else {
this.looper?.perform(() => {
this.looper?.perform(inModes = [RunLoop.Mode.common], block = () => {
this.callback?.();
})
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册