I'm building an app for iOS using Expo and I require the use of the TrackingTransparency. For some reason when I ask for the user permission it fails with the following error:
[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
I installed the library as expo indicates here
Also, after I installed the library in my app.json appeared as a plugin
"plugins": [
"expo-tracking-transparency"
]
And when I start the app the log says:
Error: Problem validating fields in app.json. Learn more: https://docs.expo.io/workflow/configuration/
• should NOT have additional property 'plugins'.
But I'm not sure if that's a real issue or I can ignore it.
The question is, what else can I do to make the tracking transparency library work?
My code where I'm requesting the permission is the following:
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,
});
}
})();
};
[EDIT]
I noticed that if I use the isAvailable() method from the expo-tracking-transparency library it says that the TrackingTransparency API is not available on the device, which is weird, because the simulator is an iPad running iOS 14.5, I also tested on an iPad mini 2 which runs iOS 12.5 it says it is not available (as expected), but the expo docs say the getTrackingPermissionsAsync() should always return true on older devices and Android.
[Edit 2]
If someone reads this and has the same problem, make sure to be using the expo V42, I was using the V40 which does not contain the code to get the permission
Related
I'm writing a share extension for ReactNative built app.
I'm using ReactNativeShareMenu package.
Whenever I build this app on a M1 architecture MacBook, I get the following error:
Error: couldn't find provider
But on intel MacBooks, it works fine.
The code at index.share.js is as follows:
const Share = () => {
useEffect(() => {
ShareMenuReactView.data().then(({mimeType, data}) => {
ShareMenuReactView.continueInApp({data, mimeType});
});
}, []);
return <View />;
};
AppRegistry.registerComponent('ShareMenuModuleComponent', () => Share);
PS: Rosetta is installed just fine and I tried using RosettaTerminal to run the app too. Nothing changed.
I have built and deployed the default 'Hello World' firebase functions, however when I try and call it the error message is 'NOT FOUND'. Any help would be greatly appreciated. Thanks
Swift Code
func cloudRequest(){
functions.httpsCallable("testFunction").call("") {(result, error) in
if let error = error as? NSError{
switch FunctionsErrorCode(rawValue: error.code) {
case .internal:
print("Internal error \(error.localizedDescription)")
default:
print("Error \(error.localizedDescription)")
}
}
print("Running result condition")
if error == nil{
print(result?.data)
}
}
}
The code for the function deployed in GCP eu west 2 is
exports.helloWorld = (req, res) => {
let message = req.query.message || req.body.message || 'Hello World!';
res.status(200).send(message);
};
check whether the function name is correct
To call a function running in any location other than the default us-central1, you must set the appropriate value at initialization. For example, on Android you would initialize with getInstance(FirebaseApp app, String region).
Ex, lets assume europe-west3 where your function deployed; to call this function
functions('europe-west3').httpsCallable('testFunction')(/* ... */)
Useful ref:
https://firebase.google.com/docs/functions/callable#initialize_the_client_sdk
As per the updated code, it seems that the target Firebase Function is called helloWorld, not testFunction. Moreover, it is located in region europe-west2. Actually, it also seems like you are using Cloud Functions instead of Firebase Functions.
Notice that a Firebase project has a GCP counterpart, therefore a Firebase Function appears in both projects but a GCP project does not necessarily have a Firebase project linked to it. You will find more information on this in the documentation.
If you intend to call the Cloud Function from iOS, I suggest you move to Firebase Functions, where you will be able to use the Firebase SDK to trigger the function (what you intended to do).
Firebase library
Use these instructions to learn how to properly write a Firebase Functions and how to deploy it. You should have something like this:
'use strict';
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
exports.helloWorld = functions.region('europe-west2').https.onRequest((req, res) => {
let message = req.query.message || req.body.message || 'Hello World!';
res.status(200).send(message);
});
Notice that the region is specified when creating the function, otherwise it would be created in us-central1.
After that, it will be possible to reach the function using Firebase from you iOS app.
lazy var functions = Functions.functions(region:"europe-west2")
functions.httpsCallable("helloWorld").call() { (result, error) in
// code
}
This method forces you to deploy a Firebase Function on a Firebase project, it does not work on a GCP-only project.
HTTP Trigger
If you intend to keep using GCP, you can access your deployed functions using their HTTP trigger. In this case it would be something like the following but with the correct project ID:
https://europe-west2-PROJECT_ID.cloudfunctions.net/helloWorld
This method also works using a Firebase Function.
NOTE: I've already searched for ages about this problem & read every similar problem on StackOverflow
I'm making Flutter app and I want to launch a URL on button click (Canvas based).
Everything was okay, until I used "url_launcher".
I'm using Flutter 1.13.6(Latest).
Below is the redirection function I'm using.
import 'package:url_launcher/url_launcher.dart' as URLLaucher;
abstract class URL {
static launchURL(String url) async {
url = Uri.encodeFull(url);
if (await URLLaucher.canLaunch(url)) {
await URLLaucher.launch(url);
} else {
throw 'Unknown error, can\'t launch the URL. Холбоост нэвтрэхэд алдаа гарлаа';
}
}
}
And this is the error log I'm gettin' when I run "flutter run" command.
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':url_launcher'.
> Could not resolve all artifacts for configuration ':url_launcher:classpath'.
> Could not download gradle.jar (com.android.tools.build:gradle:3.4.2)
> Could not get resource 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.4.2/gradle-3.4.2.jar'.
> Read timed out
> Could not download builder.jar (com.android.tools.build:builder:3.4.2)
> Could not get resource 'https://dl.google.com/dl/android/maven2/com/android/tools/build/builder/3.4.2/builder-3.4.2.jar'.
> Premature end of Content-Length delimited message body (expected: 31038805; received: 2359280
> Failed to notify project evaluation listener.
> Could not get unknown property 'android' for project ':url_launcher' of type org.gradle.api.Project.
> Could not find method implementation() for arguments [project ':url_launcher_web'] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
> Could not find method implementation() for arguments [project ':url_launcher_macos'] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
this happens when you do a hot restart after you added something to your pubspec.yaml - just close the app and install it again
I had the same error.
So I upgraded flutter to v1.12.13 and used url_launcher5.3.0 and it worked.
pubspec.yaml
url_launcher: ^6.0.6
main.dart
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
const _url = 'https://flutter.dev';
void main() => runApp(
const MaterialApp(
home: Material(
child: Center(
// ignore: deprecated_member_use
child: RaisedButton(
onPressed: _launchURL,
child: Text('Bappa\'s apps in playstore'),
),
),
),
),
);
void _launchURL() async {
launch("https://play.google.com/store/search?q=pub%3ABAPPA%20SAIKH&c=apps" );
}
I used this syntax and worked for me
void _launchUrl() async {
if (!await launchUrl(_url)) throw 'Could not launch $_url';
}
When a pipeline runs a node series of commands, how can I trigger a fail within the pipeline?
I have tried the following:
const failBuild = function(message) {
console.error('Deploy failed: ', message)
throw new Error('Deploy failed')
}
I see the "Deploy failed" message, but the pipeline still says "Success".
Bb Pipelines fail when a command exits with a non-zero exit code. So, if you want the pipeline to fail, you have to make sure the code is not 0.
In your case (note for people reading this later: see comments), you get 0 as exit status, because the throw is executed in a promise, but then catched in the promise’s catch() function – which does neither stop execution nor have any influence on the exit code.
Solution: explicitly throw an error in the catch() function.
For anyone else who might be struggling with this...
You need to return a non zero as already mentioned, I find the easiest way to do this is by passing a negative integer to PHP's exit() function.
https://php.net/manual/en/function.exit.php
if($condition == true)
{
// Whatever we were doing, it worked YAY!!
exit();
}
else
{
// Something went wrong so fail the step in the pipeline
exit(-1);
}
The accepted answer states:
Solution: explicitly throw an error in the catch() function.
So if I understand that correctly, it suggests you should write the script as:
async function main() { throw "err"; }
main().catch(e => { throw e; });
However, this does not work: the exit code is still 0, and the console displays a nasty warning:
> node "main.js"
(node:32996) UnhandledPromiseRejectionWarning: err
(node:32996) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:32996) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
> $?
0
The correct way to bubble up the error to the node process is:
process.on('unhandledRejection', up => { throw up });
async function main() { throw "err"; }
main();
This way, you get teh following result:
> node "main.js"
test2.js:1
process.on('unhandledRejection', up => { throw up });
^
err
> $?
1
Which is a little bit better (except the stacktrace is not very clear).
I'm writing a yeoman generator and want to check some prerequisites, for example a git being installed. I can easily check this using .exec, but how do i gracefully abort generator and report error to user? I searched docs, but it seems that i'm missing some obvious way to do it. Any hints?
Throwing exception will of course abort generator, but is it a best way? Maybe something more user friendly? Not all yeoman users are able to read js exceptions.
The current state of error handling in the popular generators is quite diverse:
in the most cases they just log the error and return from the action and let the subsequnt actions run and return 0 status code:
generator-karma's setupTravis method:
if (err) {
this.log.error('Could not open package.json for reading.', err);
done();
return;
}
or set a custom abort property on error and skip further actions with cheking on the abort property but still return 0 status code:
generator-jhipster's CloudFoundryGenerator:
CloudFoundryGenerator.prototype.checkInstallation = function checkInstallation() {
if(this.abort) return;
var done = this.async();
exec('cf --version', function (err) {
if (err) {
this.log.error('cloudfoundry\'s cf command line interface is not available. ' +
'You can install it via https://github.com/cloudfoundry/cli/releases');
this.abort = true;
}
done();
}.bind(this));
};
or manually end the process with process.exit:
generator-mobile's configuringmethod:
if (err) {
self.log.error(err);
process.exit(1);
}
However none of these methods provide a good way to signal to the environment that something went wrong except the last one but directly calling process.exit is a design smell.
Throwing an exception is also an option but this presents also the stackstrace to the user which is not always a good idea.
The best option would be use the Environment.error method, which has some nice advantages:
the Environment is exposed thorough the env property of the yeoman.generators.Base
an error event is emitted which is handled by the yo cli code
the execution will result in a non zero (error) status code which is override-able
by default yo will display only the message and no stacktrace
the stacktrace can be optionally displayed with providing the --debug built-in option when re-running the generator.
With using this technique your action method would look like this:
module.exports = generators.Base.extend({
method1: function () {
console.log('method 1 just ran');
this.env.error("something bad is happened");
console.log('this won't be executed');
},
method2: function () {
console.log('this won't be executed');
}
});