Good afternoon,
I am using the latest version of AudioKit (4.9 Master Branch) with Xcode 11.3 and am running into a strange permission problem. When a user launches an app for the first time, the OS asks for permission to use the microphone. After the user selects "Allow", the microphone does not work, but if you force quit the app and relaunch it the microphone works fine.
I created a function to test the state of the permission and placed it in viewDidLoad() :
func checkMic() {
switch AVAudioSession.sharedInstance().recordPermission {
case AVAudioSessionRecordPermission.granted:
print("Permission granted")
case AVAudioSessionRecordPermission.denied:
print("Pemission denied")
case AVAudioSessionRecordPermission.undetermined:
print("Request permission here")
AVAudioSession.sharedInstance().requestRecordPermission({ (granted) in
print("Mic Enabled")
})
#unknown default:
print("Not Working")
}
}
The function is only triggered during the first run but I have already initialized my AudioKit singleton class by this point. I have tried to reinitialize with no success. I have not encountered this before and am wondering if anyone else is experiencing this change or had a suggestion for it.
It seems that both the AKAnalizer and AKMicrophone are disabled when when iOS asks for permission to use the microphone. I needed to start both again. Hope this helps anyone in the same situation.
var audioCore = AudioCore.sharedInstance()
func checkMic() {
switch AVAudioSession.sharedInstance().recordPermission {
case AVAudioSessionRecordPermission.granted:
print("Permission granted")
case AVAudioSessionRecordPermission.denied:
print("Pemission denied")
case AVAudioSessionRecordPermission.undetermined:
print("Request permission here")
AVAudioSession.sharedInstance().requestRecordPermission({ (granted) in
print("Mic Enabled")
self.audioCore.microphone.start()
self.audioCore.analyzer.start()
print(self.audioCore.microphone.isStarted)
print(self.audioCore.analyzer.isStarted)
})
#unknown default:
print("Not Working")
}
Related
I don't know can I use this functionality in my UI tests on iOS, but I try it, an have problem with this.
In my UI tests I can choose Allow tracking for my app or I can decline tracking, but after all these actions, I want checkout status IDFA via ATTrackingManager.AuthorizationStatus, but this method always returns notDetermined. If I go to Settings > Privacy > Tracking, here I see that settings applied correctly (switch Allow App To Request To Track is on and switch for my app in right state (on or off)).
I don't have any idea why I recieve wrong AuthorizationStatus.
Here is my code in my XCTestCase:
import AppTrackingTransparency
enum TrackingStatus {
case authorized
case denied
case notDetermined
}
func map(_ status: ATTrackingManager.AuthorizationStatus) -> TrackingStatus {
switch ATTrackingManager.trackingAuthorizationStatus {
case .notDetermined:
return .notDetermined
case .authorized:
return .authorized
default:
return .denied
}
}
func advertisingTrackingStatusCheckout(status: TrackingStatus) {
print("IDFA status: \(ATTrackingManager.trackingAuthorizationStatus)")
var currentTrackingStatus: TrackingStatus {
return map(ATTrackingManager.trackingAuthorizationStatus)
}
guard currentTrackingStatus == status else {
XCTFail("IDFA status: \(currentTrackingStatus), expected: \(status)")
return
}
}
After settings IDFA status in my UI test, i call this method, ex. advertisingTrackingStatusCheckout(status: TrackingStatus.denied)
But it always returns notDetermined.
It behaviors have only one exception: If I manually set switch Allow App To Request To Track to off-state, calling the ATTrackingManager.trackingAuthorizationStatus will returns denied.
Delete the App, And call your function in sceneDidBecomeActive with delay. So once your app become active then it will shown. Am facing the same issue now its resolved. Like this
func sceneDidBecomeActive(_ scene: UIScene) {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
self.requestPermission()
}
}
func requestPermission() {
if #available(iOS 14, *) {
ATTrackingManager.requestTrackingAuthorization { status in
switch status {
case .authorized:
// Tracking authorization dialog was shown
// and we are authorized
print("Authorized Tracking Permission")
// Now that we are authorized we can get the IDFA
case .denied:
// Tracking authorization dialog was
// shown and permission is denied
print("Denied Tracking Permission")
case .notDetermined:
// Tracking authorization dialog has not been shown
print("Not Determined Tracking Permission")
case .restricted:
print("Restricted Tracking Permission")
#unknown default:
print("Unknown Tracking Permission")
}
}
} else {
// Fallback on earlier versions
}
}
It might be simple question.
I'm using Reactive Location, to get user's current location, please find my below code,
ReactiveLocation.authorizeAction.apply(.whenInUse).startWithResult {
switch $0 {
case let .success(status):
print("Current user permission status on WhenInUse is \(status)")
case let .failure(error):
print(error.localizedDescription)
}
}
Here error is .restricted and .denied, I want user to be presented with the error message according to error. How to identify it.
In above code, completion block looks like this,
Please help me to solve the issue.
I suggest learning more about Swift enum.
You can check for .restricted and .denied the same way you checked for .success and .failure.
The only difference is LocationAuthorizationError doesn't have associated values.
ReactiveLocation.authorizeAction.apply(.whenInUse).startWithResult {
switch $0 {
case let .success(status):
print("Current user permission status on WhenInUse is \(status)")
case let .failure(actionError):
switch actionError {
case .producerFailed(.restricted):
print("Authorization Restricted")
case .producerFailed(.denied):
print("Authorization Denied")
default:
break
}
}
}
class func checkPhotoLibraryPermission() {
// TODO: #Umer Complete this process as discussed
let photoAuthorizationStatus = PHPhotoLibrary.authorizationStatus()
switch photoAuthorizationStatus {
case .authorized:
print("Access is granted by user")
case .notDetermined:
PHPhotoLibrary.requestAuthorization({
(newStatus) in
print("status is \(newStatus)")
if newStatus == PHAuthorizationStatus.authorized {
/* do stuff here */
print("success")
}
else {
}
})
print("It is not determined until now")
case .restricted:
print("User do not have access to photo album.")
case .denied:
print("User has denied the permission.")
}
}
in case .denied
If we come first time to access photo library access permission is asked to user and if user do not allow permission, next time when user tries to access photo library it directly goes to settings where user can manually set permissions.
I have app in which I have to add events in default calendar which worked fine until iOS 10. Now in iOS 10 it is not granting access. I have set use legacy swift language version to yes. My code is
let eventStore = EKEventStore()
switch EKEventStore.authorizationStatusForEntityType(EKEntityType.Event) {
case .Authorized:
//access
case .Denied:
print("Access denied")
case .NotDetermined:
eventStore.requestAccessToEntityType(EKEntityType.Event, completion:
{[weak self] (granted: Bool, error: NSError?) -> Void in
if granted {
//access
} else {
print("Access denied")
}
})
default:
print("Case Default")
}
While debug my app is crashing at eventStore.requestAccessToEntityType in Xcode 8.
My app is live and I need to solve it. Any help is appropriated. Thanks in advance.
On iOS 10 builds, you need to set a description message for the permission alert on Info.plist
Important: An iOS app linked on or after iOS 10.0 must include in its
Info.plist file the usage description keys for the types of data it
needs to access or it will crash. To access Reminders and Calendar
data specifically, it must include NSRemindersUsageDescription and
NSCalendarsUsageDescription, respectively.
from Apple Docs
let eventStore = EKEventStore()
switch EKEventStore.authorizationStatus(for: .event) {
case .authorized: break
//access
case .denied:
print("Access denied")
case .notDetermined:
eventStore.requestAccess(to: .event, completion:
{[weak self] (granted: Bool, error: Error?) -> Void in
if granted {
//access
} else {
print("Access denied")
}
})
default:
print("Case Default")
}
With XCode 8 and swift 3, this is the new format. Did you test your app on iOS 10.
In my audio recording application I'm trying to ask the user for access to the microphone. However, I keep getting the .NotDetermined case and no prompt. The documentation states that the Not Determined case will prompt the user but that doesn't seem to be the case.
#IBAction func recordTapped(recordButton: UIButton!){
let microPhoneStatus = AVCaptureDevice.authorizationStatusForMediaType(AVMediaTypeAudio)
switch microPhoneStatus {
case .Authorized:
// Has access
println("access")
vibrate()
recordNow()
case .Denied:
// No access granted
println("denied")
case .Restricted:
// Microphone disabled in settings
println("mic disabled in settings")
case .NotDetermined:
// Didn't request access yet
AVCaptureDevice.requestAccessForMediaType(AVMediaTypeAudio, completionHandler: nil)
println("Not determined")
}
}