index.uts 1.4 KB
Newer Older
DCloud-yyl's avatar
DCloud-yyl 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
import { OpenAppAuthorizeSettingOptions, OpenAppAuthorizeSetting, OpenAppAuthorizeSettingSuccess, OpenAppAuthorizeSettingFail, OpenAppAuthorizeSettingComplete } from "../interface.uts";
import { UTSiOS } from "DCloudUTSFoundation";
import { UIApplication } from 'UIKit';

export const openAppAuthorizeSetting: OpenAppAuthorizeSetting = function(settingOptions: OpenAppAuthorizeSettingOptions) {
	const url = URL(string = UIApplication.openSettingsURLString)!
	if (UIApplication.shared.canOpenURL(url)){
		let op = new Map<UIApplication.OpenExternalURLOptionsKey, any>()
		if (UTSiOS.available("iOS 10, *")) {
		  UIApplication.shared.open(url,options=op,completionHandler=(result: Boolean):void => {
			if(result){
				const success : OpenAppAuthorizeSettingSuccess = { errMsg:"" }
				const complete : OpenAppAuthorizeSettingComplete = { errMsg:"" }
				settingOptions.success?.(success);
				settingOptions.complete?.(complete);
			}else{
				const fail : OpenAppAuthorizeSettingFail = { errMsg: "unknown error"};
				const complete : OpenAppAuthorizeSettingComplete = { errMsg: "unknown error"}
				settingOptions.fail?.(fail);
				settingOptions.complete?.(complete);
			}
		  })
		}
	}else{
		const fail : OpenAppAuthorizeSettingFail = { errMsg: "unknown error" };
		const complete : OpenAppAuthorizeSettingComplete = { errMsg: "unknown error" }
		settingOptions.fail?.(fail);
		settingOptions.complete?.(complete);
	}
}