Google Play应用更新因功能故障被拒,求代码排查解决
问题:Google Play上架因Broken Functionality政策被拒
- 应用版本6的更新未通过Google Play审核,违反Broken Functionality政策:存在无响应或无法返回内容的按钮(详情见截图IN_APP_EXPERIENCE-533.png)
- 已完成14天测试,22名参与用户中仅1位遇到该问题,无法自行定位原因,附上React Native页面代码,请求协助修复以完成上架
涉事页面代码
import React, { useState } from 'react'; import { View, SafeAreaView, Image, Text, StyleSheet, TouchableOpacity, TextInput, Alert, ScrollView,Linking } from 'react-native'; import Icon from 'react-native-vector-icons/MaterialIcons'; import COLORS from './colors'; const ZAADSLSHSCREEN = ({ navigation, route }) => { const { params: { plant } } = route; const [lastNumber, setLastNumber] = useState(''); const handlePress = async () => { if (!lastNumber.trim() || isNaN(lastNumber)) { Alert.alert('Invalid Input', 'Please enter a valid number.'); return; } const code = `*377*323401*${lastNumber}#`; const encodedCode = encodeURIComponent(code); const url = `tel:${encodedCode}`; try { const supported = await Linking.canOpenURL(url); if (supported) { Alert.alert('Confirm Dial', 'Do you want to dial this USSD code?', [ { text: 'Cancel', onPress: () => {}, style: 'cancel' }, { text: 'OK', onPress: () => Linking.openURL(url) } ]); } else { Alert.alert('Unsupported Feature', "This device can't handle dialing the USSD code."); } } catch (error) { Alert.alert('Error', 'An unexpected error occurred: ' + error.message); } }; return ( <ScrollView> <SafeAreaView style={styles.container}> <Image source={plant.img} style={styles.image} /> <View style={styles.detailsContainer}> <Text style={styles.title}>Dollar ayaad heli doontaa</Text> <Text style={styles.description}>{plant.about}</Text> <TextInput style={styles.input} onChangeText={setLastNumber} value={lastNumber} placeholder="Geli lacagta aad sarifanayso" keyboardType="numeric" /> <TouchableOpacity onPress={handlePress} style={styles.buyBtn}> <Text style={styles.buyBtnText}>Sarifo</Text> </TouchableOpacity> </View> </SafeAreaView> </ScrollView> ); }; const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: COLORS.white, }, image: { resizeMode: 'contain', flex: 2, marginTop: 80, justifyContent: 'center', alignItems: 'center', alignSelf:'center' }, detailsContainer: { flex: 1, backgroundColor: COLORS.light, margin: 7, borderRadius: 20, padding: 20, }, title: { fontSize: 20, fontWeight: 'bold', }, description: { color: 'grey', fontSize: 16, lineHeight: 22, marginTop: 10, }, input: { height: 40, marginVertical: 12, borderBottomWidth: 1, padding: 10, color: '#000', borderRadius: 50, textAlign: 'center', fontSize: 18 }, buyBtn: { backgroundColor: '#347dce', height: 50, borderRadius: 30, justifyContent: 'center', alignItems: 'center', }, buyBtnText: { color: COLORS.white, fontSize: 18, fontWeight: 'bold', } }); export default ZAADSLSHSCREEN;
修复建议
1. 修正USSD代码的URL构造逻辑
Android的tel:协议原生支持*和#字符,无需编码。原代码中的encodeURIComponent可能导致部分设备解析USSD代码异常,修改如下:
// 替换原URL构造部分 const code = `*377*323401*${lastNumber}#`; const url = `tel:${code}`; // 直接使用未编码的USSD代码
2. 添加按钮防重复点击与状态管理
添加加载状态,避免用户重复点击导致无响应:
// 在组件内添加状态 const [isLoading, setIsLoading] = useState(false); // 修改handlePress函数 const handlePress = async () => { if (isLoading) return; // 防止重复点击 setIsLoading(true); try { // 原逻辑保持不变,仅修改URL部分 // ... } finally { setIsLoading(false); // 无论成功失败都重置状态 } }; // 修改TouchableOpacity属性 <TouchableOpacity onPress={handlePress} style={styles.buyBtn} disabled={isLoading} > <Text style={styles.buyBtnText}>{isLoading ? '加载中...' : 'Sarifo'}</Text> </TouchableOpacity>
3. 完善边界错误处理
- 处理
route.params.plant可能为undefined的情况,防止页面渲染崩溃:
const plant = route.params?.plant || { img: require('./default-plant.png'), // 替换为你的默认图片路径 about: '' };
- 对
Linking.openURL单独添加错误捕获,即使canOpenURL返回true,实际打开仍可能失败:
{ text: 'OK', onPress: async () => { try { await Linking.openURL(url); } catch (openError) { Alert.alert('调用失败', '无法启动拨号功能,请检查设备权限'); } } }
4. 优化输入验证逻辑
原isNaN判断在输入纯数字字符串时正常,但可以更严谨地限制为正整数:
if (!lastNumber.trim() || !/^\d+$/.test(lastNumber.trim())) { Alert.alert('无效输入', '请输入有效的数字'); return; }
5. 测试验证建议
- 在不同Android版本(尤其是Android 10及以下)、不同品牌设备上测试USSD调用逻辑
- 测试拨号权限被禁用的场景,确保按钮有明确的错误反馈
- 模拟网络异常环境,验证错误处理流程是否正常
内容的提问来源于stack exchange,提问作者Abdiwahab Youusf Abdillahi
相关产品推荐
相关产品推荐

