what is the significance of setFrequency() function in titanium Js v7.5.0 - titanium

I have been facing an issue regarding Geolocation in iOS/Android app. I am using Titanium Js and have upgraded Ti v7.5.0 to v8.3.1. I checked my legacy code and came to know that this below function
Titanium.Geolocation.setFrequency()
creating a problem. It seems like this function gets deprecated.
this.locationFrequency = 100;
Geolocate.prototype.getCurrentPosition = function(callback){
var self = this;
// initialize the callback
this.locationReceivedCallback = callback;
// Set this so we get updates rapidly
Titanium.Geolocation.setFrequency(this.locationFrequency)
// Register for the actual event
Titanium.Geolocation.addEventListener('location', someCallBackFunc);
};
Now, I need help to understand what actually this Titanium.Geolocation.setFrequency() does. Is there any alternate way to achieve the same in latest version of Ti?

Since it is open source you can look at the github repo:
https://github.com/appcelerator/titanium_mobile/blob/7_5_X/android/modules/geolocation/src/java/ti/modules/titanium/geolocation/GeolocationModule.java#L469
and check the official documentation at frequency
https://docs.appcelerator.com/platform/latest/?print=/api/Titanium.Geolocation#property-frequency and use the recommendation there.

Related

React Native App Working in Development, 'Error: 'undefined' is not a function' in Production

I have completed an app that builds on both Android and iOS. It works as expected when I build the app from the CLI or when I build it via XCode / Android Studio. However, on TestFlight, it gets errors that simply do NOT exist when I build it locally. These errors only appear on TestFlight, and thus I have little to no idea on how to go finding them down or even resolving them. Does anyone have better expertise in this area?
I'm not sure how common an issue this is-- I've never heard of it before to be honest, but the components that were not working were components that utilized ({props}) in a component. For example, any component wthat utilized the following declarations did NOT work
function Example({props}){
// stuff
}
// OR //
const Example = ({props}) => {
// stuff
}
all of the values inside of props were unreadable. I fixed this by simply moving EVERYTHING into a recoil state instead and that mitigated any errors. For example...
navigation.navigate("path",{prop1: value})
// AND //
return (<Example prop={value} prop={value})
would not work unless the prop was a single value-- a string, an int, a bool, these would work. Objects and Arrays did NOT properly carry over.
Hope this helps someone in the future.

When do you use react-native-push-notification vs #react-native-community/push-notification-ios?

I'm reading the installation instructions for react-native-push-notification and it indicates that for iOS, you use #react-native-community/push-notification-ios. It seems as though you have to add both of these modules separately. However, I don't understand which to use in my actual code. Do you use var PushNotification = require("react-native-push-notification"); as it says in react-native-push-notification, or do you use import PushNotificationIOS from "#react-native-community/push-notification-ios"; from #react-native-community/push-notification-ios?
You do have to have both packages in your package.json but you do not need to use PushNotificationIOS for anything other than a finish handler as shown in the usage section here.
Generally though, you would only need to use var PushNotification = require("react-native-push-notification") and call your handlers on that.

React: Calling JS function after bridge has been destroyed --- How to find which function

I'm working on an update for our app. I've added a HeadlessTask and I've started seeing this warning in the console:
React: Calling JS function after bridge has been destroyed
How can I get the name of the function being executed?
From the error message I assume you're in java (react-native Android):
When you reload on react-native, what happens behind the scenes is that the react context is getting destroyed, and a new one is being created.
That error get's thrown whenever a react-native Native Module is trying to do work, by using the old react context (the one that was valid before the reload).
The last time I saw that error it also included an explanation as to which module tried to do work by using the old context. Typically it's the RCTDeviceEventEmitter module trying to send a message to javascript.
You'll have to open logcat on Android studio and read the full error message.
p.s: If you're using react-native-navigation in your project, (after you discover which module is the trouble maker by using the logcat), make sure to search on their issues as they are heavily using the native side of react-native android, and I've seen lot's of similar issues so far.
Never found a good solution to this until recently, so thought I'd put this here in case it helps someone else. I finally got around this error by doing the following:
public class RNMyNativeModule extends ReactContextBaseModule {
private ReactApplicationContext currentContext;
public RNMyNativeModule(ReactApplicationContext reactContext) {
super(reactContext);
currentContext = reactContext;
}
public void myEmitFn(String emitMe) {
currentContext
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit("RNMyNativeModuleEvent", emitMe);
}
}
Basically, in your module constructor, make sure you capture the currentContext in it's own variable, and just use that whenever you need it. Otherwise it gets overwritten and destroyed whenever a live reload happens, and getReactApplicationContext() is not actually giving you the current context.

React Native - Parse URL to get Query Variable

Looking for a way to parse a URL to get a query variable in React Native received from Linking.
I'm receiving the URL as something like:
url-app-scheme://somePage?someVar=someVal
I'd like to get the someVar value from the URL.
Any thoughts?
This should do the trick
var url = "http://example.com?myVar=test&otherVariable=someData&number=123"
var regex = /[?&]([^=#]+)=([^&#]*)/g,
params = {},
match;
while (match = regex.exec(url)) {
params[match[1]] = match[2];
}
console.log(params)
There is a URL class in JavaScript which is intended to let you both build and parse URLs robustly, making query parameters easily accessible:
const url = new URL('url-app-scheme://somePage?someVar=someVal');
url.searchParams.get('someVar')
Sadly, the implementation of URL in React Native is not complete and has some known bugs. Fortunately, there is a solid polyfill library called react-native-url-polyfill which provides an implementation of URL that is well behaved and tested - I highly recommend it.
Using query-string its working
yarn add query-string
import queryString from 'query-string';
const parsed = queryString.parseUrl("https://pokeapi.co/api/v2/pokemon?offset=10&limit=10");
console.log(parsed.query.offset) will display 10
There are ways of doing this that you can leverage from the JS ecosystem. Try URI.js https://github.com/medialize/URI.js
Try url https://www.npmjs.com/package/url
"This module has utilities for URL resolution and parsing meant to have feature parity with node.js core url module."
The node URL object is available to your app when using the Chrome react-native debugger, but is not available on your iPhone when untethered.
So use this package
npm install url
Sample code:
import url from 'url';
...
let urlObject = url.parse(inUrlString);
let outUrlString = urlObject.protocol + '//' + urlObject.host + '/more/jump?jump_path=' + encodeURIComponent(urlObject.pathname);
url="example.com/path/?id=1"
let urlObject = url.parse(url, true); // second parameter `true` (parse search query)
console.log(urlObject.query['id']); // 1
Update: This is not a solution to the above question because it doesn't work unless in debugging mode. I have not deleted this answer however, because I think it points out a note worthy nuance.
JavaScript's very own URL Web API is supported in React Native (using version 0.46). You can use to to parse or build any and every part of the url with great ease.
The API is identical to the WHATWG API of the URL module in Node.js This answer should really be more obvious, but its easy to get lost with the number of okay url parsing packages available.
Edit: This works only in the JS debugging mode for some reason, and not otherwise. So this solution doesn't really hold valid, but I'm leaving it here because I'd love to know how to get the same URL module to work with react-native.

Detecting if a running application is sandboxed

Given an application's pid, is there any way, programatically, of detecting if that application is running in an OSX sandbox environment?
Ideally, I'd like to know if there's an API call somewhere, preferably in C, rather than objective-C (for a daemon, so not using Cocoa), but if not, is there any other way of checking?
#Linuxios was right partly right about there being a CoreFoundation call. In fact, there are a few that when combined, can be used to solve this and it's based on the call to SecStaticCodeCheckValidityWithErrors
For anyone that may want, or need to programmatically test for an app being sandboxed can follow this blog.
Also, the full code to the article has been added to Github here.
First you must get the path of the application from the pid, and then you can use the command codesign --display --entitlements - app_path to view all the entitlements. If the app has the entitlements com.apple.security.app-sandbox set to true then it is sandboxed.
You can take a look here.
For detecting the sandbox in Flex/AIR/AS3 you can use the following kludge. The same approach should also work in objc. The only condition under which this would not work would be if the Documents folder were entirely empty. Or you could use any other folder that is off-limits to the sandbox.
var file:File = File.userDirectory;
var a:Array = file.nativePath.split("/");
var userName:String = a[2];
var docFolder:File = new File("/Users/" + userName + "/Documents/");
var dirList:Array = docFolder.getDirectoryListing();
if (dirList.length>0) {
docDirectoryDisplay.text = "App is NOT sandboxed.";
} else {
docDirectoryDisplay.text = "App is sandboxed.";
}