expo location permissions work on android, but not on iOS - ios

I have a react-native app that uses expo.
The location permissions work on android, but not on iOS.
On a real iPhone (iOS version 14.4.2), it does nothing. On a simulator, I get this error message:
[Unhandled promise rejection: Error: LOCATION_FOREGROUND permission is required to do this operation.]
at node_modules/react-native/Libraries/BatchedBridge/NativeModules.js:103:50 in promiseMethodWrapper
at node_modules/#unimodules/react-native-adapter/build/NativeModulesProxy.native.js:15:23 in moduleName.methodInfo.name
at http://127.0.0.1:19000/node_modules/expo/AppEntry.bundle?platform=ios&dev=true&hot=false&minify=false:293333:90 in watchPositionAsync$
at http://127.0.0.1:19000/node_modules/expo/AppEntry.bundle?platform=ios&dev=true&hot=false&minify=false:293327:37 in watchPositionAsync
Update: I tried it on another Android device and it did not work, so maybe it works on my main Android phone because the permissions were already granted when running a previous version? There is a bug report about permissions breaking between Expo version 40 and 41 https://github.com/expo/expo/issues/12581
Here is what I'm using:
app.json:
{
"expo": {
"name": "Andiamo",
"slug": "andiamo_places",
"version": "1.0.0",
"orientation": "default",
"icon": "./assets/icon.png",
"splash": {
"image": "./assets/splash.png",
"resizeMode": "contain",
"backgroundColor": "#ffffff"
},
"updates": {
"fallbackToCacheTimeout": 0
},
"assetBundlePatterns": [
"**/*"
],
"ios": {
"bundleIdentifier": "com.andiamoplaces.andiamotravelapp",
"supportsTablet": true,
"infoPlist": {
"NSLocationUsageDescription":
"The app needs permission to access your location, if you want to be located on the map.",
"NSLocationWhenInUseUsageDescription": "The app needs permission to access your location, if you want to be located on the map",
"NSLocationAlwaysUsageDescription": "The app needs permission to access your location, if you want to be located on the map",
"NSLocationAlwaysAndWhenInUseUsageDescription": "The app needs permission to access your location, if you want to be located on the map",
"NSPhotoLibraryUsageDescription": "The app needs permission to your camera roll, if you want to upload pictures.",
"NSCameraUsageDescription": "The app needs permission to your camera, if you want to take pictures from the app."
}
},
"android": {
"package": "com.andiamoplaces.andiamotravelapp",
"adaptiveIcon": {
"foregroundImage": "./assets/adaptive-icon.png",
"backgroundColor": "#FFFFFF"
},
"permissions": [
"CAMERA",
"LOCATION"
]
},
"web": {
"favicon": "./assets/favicon.png"
},
"description": ""
}
}
package.json:
{
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web",
"eject": "expo eject",
"postinstall": "jetifier -r"
},
"dependencies": {
"#expo/vector-icons": "^12.0.0",
"#react-native-community/clipboard": "^1.5.1",
"#react-native-community/datetimepicker": "3.2.0",
"#react-native-community/masked-view": "0.1.10",
"#react-navigation/native": "^3.8.4",
"#use-expo/font": "^2.0.0",
"cross-fetch": "^3.1.4",
"expo": "^41.0.0",
"expo-camera": "~11.0.2",
"expo-cli": "^4.4.4",
"expo-clipboard": "~1.0.2",
"expo-facebook": "~11.0.5",
"expo-font": "~9.1.0",
"expo-image-manipulator": "~9.1.0",
"expo-image-picker": "~10.1.4",
"expo-location": "~12.0.4",
"expo-media-library": "~12.0.2",
"expo-permissions": "~12.0.1",
"expo-status-bar": "~1.0.4",
"firebase": "8.2.3",
"geolib": "^3.3.1",
"global": "^4.4.0",
"luxon": "^1.26.0",
"native-base": "^2.15.2",
"react": "16.13.1",
"react-devtools": "^4.13.2",
"react-dom": "16.13.1",
"react-native": "https://github.com/expo/react-native/archive/sdk-41.0.0.tar.gz",
"react-native-color-picker": "^0.6.0",
"react-native-draggable-flatlist": "^2.6.1",
"react-native-gesture-handler": "~1.10.2",
"react-native-ionicons": "^4.6.5",
"react-native-maps": "0.27.1",
"react-native-material-menu": "^1.2.0",
"react-native-modal": "^11.10.0",
"react-native-pell-rich-editor": "^1.7.0",
"react-native-popup-menu": "^0.15.10",
"react-native-prompt-crossplatform": "^1.6.1",
"react-native-ratings": "^8.0.4",
"react-native-reanimated": "~2.1.0",
"react-native-safe-area-context": "3.2.0",
"react-native-safe-area-view": "^1.1.1",
"react-native-screens": "~3.0.0",
"react-native-simple-radio-button": "^2.7.4",
"react-native-switch": "^2.0.0",
"react-native-switch-selector": "^2.1.4",
"react-native-vector-icons": "^8.1.0",
"react-native-web": "~0.13.12",
"react-native-webview": "11.2.3",
"react-native-youtube-iframe": "^2.0.1",
"react-navigation": "^4.4.4",
"react-navigation-drawer": "^2.7.1",
"react-navigation-stack": "^2.10.4",
"react-navigation-tabs": "^2.11.1",
"react-redux": "^7.2.4",
"redux": "^4.1.0",
"redux-persist": "^6.0.0",
"redux-thunk": "^2.3.0"
},
"devDependencies": {
"#babel/core": "~7.9.0",
"jetifier": "^1.6.8"
},
"private": true
}
code:
startUserLocationUpdates = async () => {
const returns = await Location.watchPositionAsync(
{
accuracy: Location.Accuracy.BestForNavigation,
timeInterval: 1000,
// distanceInterval: 0,
},
(loc) => {
if (this.props.ShowLocation) this.centerMapTo(loc.coords.latitude, loc.coords.longitude);
this.props.onSetCurrentLocation({ latitude: loc.coords.latitude, longitude: loc.coords.longitude });
}
);
this._removeLocationUpdates = returns.remove;
};

An updated version of the Permissions with formatted code.
if (Platform.OS !== "web") {
const { status } = await Location.requestForegroundPermissionsAsync();
if (status !== "granted") {
Alert.alert(
"Insufficient permissions!",
"Sorry, we need location permissions to make this work!",
[{ text: "Okay" }]
);
return;
}
}
In fact, I've had the opposite scenario; iOS was working fine, but Android did not without the code above.
<uses-permission android:name=... in the AndroidManifest.xml is being automatically by Expo, so you don't need to care about it and modify anything.

Related

Issue using rn-nodeify in React-native project

I am developing a mobile app using React native, which involves an interaction with Meta1.js
and Problem is RN does not support core Node.js modules, so I had to install react-native-crypto, react-native-randombytes, rn-nodeify and run ./node_modules/.bin/rn-nodeify --hack --install I actually followed this docs
but I end-up with that error
I also tried to install node, clean the cache, delete watchman, and none of that worked for me, and when I run yarn ios the app crash (build failed)
This is the package.json
"scripts": {
"android": "react-native run-android",
"postinstall": "rn-nodeify --install fs,dgram,process,path,console --hack",
"ios": "react-native run-ios",
"start": "react-native start",
"test": "jest",
"lint": "eslint ."
},
"dependencies": {
"#react-native-community/masked-view": "^0.1.10",
"#react-navigation/bottom-tabs": "^5.11.8",
"#react-navigation/native": "^5.9.3",
"#react-navigation/stack": "^5.14.3",
"#tradle/react-native-http": "^2.0.1",
"assert": "^1.5.0",
"browserify-zlib": "^0.1.4",
"buffer": "^4.9.2",
"console-browserify": "^1.2.0",
"constants-browserify": "^1.0.0",
"dns.js": "^1.0.1",
"domain-browser": "^1.2.0",
"https-browserify": "0.0.1",
"path-browserify": "0.0.0",
"process": "^0.11.10",
"punycode": "^1.4.1",
"querystring-es3": "^0.2.1",
"react": "17.0.1",
"react-native": "0.64.0",
"react-native-crypto": "^2.2.0",
"react-native-gesture-handler": "^1.10.3",
"react-native-level-fs": "^3.0.1",
"react-native-modal": "^11.7.0",
"react-native-os": "^1.2.6",
"react-native-randombytes": "^3.6.0",
"react-native-reanimated": "^2.0.0",
"react-native-safe-area-context": "^3.2.0",
"react-native-screens": "^2.18.1",
"react-native-tcp": "^3.3.2",
"react-native-udp": "^2.7.0",
"react-native-vector-icons": "^8.1.0",
"readable-stream": "^1.0.33",
"rn-nodeify": "^10.2.0",
"stream-browserify": "^1.0.0",
"string_decoder": "^0.10.31",
"timers-browserify": "^1.4.2",
"tty-browserify": "0.0.0",
"url": "^0.10.3",
"vm-browserify": "0.0.4"
},
"devDependencies": {
"#babel/core": "^7.12.9",
"#babel/runtime": "^7.12.5",
"#react-native-community/eslint-config": "^2.0.0",
"babel-jest": "^26.6.3",
"eslint": "7.14.0",
"jest": "^26.6.3",
"metro-react-native-babel-preset": "^0.64.0",
"react-test-renderer": "17.0.1"
},
"jest": {
"preset": "react-native"
},
"react-native": {
"console": "console-browserify",
"path": "path-browserify",
"fs": "react-native-level-fs",
"dgram": "react-native-udp",
"zlib": "browserify-zlib",
"constants": "constants-browserify",
"crypto": "react-native-crypto",
"dns": "dns.js",
"net": "react-native-tcp",
"domain": "domain-browser",
"http": "#tradle/react-native-http",
"https": "https-browserify",
"os": "react-native-os",
"querystring": "querystring-es3",
"_stream_transform": "readable-stream/transform",
"_stream_readable": "readable-stream/readable",
"_stream_writable": "readable-stream/writable",
"_stream_duplex": "readable-stream/duplex",
"_stream_passthrough": "readable-stream/passthrough",
"stream": "stream-browserify",
"timers": "timers-browserify",
"tty": "tty-browserify",
"vm": "vm-browserify",
"tls": false
},
"browser": {
"console": "console-browserify",
"path": "path-browserify",
"fs": "react-native-level-fs",
"dgram": "react-native-udp",
"zlib": "browserify-zlib",
"constants": "constants-browserify",
"crypto": "react-native-crypto",
"dns": "dns.js",
"net": "react-native-tcp",
"domain": "domain-browser",
"http": "#tradle/react-native-http",
"https": "https-browserify",
"os": "react-native-os",
"querystring": "querystring-es3",
"_stream_transform": "readable-stream/transform",
"_stream_readable": "readable-stream/readable",
"_stream_writable": "readable-stream/writable",
"_stream_duplex": "readable-stream/duplex",
"_stream_passthrough": "readable-stream/passthrough",
"stream": "stream-browserify",
"timers": "timers-browserify",
"tty": "tty-browserify",
"vm": "vm-browserify",
"tls": false
}
}
this my first time to ask a question on stack overflow and I hope someone will tell me what to do?

React Native / App Store Connect: ITMS-90809: Deprecated API Usage

When I upload my app to the app store, I get a mail from the apple:
ITMS-90809: Deprecated API Usage - New apps that use UIWebView are no longer accepted. Instead, use WKWebView for improved security and reliability. Learn more (https://developer.apple.com/documentation/uikit/uiwebview)
I am unable to understand which is the problem causing library in my code. If anyone would help me in figuring out the problem causing library, I'll be really thankful. When I run: grep -r UIWebView ./* Here is what happens My package.json:
{
"name": "MyApp",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"dependencies": {
"#expo/ex-navigation": "^3.1.0",
"babel-preset-react-native-stage-0": "^1.0.1",
"firebase": "^4.6.2",
"lodash": "^4.17.10",
"moment": "^2.22.1",
"prop-types": "^15.6.0",
"react": "16.0.0",
"react-native": "^0.55.0",
"react-native-datepicker": "^1.7.2",
"react-native-email": "^1.0.2",
"react-native-firebase": "^5.2.3",
"react-native-loading-spinner-overlay": "^0.5.2",
"react-native-step-indicator": "0.0.7",
"react-native-swipe-list-view": "^3.2.5",
"react-native-vector-icons": "^4.4.2",
"react-redux": "^5.0.6",
"redux": "^3.7.2",
"redux-thunk": "^2.2.0"
},
"devDependencies": {
"babel-eslint": "^8.0.3",
"babel-jest": "21.2.0",
"babel-preset-react-native": "4.0.0",
"eslint": "^4.12.1",
"eslint-plugin-react": "^7.5.1",
"eslint-plugin-react-native": "^3.2.0",
"jest": "21.2.1",
"react-native-dotenv": "^0.1.0",
"react-test-renderer": "16.0.0"
},
"jest": {
"preset": "react-native"
},
"rnpm": {
"assets": [
"js/assets/fonts"
]
}
}

Electron app window does not gain focus when distributed for Mac

This a strange one for me. I have an Electron app which works fine when I run it locally. However, when I npm run dist it to create a native version, the resulting app fails to take focus when I click on it. I click on the text field in the window and a flashing cursor shows up however, when I type keystrokes, they go to the window I was in before (e.g. Finder). This only happens in Mac (Windows works fine) when I'm using a packaged version.
Very perplexing stuff :)
My package.json looks like this (sanitised some names and URLs):
{
"name": "Myapp",
"productName": "MyApp",
"version": "0.0.44",
"description": "MyApp",
"license": "",
"repository": "",
"main": "./main.js",
"author": {
"name": "MyApp Ltd.",
"email": "c#c.com",
"url": "www.c.com"
},
"engines": {
"node": ">=4"
},
"electronVersion": "1.8.3",
"scripts": {
"test": "mocha",
"start": "electron .",
"pack": "build --dir",
"dist": "build"
},
"build": {
"appId": "MyApp",
"win": {
"target": "squirrel",
"icon": "assets/icons/Windows_Icon.ico"
},
"squirrelWindows": {
"loadingGif": "assets/img/installing.gif",
"iconUrl": "https:/fake-url.com/icon.ico",
"msi": false
},
"dmg": {
"window": {
"x": 200,
"y": 200,
"width": 537,
"height": 374
},
"icon": "assets/icons/Mac_Icon.icns",
"background": "assets/img/dmg-background.png"
},
"mac": {
"icon": "assets/icons/Mac_Icon.icns",
"extendInfo": {
"LSBackgroundOnly": 1
}
}
},
"dependencies": {
"azure-event-hubs": "0.0.4",
"babel-polyfill": "^6.20.0",
"bootstrap": "^3.3.7",
"chokidar": "^1.6.1",
"download": "^5.0.2",
"electron-debug": "^0.3.0",
"electron-is-dev": "^0.3.0",
"electron-json-storage": "^3.0.4",
"electron-log": "^2.2.6",
"electron-positioner": "^3.0.0",
"electron-squirrel-startup": "^1.0.0",
"follow-redirects": "^1.2.3",
"glob": "^7.1.1",
"howler": "^2.0.3",
"jquery": "^3.2.1",
"nan": "^2.1.0",
"nconf": "^0.7.2",
"node-schedule": "^1.2.5",
"opener": "^1.4.3",
"pusher-js": "^4.1.0",
"sqlite3": "^3.1.8",
"unirest": "^0.5.1"
},
"devDependencies": {
"chai": "^4.0.2",
"chai-as-promised": "^6.0.0",
"electron": "^1.8.3",
"electron-builder": "^20.8.0",
"electron-builder-squirrel-windows": "^20.9.0",
"electron-installer-dmg": "^0.2.1",
"electron-packager": "^5.1.1",
"mocha": "^3.2.0",
"spectron": "^3.0.0",
"xo": "^0.10.0"
},
"xo": {
"esnext": true,
"envs": [
"node",
"browser"
]
}
}
The LSBackgroundOnly option in Mac apparently has this effect because it designates the app a background app and presumably no events are delivered to it. Once I set it to false, the issue was resolved.

React Native get ios device language

I am trying to get the current locale from ios devices.
I followed this guide when I created my project and I'm using expo.
I tried the following code
if (Platform.OS === "android") {
langRegionLocale = NativeModules.I18nManager.localeIdentifier || "";
} else if (Platform.OS === "ios") {
langRegionLocale = NativeModules.SettingsManager.settings.AppleLocale || "";
}
and it worked for android, but when tested on an iPhone, it did not work and said SettingsManager was undefined when i logged it.
How can I get the current locale for ios without ejecting or using AlexanderZaytsev/react-native-i18n?
If possible I would like to use something that is built in.
Below is my package.json
{
"name": "demoapp",
"version": "0.1.0",
"private": true,
"devDependencies": {
"react-native-scripts": "1.5.0",
"jest-expo": "^21.0.2",
"react-test-renderer": "16.0.0-alpha.12"
},
"main": "./node_modules/react-native-scripts/build/bin/crna-entry.js",
"scripts": {
"start": "react-native-scripts start",
"eject": "react-native-scripts eject",
"android": "react-native-scripts android",
"ios": "react-native-scripts ios",
"test": "node node_modules/jest/bin/jest.js --watch"
},
"jest": {
"preset": "jest-expo"
},
"dependencies": {
"expo": "^21.0.0",
"react": "16.0.0-alpha.12",
"react-native": "^0.48.4",
"react-navigation": "^1.0.0-beta.13",
"react-redux": "^5.0.6",
"redux": "^3.7.2",
"redux-thunk": "^2.2.0"
}
}
Expo Util API has a method for getting device locale.
Expo.Util.getCurrentLocaleAsync()
Returns the current device
locale as a string.

Ionic 3 + One Signal handleNotificationReceived doesn't get fired

I'm following this Ionic SDK Setup link. I'm setting up the push notification on my app.
It's working, I can get the notification. Here's my code.
this.platform.ready().then(() => {
let OneSignal = window["plugins"].OneSignal;
OneSignal
.startInit(AppSettings.ONESIGNAL_APP_ID)
.inFocusDisplaying(OneSignal.OSInFocusDisplayOption.Notification)
.handleNotificationOpened(function(jsonData) {
console.log('OPENED');
})
.handleNotificationReceived(function(jsonData) {
console.log('RECEIVED');
})
.endInit();
OneSignal.getIds(notificationsCallBack.getIdReceived.bind(this));
});
However, the function handleNotificationReceived is only called if the app is open. I need to execute some code (I need an in-app badge), even if the app is closed. I'm setting the content_available to true on my OneSignal API, I also tested directly on the OneSignal website and I couldn't make it works. The function handleNotificationOpened works as expected.
How can I handle the notification received event when my app is not open?
I'm testing on iPhone 6+, iOS 11.0.3
My env:
Ionic 3.12.0
Cordova 7.0.1
My package.json
{
"name": "XXX",
"author": "XXXX XX",
"homepage": "XXX",
"private": true,
"scripts": {
"ionic:build": "ionic-app-scripts build",
"ionic:serve": "ionic-app-scripts serve"
},
"dependencies": {
"#angular/common": "4.2.2",
"#angular/compiler": "4.2.2",
"#angular/compiler-cli": "4.2.2",
"#angular/core": "4.2.2",
"#angular/forms": "4.2.2",
"#angular/http": "4.2.2",
"#angular/platform-browser": "4.2.2",
"#angular/platform-browser-dynamic": "4.2.2",
"#angular/platform-server": "4.2.2",
"#angular/router": "^4.2.2",
"#ionic-native/camera": "^3.4.4",
"#ionic-native/core": "^3.10.3",
"#ionic-native/facebook": "^4.3.1",
"#ionic-native/geolocation": "^3.2.2",
"#ionic-native/google-maps": "^3.4.4",
"#ionic-native/google-plus": "^3.4.4",
"#ionic-native/image-picker": "^3.2.2",
"#ionic-native/native-storage": "^3.4.4",
"#ionic-native/splash-screen": "^3.12.1",
"#ionic-native/status-bar": "^3.12.1",
"#ionic-native/toast": "^3.10.3",
"#ionic-native/transfer": "^3.2.2",
"#ionic/storage": "^2.0.0",
"bourbon": "^4.2.7",
"cordova-ios": "^4.5.1",
"cordova-plugin-camera": "^2.4.1",
"cordova-plugin-compat": "^1.2.0",
"cordova-plugin-console": "^1.0.7",
"cordova-plugin-crop": "^0.3.1",
"cordova-plugin-device": "^1.1.6",
"cordova-plugin-facebook4": "^1.7.4",
"cordova-plugin-googlemaps": "^2.0.11",
"cordova-plugin-googlemaps-sdk": "git+https://github.com/mapsplugin/cordova-plugin-googlemaps-sdk.git",
"cordova-plugin-googleplus": "^5.1.1",
"cordova-plugin-nativestorage": "^2.2.2",
"cordova-plugin-splashscreen": "^4.0.3",
"cordova-plugin-statusbar": "^2.2.3",
"cordova-plugin-whitelist": "^1.3.2",
"cordova-plugin-x-toast": "^2.6.0",
"cordova-sqlite-storage": "^2.0.4",
"cropperjs": "^1.1.0",
"font-awesome": "^4.7.0",
"ionic-angular": "3.3.0",
"ionic-native": "2.9.0",
"ionic-plugin-keyboard": "^2.2.1",
"ionic2-auto-complete": "^1.5.0-beta",
"ionicons": "3.0.0",
"ios-sim": "^6.1.2",
"ng2-cookies": "^1.0.4",
"onesignal-cordova-plugin": "^2.0.11",
"rxjs": "5.4.0",
"sw-toolbox": "3.6.0",
"zone.js": "0.8.12"
},
"devDependencies": {
"#ionic/app-scripts": "1.3.7",
"typescript": "2.3.4"
},
"cordovaPlugins": [
"cordova-plugin-device",
"cordova-plugin-console",
"cordova-plugin-whitelist",
"cordova-plugin-splashscreen",
"cordova-plugin-statusbar",
"ionic-plugin-keyboard",
"cordova-plugin-geolocation",
"cordova-plugin-compat",
"cordova-plugin-file-transfer",
"cordova-plugin-file"
],
"cordovaPlatforms": [
{
"platform": "ios",
"version": "",
"locator": "ios"
},
{
"platform": "android",
"version": "",
"locator": "android"
}
],
"description": "ion2-FullApp: The Best Ionic 2 Starter app",
"config": {
"ionic_sass": "./config/sass.config.js",
"ionic_copy": "./config/copy.config.js"
},
"cordova": {
"platforms": [
"ios"
],
"plugins": {
"cordova-plugin-camera": {
"CAMERA_USAGE_DESCRIPTION": " ",
"PHOTOLIBRARY_USAGE_DESCRIPTION": " "
},
"cordova-plugin-console": {},
"cordova-plugin-crop": {},
"cordova-plugin-device": {},
"cordova-plugin-facebook4": {
"APP_ID": "XX",
"APP_NAME": "XXX"
},
"cordova-plugin-googleplus": {
"REVERSED_CLIENT_ID": "XX"
},
"cordova-plugin-nativestorage": {},
"cordova-plugin-splashscreen": {},
"cordova-plugin-statusbar": {},
"cordova-plugin-whitelist": {},
"cordova-plugin-x-toast": {},
"cordova-sqlite-storage": {},
"ionic-plugin-keyboard": {},
"onesignal-cordova-plugin": {},
"cordova-plugin-googlemaps": {
"API_KEY_FOR_ANDROID": "XX",
"API_KEY_FOR_IOS": "XX",
"LOCATION_WHEN_IN_USE_DESCRIPTION": "Show your location on the map",
"LOCATION_ALWAYS_USAGE_DESCRIPTION": "Trace your location on the map",
"key": "XX"
}
}
}
}
The notification opened event was fixed in the OneSignal Cordova SDK 2.2.0. It was only an issue for iOS 11 devices.
you need to check this. Let me know if it works for you.
You need to set content_available and mutable_content in true in the body of the POST request.

Resources