cancelPeripheralConnection invokes didFailToConnectPeripheral - ios

I'm writing the app which uses CoreBluetooth framework. Everything is fine except one thing. According to Apple documentation for CBCentralManager, calling cancelPeripheralConnection: method causes invoking of centralManager:didDisconnectPeripheral:error: delegate method, but in my case centralManager:didFailToConnectPeripheral:error: is invoked. Any clues why is that?
Thanks for every help.
Edit
I'm not connected to peripheral, but I have pending connection. To be specific, I call connectPeripheral: method and when app is waiting for connection, user taps "Cancel" button. Then, I call cancelPeripheralConneciton: and later I have situation described above. The error I get has domain CBErrorDomain and description Unknown error.

Related

iOS CallKit - no 'missed call notifications'

I am using CallKit, and it is working fine, it calls on my phone properly, I can answer and deny it.
The problem is there is no 'missed call' notification when I do not answer it.
Is there any setting in CallKit that toggles it?
We were also facing the same issues, and the solution was to manage UILocalNotifications yourself. CallKit only provides triggers and callbacks for events.
Check out the method reportCall(with:endedAt:reason) on CXProvider. You can specify the end reason to let CallKit know why the call ended.
https://developer.apple.com/documentation/callkit/cxprovider/1930701-reportcall
The reasons include:
case failed - An error occurred while attempting to service the call.
case remoteEnded - The remote party explicitly ended the call.
case unanswered - The call never started connecting and was never
explicitly ended, such as when an outgoing or incoming call times
out.
case answeredElsewhere - Another device answered the call.
case declinedElsewhere - Another device declined the call.
If you call reportCall with a reason of unanswered, then it will show up as a missed call in the recent calls section of the phone app.

CallKit error com.apple.CallKit.error.requesttransaction error 7

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.

userNotificationCenter(_:didReceive:withCompletionHandler:) not be called when a notification action is selected

I am trying to get actionable notifications working and I have gotten the actions to display when the notification is expanded, but I cannot get the delegate function to be called when I select an action. I am declaring self.notificationCenter.delegate = self in application(_:didFinishLaunchingWithOptions:), and, if I'm understanding correctly, when an action is selected it should call userNotificationCenter(_:didReceive:withCompletionHandler:), passing in the UNNotificationResponse object. But that method never gets triggered in my code. Any ideas why that may be happening?
The method you have mentioned above gets called as soon as you receive notification.
The method which is executed after clicking on action on notification is,
application:handleActionWithIdentifier:forRemoteNotification:completionHandler:
I figured out the issue. To handle notifications with content you have to add a service extension as a new target in the project. The last thing I ran was the service extension so the debugger wasn't stopping at breakpoints in the main app. I didn't know service extensions are essentially treated like completely separate apps. Since I was still in the process of working on the content of that method, what was in there was not working and it was hitting the breakpoints, so I thought it was not calling that function like it should.

Does WCSessionDelegate get an initial sessionReachabilityDidChange after activating WCSession?

When setting up a WCSession in a watchOS app, does the WCSessionDelegate's sessionReachabilityDidChange: method always get invoked immediately after calling activateSession? From my testing this seems to be true but I am not finding any confirmation of this in documentation.
I ask because if I can rely on sessionReachabilityDidChange: being called immediately after activating the session, I can remove some redundant code from applicationDidBecomeActive that checks for a reachable session and sends some initial messages to the iPhone app.
Why not just call it yourself after you are done doing all your set up? That way you don't rely on any undocumented behavior, yet you don't have to duplicate code in two places

application:didRegisterForRemoteNotificationsWithDeviceToken: is called before the prompt

During the initial app installation everything works as exptected: application:didRegisterForRemoteNotificationsWithDeviceToken: is called after the prompt *"APP Would Like To Send You Push Notifications"* is accepted or rejected. But if the app is deleted, and reinstalled again I'm getting a weird behaviour: that delegate method is called BEFORE user had a chance to accept or reject the prompt, right after it appears...
In my app I need to perform some UI action after a user accepts or rejects that prompt, and I don't see any other option other than using the above delegate method (and it seems not to work after re-install)
Any help is greatly appreciated.

Resources