Expo请求TrackingTransparency权限报undefined错误如何解决
Expo集成expo-tracking-transparency库报错问题解决
问题描述
使用Expo开发iOS应用需要调用TrackingTransparency能力,按照官方文档安装expo-tracking-transparency库后,请求权限时触发如下报错:
[Unhandled promise rejection: TypeError: undefined is not an object (evaluating '_ExpoTrackingTransparency.default.requestPermissionsAsync')] at node_modules\expo-tracking-transparency\build\TrackingTransparency.js:31:7 in requestTrackingPermissionsAsync at node_modules\regenerator-runtime\runtime.js:63:36 in tryCatch at node_modules\regenerator-runtime\runtime.js:293:29 in invoke at node_modules\regenerator-runtime\runtime.js:63:36 in tryCatch at node_modules\regenerator-runtime\runtime.js:154:27 in invoke at node_modules\regenerator-runtime\runtime.js:189:16 in PromiseImpl$argument_0 at node_modules\react-native\node_modules\promise\setimmediate\core.js:45:6 in tryCallTwo at node_modules\react-native\node_modules\promise\setimmediate\core.js:200:22 in doResolve at node_modules\react-native\node_modules\promise\setimmediate\core.js:66:11 in Promise at node_modules\regenerator-runtime\runtime.js:188:15 in callInvokeWithMethodAndArg at node_modules\regenerator-runtime\runtime.js:211:38 in enqueue at node_modules\regenerator-runtime\runtime.js:238:8 in exports.async at node_modules\expo-tracking-transparency\build\TrackingTransparency.js:5:41 in <global> at node_modules\regenerator-runtime\runtime.js:63:36 in tryCatch at node_modules\regenerator-runtime\runtime.js:293:29 in invoke at node_modules\regenerator-runtime\runtime.js:63:36 in tryCatch at node_modules\regenerator-runtime\runtime.js:154:27 in invoke at node_modules\regenerator-runtime\runtime.js:189:16 in PromiseImpl$argument_0 at node_modules\react-native\node_modules\promise\setimmediate\core.js:45:6 in tryCallTwo at node_modules\react-native\node_modules\promise\setimmediate\core.js:200:22 in doResolve at node_modules\react-native\node_modules\promise\setimmediate\core.js:66:11 in Promise at node_modules\regenerator-runtime\runtime.js:188:15 in callInvokeWithMethodAndArg at node_modules\regenerator-runtime\runtime.js:211:38 in enqueue at node_modules\regenerator-runtime\runtime.js:238:8 in exports.async at node_modules\react-native-gradient-buttons\src\index.js:80:29 in <anonymous> at node_modules\react-native\Libraries\Pressability\Pressability.js:691:17 in _performTransitionSideEffects at node_modules\react-native\Libraries\Pressability\Pressability.js:628:6 in _receiveSignal at node_modules\react-native\Libraries\Pressability\Pressability.js:524:8 in responderEventHandlers.onResponderRelease at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:265:4 in invokeGuardedCallbackImpl at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:476:2 in invokeGuardedCallback at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:500:2 in invokeGuardedCallbackAndCatchFirstError at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:597:41 in executeDispatch at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:621:19 in executeDispatchesInOrder at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:2521:28 in executeDispatchesAndRelease at [native code]:null in forEach at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:836:4 in forEachAccumulated at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:2546:20 in runEventsInBatch at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:2702:18 in runExtractedPluginEventsInBatch at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:2639:35 in batchedUpdates$argument_0 at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:17712:13 in batchedUpdates$1 at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:2492:29 in batchedUpdates at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:2638:16 in _receiveRootNodeIDEvent at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:2767:27 in receiveTouches at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:416:4 in __callFunction at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:109:6 in __guard$argument_0 at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:364:10 in __guard at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:108:4 in callFunctionReturnFlushedQueue at [native code]:null in callFunctionReturnFlushedQueue
已做配置与异常
安装完成后在app.json中添加了如下插件配置:
"plugins": [ "expo-tracking-transparency" ]
启动应用时日志报app.json校验错误,提示should NOT have additional property 'plugins'。
请求权限的代码如下:
const logInHandler = () => { (async () => { const w = await requestTrackingPermissionsAsync(); console.log(w); const { status } = await requestTrackingPermissionsAsync(); if (status === 'granted') { login(); } else { dispatchAlertState({ action: SHOW_ALERT, message: 'Permission is required in order to log in.', type: AlertType.error, }); } })(); };
调用库的isAvailable()方法检测时,运行iOS14.5的iPad模拟器提示TrackingTransparency API不可用(运行iOS12.5的iPad mini 2提示不可用符合预期),不符合Expo官方文档中getTrackingPermissionsAsync()在旧款iOS设备和Android设备上应始终返回true的描述。
解决方案
问题根源是使用的V40版本Expo不包含该权限的相关适配代码,升级到V42版本即可解决上述所有问题。
内容的提问来源于stack exchange,提问作者Christian Del Rio
相关产品推荐
相关产品推荐

