When running PHPhotoLibrary.authorizationStatus(for: .readWrite), it fires the permission request. If I comment the line out in override func viewDidLoad(), the permission request is not fired. And I need to know if permissions are already granted.
Help is greatly appreciated,
Kind regards
Related
Apple has deprecated the authorizationStatus method. Is there a way to know which is the status of the authorisation for my App?
Let's say that a user granted the permission in a previous session and with another app session I wanted to show or hide a button depending on the fact that the user has granted the permission or not. How can I get this information now that authorizationStatus is no longer available?
You should use locationManagerDidChangeAuthorization delegate.
see documentation: CLLocationManager:
class func authorizationStatus() -> CLAuthorizationStatus
is deprecated.
there are new instance property that available since iOS 14
var authorizationStatus: CLAuthorizationStatus - The current
authorization status for the app.
I'm using Twilio voice quickstart code https://github.com/twilio/voice-quickstart-swift.
When I make a client to client call, call doesn't connect. CallKit runs in the background though, I can see the green notification bar when I send app in the background.
Following is the error:
StartCallAction transaction request failed: The operation couldn’t be completed. (com.apple.CallKit.error.requesttransaction error 7.)
As you can see Googling doesn't help as there doesn't seem to be any solution around?
Does anyone know how to fix or debug it further?
Updated:
Attaching VoIP settings, it's certainly enabled.
Problem is in your code which you write to handle and initialise variables. There is nothing wrong in the Twilio sdk either so don't look there. Anything which you are doing beyond twilio sample code is the place to look for the problem.
I've also wasted months of my time on similar issue and found out that there was issue with initialising one variable.
You are trying to request CXStartCallAction right after another CXStartCallAction was requested. You need to end the first call correctly.
In any case you must follow correct sequence of actions. Once you user wrong action in a sequence, CallKit will return one or another error.
And DO NOT request one action immediately after another is processed. There should be some time between two requests. For example, you initiated CXStartCallAction, then you checked that user is offline and trying to end the call. If that check is quick, then "end action" may result in error. You need to wait a few milliseconds before cancelling the outgoing call.
Twilio developer evangelist here.
Have you enabled capabilities for Voice over IP in the project settings?
Try to initialize CXProvider and CXCallController sooner, before requesting CXStartCallAction
I had the same problem because the Provider and the CallController have been lazy loaded.
It looks like that the CXProvider initWithConfiguration runs asynchronously which means you need to call this early otherwise you run into the risk of having a call without the completion of the initWithConfiguration function.
Thanks to #Allen for pointing me in the right direction.
This question already has answers here:
Why does viewWillAppear not get called when an app comes back from the background?
(7 answers)
Closed 4 years ago.
I am working on project that needs to load the users contacts. For this I need the contacts information. Thus I am using Contacts Framework. It is easy to use and really very fast also. I am new to iOS so I just used the code snippet of getting contacts information.
What I have done: But I have problem, and that is when the user install the application and go the respective ViewController, the ViewController shows Dialog for permission. There user can Deny and Allow the permission. My app works well when user allows the permission but does not work in other way. So I used a function to check if user has given my app the permission or not.
So I read that when user has not granted the permission we can not do anything. Except we can take him to settings where he can allow the permission and get back the app. here is the code I am using to go to the settings app.
if let appSettings = URL(string: UIApplicationOpenSettingsURLString + Bundle.main.bundleIdentifier!) {
if UIApplication.shared.canOpenURL(appSettings) {
UIApplication.shared.open(appSettings)
}
}
Problem:
now my problem is critical, and that is I know I can take user to
settings view, now what if user still do not allow the Permission and
just get back to our App, in this case how to check if user has given
us permission or not??
I am new to iOS and swift so please help me through example. I have searched a lot but did not find anything. In Android there are callback and also onResume could be used, but in iOS I used ViewWillAppear thinking as equivalent of onResume but that did not work.
If you had a refresh button you could do something like the following:
#IBAction func refreshButtonPressed(_ sender: UIButton) {
ContactsService.sharedInstance.CNContactStore.requestAccess(to: .contacts, completion: { granted, error in
if !granted {
//TODO: - Do something (e.g)
self.[method to display an access denied alert to the user]
return
} else {
[insert your code here]
}
}
Also, as another user has stated in a reply to your original question: Why does viewWillAppear not get called when an app comes back from the background? may be of interest to you. You may want to call the contents of the ContactsService.sharedInstance.CNContactStore.requestAccess( .... { } block inside a function and hook that up to a listener for the UIApplication.willEnterForegroundNotification
https://developer.apple.com/documentation/contacts
https://developer.apple.com/documentation/contacts/cncontactstore
https://developer.apple.com/documentation/contacts/cncontactstore/1402873-requestaccess
I'm having strange problem with UITableViewController. I'm requesting location service authroization inside viewDidLoad method, and I could see alertbox appear. However, this alertbox stays appear for couple of seconds then disappears. Why is this happening?
override func viewDidLoad() {
let locationManager = CLLocationManager()
locationManager.requestAlwaysAuthorization()
}
I tried this code inside the UIViewController that loads this UITableViewController and encountered different problem. This time, only push notification service request alertbox is displayed and location service request is entirely ignored. I'm guessing it is because push notification service request is not from me but from ios, and my location service request got overwritten by the ios notification request. It's my assumption correct or is there any explination for this behaviour?
Your location manager is going out of existence because it is a local variable. Make it a persistent property:
let locationManager = CLLocationManager()
override func viewDidLoad() {
// ...
}
Also I'm not sure whether it's a good idea to do this in viewDidLoad. The view is not yet in the interface; in fact, there may be no interface yet.
But there are a lot of other things wrong with your code. You may already have authorization, or authorization may already have been denied, in which case there is no point requesting it. In general authorization requests are a much more elaborate business than your simple-minded code makes out.
The Apple documentation for AVAudioSession Class Reference displays the following about the "requestRecordPermission:" method:
…… This method always returns immediately: if the user has previously
granted or denied recording permission, it executes the block when
called; otherwise, it displays an alert and executes the block only
after the user has responded to the alert.
That is clear,but my problem is this: How can I get back (for testing purposes) to the situation where the user has not yet granted or denied recording permission? I tried to completely remove the app from the device but it did not work.
You have to reset location and privacy.
Settings -> General -> Reset -> Reset Location & Privacy