I have two options to establish a Bluetooth connection with my iPhone.
Audio
Calls
(See image)
When I'm connected to the audio channel I can get the name of the device I'm connected to using AVAudioChannel as such:
let connectedAvSession = AVAudioSession.sharedInstance().currentRoute
let outputs = connectedAvSession.outputs
print("OnBoardingCarSelectionViewController, createArray() =>\n currently connected devices via audio session = ", outputs)
for output in outputs {
let name = output.portName.description
let uid = output.uid.description
let port = output.portType.rawValue
presentAlert("AV Channel", message: "name: \(name), uid: \(uid), port: \(port)")
}
When I change the connection to calls, I can't get the name of the device anymore.
Is there a way I can know what I'm connected to when the connection is only set for phone calls?
An EAAccessoryManager object coordinates the attached accessories for
an iOS-based device. Use the shared accessory manager to retrieve a
list of connected accessories, and start and stop the delivery of
connection and disconnection notifications.
Important :-
Blockquote
Phone and iPad apps running on Macs with Apple silicon
never receive connection notifications.
below will be used for getting the connected Device:-
var connectedAccessories: [EAAccessory]
The accessory objects correspond to the list of currently connected accessories.
link for your reference:- https://developer.apple.com/documentation/externalaccessory/eaaccessorymanager/1613821-connectedaccessories
Related
As per the requirement, iOS app needs to identify the currently connected networks whether its open or password protected and display an alert message to the user.
I have gone through the link below but could not make it work https://developer.apple.com/documentation/networkextension/nehotspotnetwork/1618930-issecure
I have received entitlements from the apple, But could not see any sample project.
I expect the code should be similar to the below (just to make the question clear, not real code)
let network = NEHotspotNetwork() // get the currently connected network
let isSecured = network.isSecure // get the current security
print("isSecure \(isSecured)") //printing the security is password protected or not
Few things to consider to achieve this
Request entitlement from apple
Your device target is iOS 14.*
Code below
if #available(iOS 14.0, *) {
NEHotspotNetwork.fetchCurrent { network in
if let network = network {
print("is secured ((network.isSecure))")
}
}
}
I want to develop an SOS application. When I am trying to use URL schema openURL(), it will display an alert but my requirement is to connect the call without any alert or popup while trying to call. So I found a solution using CallKit. When I implemented CallKit in my application it does not ask for any permission, the outgoing call is placed but the callee doesn't get any call. Is there any solution for this?
I have tried the following code for connecting the call.
#IBAction func buttonCallTapped(_ sender: Any) {
let provider = CXProvider(configuration: CXProviderConfiguration(localizedName: "My App"))
provider.setDelegate(self, queue: nil)
let controller = CXCallController()
let transaction = CXTransaction(action: CXStartCallAction(call: UUID(), handle: CXHandle(type: .phoneNumber, value: "\(number)")))
controller.request(transaction, completion: { error in })
DispatchQueue.main.asyncAfter(wallDeadline: DispatchWallTime.now() + 5) {
provider.reportOutgoingCall(with: controller.callObserver.calls[0].uuid, connectedAt: nil)
}
}
You just can't make standard native calls through CallKit. The CallKit framework, as clearly stated in the documentation, is meant to be used to develop custom VoIP applications and integrate them with the native phone interface.
Any iOS application can't make native call without user action.
An alert will be shown with phone number and two buttons will be available "Call" and "Cancel" which is presented from the OS level.
Just like we are showing popup to delete photos from Photos app.
Solution
If you want to implement SOS Application (Yes its possible using VoIP
service), But you can place calls when app is active (Can be done
without user action given internet connection is there.)
Note: The receiving side also should support VoIP.
How to Implement VoIP
We need permission of Voice over IP services to make calls in between iPhone devices.
VoIP app must have background mode enabled in the Xcode Project >
Capabilities pane. Select the checkbox for Voice over IP
Also CallKit is indented only for VoIP Apps, If you really want to implement the VoIP follow CallKit Tutorial
I DO NOT want to use the following:
if let url = URL( string: "tel://4151231234" )
{
UIApplication.shared.open( url, options: [:] )
}
Instead, I would like to have a list of supported URLschemes in the device that allows making phone calls. Something that would result in a list a bit like the following:
"tel://", "whatsapp://", "facetime://", "Hangout://", etc.
The problem using the "tel://" URL scheme is that iOS returns
iPhone Calls Not Available" on all devices that are not paired
with an iPhone even though they have VOIP apps that supports phone calls.
I do not want to become a VOIP app myself (using CallKit).
But I do not mind using using CallKit IF I don't implement
the entire API to become a phone app.
The Contact App has the behavior that I am looking for:
- When Selecting a contact (in the Apple's contact app),
Tap on "Call" at the top
- A pop up list of applications supporting phone calls is listed
including 'Call', "Facetime" and "Hangouts" (in my iPad).
I would like to have the list that allows the Contact app to know which apps (and also which URLschemes) can be used to make phone calls.
I bet it is simple... I just don't know ;( Help me please :<
I DO NOT want to use the following:
if let url = URL( string: "tel://4151231234" )
{ UIApplication.shared.open( url, options: [:] )
}
What would be the code to create a list of apps/URLscheme that support making phone calls?
I am trying to make sure Firebase has a connection before continuing to load the app. I'm using the code from Firebase's own code sample. I have placed it in the ViewDidLoad function on my home view controller:
let connectedRef = Database.database().reference(withPath: ".info/connected")
connectedRef.observe(.value, with: { snapshot in
if let connected = snapshot.value as? Bool, connected {
print("Connected")
} else {
print("Not connected")
// show alert here
}
})
The problem is that the above code always shows "Not Connected" before then showing "Connected". This is a problem because when the app is not connected, it's supposed to show an alert, and the alert will then fire every time the user opens the app.
Is this expected behavior? If so, is there a way around it?
How do I check for Firebase connectivity without Firebase returning that it's not connected first every time?
The behavior you're observing is expected. The Firebase SDK can't establish its connection immediately upon startup. There is always going to be some latency between launch and whenever a connection is first available.
Also, I don't think this strategy is a good idea, because mobile connections can be intermittent and flakey. Firebase can not possibly ensure that your app will retain a good connection even after it's first established. Your app will be easier to use if you assume that it doesn't have a connection all the time. Users have come to expect some level of offline usage, and Realtime Database supports that to some degree with offline data persistence.
I need to know if the user could theoretically make a phone call.
Does anyone know how to "return true" (using Cocoa iOS) when the user's iPhone is able to connect to the carrier's network? (not the internet)
Or how to programmatically tell "how many bars of reception" the user has?
Link your application against the CoreTelephony.framework
You can check the CTCarrier object and see if you've a valid result (!=nil) for some property that require a connection with the Phone Provider.
For example, below there's a snip of code that check against the mobileNetworkCode property of CTCarrier. This property is != nil if-and-only-if the device is connected to a Phone Provider (your desired task, user able to make a phone call, is included in the state described above).
CTTelephonyNetworkInfo *netInfo = [[CTTelephonyNetworkInfo alloc] init];
CTCarrier *carrier = [netInfo subscriberCellularProvider];
//The value for this property is nil if any of the following apply:
// - The device is in Airplane mode.
// - There is no SIM card in the device.
// - The device is outside of cellular service range.
NSString *mnc = [carrier mobileNetworkCode];
if(!mnc) {
//if we're here, than probably we're disconnected from the Phone Provider
}
netInfo.subscriberCellularProviderDidUpdateNotifier = ^ (CTCarrier * carrier) {
//this block is executed each time we've a change to the state of the carrier
//be sure to check the carrier object, in order to see is we're connected to a
//phone provider.
};
more info at the Apple Developer Documentation url: http://developer.apple.com/library/IOs/#documentation/NetworkingInternet/Reference/CTCarrier/Reference/Reference.html