此问题的根本原因是因为移动设备的网络代理阻止了网络请求。要解决这个问题,需要在app.json文件中添加以下内容:
"expo": { "android": { "useNextNotificationsApi": true, "permissions": ["NOTIFICATIONS", "CAMERA_ROLL", "CAMERA", "READ_EXTERNAL_STORAGE", "WRITE_EXTERNAL_STORAGE"] }, "ios": { "supportsTablet": true, "bundleIdentifier": "com.example.yourexpobundle", "permissions": ["NOTIFICATIONS", "CAMERA_ROLL", "CAMERA"] }, "web": { "favicon": "./favicon.png" }, "name": "your-app-name", "slug": "your-app-slug", "version": "1.0.0", "orientation": "portrait", "icon": "./assets/icon.png", "splash": { "image": "./assets/splash.png", "resizeMode": "contain", "backgroundColor": "#ffffff" }, "updates": { "fallbackToCacheTimeout": 0 }, "assetBundlePatterns": [ "**/*" ], "ios": { "supportsTablet": true }, "android": { "adaptiveIcon": { "foregroundImage": "./assets/adaptive-icon.png", "backgroundColor": "#FFFFFF" } } }
这里最重要的部分是permissions部分,必须将NOTIFICATIONS权限添加到列表中供Expo在应用程序中使用。