How to detect app was reopened after changing settings? - permissions

I am using simple permissions plugin to request contacts permissions in my flutter app.
When user presses on 'Don't ask Again' option and denies the permission, I am giving a button which opens settings using openSettings().
Now, if User enables the permissions and presses back to come on the app, how do I detect that permission has been granted?
Here is some code to give an idea-
Text(
'Permission to access Contacts was denied.\nPlease press Settings to provide permissions and continue connecting!',
),
MaterialButton(
onPressed: () {
SimplePermissions.openSettings();
},
child: Text('Settings'),
)

You can use WidgetsBindingObserver class. It allows you to detect the lifecycle of a widget.
Extend your current state with WidgetsBindingObserver and add these lines to your initState.
WidgetsBinding.instance.addObserver(this); //this sets WidgetsBindingObserver
requestPermission(); //this will request the permission on initial load.
Add the following lines to your state.
#override
void didChangeAppLifecycleState(AppLifecycleState state) {
checkPermission(); //this will check the status of permission when the user returns back from the settings page.
}
checkPermission() async {
bool res = await SimplePermissions.checkPermission(Permission.Camera);
if (!res) {
setState(() {
_statusMessage = "waiting for camera permission";
});
} else {
setState(() {
_statusMessage = "camera permission has been granted";
});
}
}
Check the full example code here.

Related

Can I use Firebase's signinWithRedirect within the dialog API of a MS Powerpoint Add-In on Safari?

I'm developing authentication with firebase for a add-in for MS Powerpoint. In order to add authentication with Google I created a button which opens a dialog box:
`function openGoogleAuthDialog() {
Office.context.ui.displayDialogAsync(hostURLofDialogComponent,
{ width: 50, height: 50 }, (result) => {
if (result.status === Office.AsyncResultStatus.Succeeded) {
dialog = result.value;
dialog.addEventHandler(Office.EventType.DialogMessageReceived, processMessage);
} else {
console.log("Unable to open dialog box");
}
});
}`
The dialog opens successfully. Within the Dialog component i have another button that should redirect to google as well as a useEffect that is supposed to send back the result of the authentication to the parent.
`export function AuthDialog() {
const authFirebase = getAuth(firebaseApp);
const handleAuth = () => {
const provider = new GoogleAuthProvider();
signInWithRedirect(authFirebase, provider);
};
useEffect(() => {
getRedirectResult(authFirebase).then((result) => {
Office.context.ui.messageParent(JSON.stringify(result));
});
}, []);
return <button onClick={handleAuth}>Authenticate With Google</button>;
}`
The problem is, that if I click on the button it will leave the page and it seems like it's gonna redirect but then stops and comes back to the dialog component without showing me the google sign-in interface.
I tried this functionality within google chrome and brave browser and it shows the Google Sign-In Interface as expected. As MS Office Plugins are using Safari under the hood, and the functionality was behaving in the same faulty way in the Safari browser, I can imagine it's a problem with Safari. Has anyone experienced a similar issue? Your help would be much appreciated!

How do I have a user check a box to grant permissions instead of the user clicking okay on an Alert in React-Native?

The iOS version of the app requires two different permissions: Microphone and BLE. Currently, permissions are being granted on a as needed basis. However, I would like to create a page that allows a user to click on checkbox so that they can grant permission when they first start the app.
Microphone access is asked for via a method which contains the following code:
OVBluetoothManager.startDetectingNoise(NOISE_DETECT_INTERVAL);
Where NOISE_DETECT_INTERVAL is 3000.
BLE is asked for via a method that contains the following code:
OVBluetoothManager.attemptToTriggerLEPairing();
Here are the two methods inside OVBluetoothManager.m file:
RCT_EXPORT_METHOD(attemptToTriggerLEPairing)
{
[[someManager sharedInstance] getLED];
[[someManager sharedInstance] getBattery];
}
RCT_EXPORT_METHOD(startDetectingNoise:(NSInteger)timeInterval)
{
dispatch_async(dispatch_get_main_queue(), ^{
[self.noiseDetector startDetectingNoiseWithTimeIntervalInMs:timeInterval];
});
}
In both cases, the user is prompted by an Alert to grant permissions. Assuming the user grants permission, everything proceeds as usual.
In this post it was suggested that the follow code:
Permissions.request('photo').then(response => {
if (response === 'authorized') {
iPhotoPermission = true;
}
Permissions.request('contact').then(response => {
if (response === 'authorized') {
iPhotoPermission = true;
}
});
});
could grant multiple permissions at once. Is it possible to do this without using react-native-permissions?
Try this library for the checkbox on alert:
https://www.npmjs.com/package/react-native-awesome-alert

React-native Geolocation. Wait for user's response to request

iOS issue only:
I am using the following code to get the users location.
navigator.geolocation.getCurrentPosition(
(position) => {
console.log("Native GEO GOOD", position);
return resolve(position)
},
(err) => {
console.log("Native GEO BADD", err);
return reject(err)
},
{ enableHighAccuracy: false, timeout: 5000, maximumAge: 0 },
)
The above code opens a dialog box, from which the user can allow my app to geolocate.
The problem is I want to wait until the user actually responds using the dialog box before calling the error or success callback.
I tried to use: requestAuthorization(). But that just opens the dialog box and I have no way to telling when the user has accepted the request to geolocate.
What I would like to do is ask the users permission to geolocate, then after the user accepts, try to geolocate the user.
But I don't see how to do that using react-native geolocation.
If requestAuthorization() took a callback option for when the user responds to the dialog box, that would solve my issue.
In React-Native using Expo (https://expo.io) you ask for permissions using a Promise and then act on the promise (hopefully when permission is given).
Permissions.askAsync((Permissions.LOCATION)
.then(({status}) => {
//your code here after permission is granted
});
);
If you aren't using expo, there is a Component call react-native-permissions (https://github.com/yonahforst/react-native-permissions.git) that allows you to request permissions using a promise like my example but without expo. Their example shows the request setting state to let you know the permissions status which you can act on.
Permissions.request('location', { type: 'always' }).then(response => {
this.setState({ locationPermission: response })
})

Is it possible to access user's webcam by admin using RTCMultiConnection#V3

I am creating Audio/Video/Text chat application. I have successfully completed Video conferencing functionality. But I don't have any idea about accessing User's webcam without user's permission.
What exactly I want to do is Admin can access user's webcam. I have created online user's list. When admin click on a button Watch of online user, admin should be able to access user's webcam, So that admin can see from that particular user's webcam.
Can any one guide me to do that?
Super admin can see all rooms, get video from any user from any room.
You can use socket.io or otherwise PHP/mySQL to share rooms with the super-admin.
A super admin can view any user's video using "join" method:
var selectedUserId = database.getSelectedUserId();
connection.join(selectedUserId);
Super admin must set "dontCaptureUserMedia=true" to make sure he don't share his own camera. Which means that super-admin will seemlessly view videos from any user from any room.
connection.dontCaptureUserMedia = true;
var selectedUserId = database.getSelectedUserId();
connection.join(selectedUserId);
See how to send or receive custom messages using socket.io and try a demo as well.
Here is an example code for super admin:
connection.socketCustomEvent = 'super-admin-socket';
connection.dontCaptureUserMedia = true;
connection.connectSocket(function() {
connection.socket.on(connection.socketCustomEvent, function(message) {
if (message.newUser === true) {
connection.join(message.userid);
}
});
});
Here is code for all normal users. i.e. any user from any room:
connection.socketCustomEvent = 'super-admin-socket';
connection.openOrJoin('any-room-id', function() {
// this message is going toward super-admin
// super-admin will receive this message
// super-admin can view this user's camera seamlessly
// or show his name in a list
connection.socket.emit(connection.socketCustomEvent, {
newUser: true,
userid: connection.userid
});
});
See how to share rooms with super admin:
Following code is for normal users:
connection.socketCustomEvent = 'super-admin-socket';
connection.openOrJoin('any-room-id', function() {
// check if it is a room owner
if (connection.isInitiator === true) {
// room owner is sharing his room with super-adin
connection.socket.emit(connection.socketCustomEvent, {
newRoom: true,
roomid: connection.sessionid
});
}
});
Following code is for super admin:
connection.socketCustomEvent = 'super-admin-socket';
connection.dontCaptureUserMedia = true;
connection.connectSocket(function() {
connection.socket.on(connection.socketCustomEvent, function(message) {
if (message.newUser === true) {
connection.join(message.userid);
}
if (message.newRoom === true) {
// display room in a list
// or view room owner's video
connection.join(message.roomid);
}
});
});
Conclusion:
Super admin must have userid from any user to view his video.

How to change the status of the user using react-native-facebook-login

I installed react-native-google-signin. The function GoogleSignin.currentUserAsync() detects a change of the user's status when it is registered.
const user = GoogleSignin.currentUserAsync();
this.setState({user});
When I use react-native-facebook-login, how should I change the status of the user?
Basically there are two ways of using the package, one is to import the FBLogin button, the other is to create your own button and call the FBLoginManager. I am not 100% certain what do you mean by change the status of the user, but if you just want to set the state after user signs in, the idea is like this, very similar to your google code
FBLoginManager.loginWithPermissions(["email","user_friends"],(err, data) => {
if (!err) {
this.setState({user: data});
this.props.onLogin(data.credentials); // whatever your logic is
}
});
Here I am using the FBLoginManager, if you need a FBLogin example their document would be a perfect place to refer
https://github.com/magus/react-native-facebook-login
To streamline your code, you could use a framework like Invertase's React Native Firebase, which can handle Google, Facebook, and Twitter auth changes with the same API. Using this, you can just do the following:
componentDidMount() {
this.unsubscribe = firebase.auth().onAuthStateChanged((user) => {
if (user) {
// User is signed in.
} else {
// User has signed out
}
});
}