microsoft / react-native-macos

A framework for building native macOS apps with React.
https://microsoft.github.io/react-native-windows/
MIT License
3.49k stars 135 forks source link

How can i get the microphone or camera permission in react-native-macOS, i am using react-native-permissions #2107

Open MuhammadBilal164 opened 6 months ago

MuhammadBilal164 commented 6 months ago

i want to implement call functionality in macOS and i want mircrophone permission, but in app i am using react-native-permissions which is not available for macOS platform

Saadnajmi commented 6 months ago

I think you'd have to open an issue or contribute a change in the react-native-permissions repo to support macOS. I'm not sure how easy or simple that task would be

MuhammadBilal164 commented 6 months ago

@Saadnajmi i have created native method which takes permission of camera and microphone and export that method to JS and call that method from JS

create a method in native Module `- (void)requestForCameraAndMicrophonePermission { [AVCaptureDevice requestAccessForMediaType:AVMediaTypeAudio completionHandler:^(BOOL granted) { if (granted) { ..... Your logic/ send event to JS } else { ..... Your logic/ send event to JS } }];

[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
    if (granted) {
       ..... Your logic/ send event to JS 
    } else {
       ..... Your logic/ send event to JS 
    }
}];

}`

You can also export this method directly but i call this method separately RCT_EXPORT_METHOD(requestForPermission){ [self requestCameraAndMicrophonePermission]; }

Saadnajmi commented 6 months ago

@MuhammadBilal164 is that the same code as iOS, implying that most of the permission requesting code is cross platform between iOS and macOS? If so, it might be easy to add macOS support to react-native-permissions