Get iPhone Carrier Reception Status? (not internet) - iphone

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

Related

How to check to which Bluetooth device my iPhone is connected

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

IOS - How to determine carrier name of phone numbers and last call charge for outgoing call in iPhone

Can anyone please tell me how to find out the last call charge of an outgoing call and the carrier name of an outgoing call phone number? Is there an API for getting the details of the carrier name and call cost in an iPhone?
It is not even about confidentiality or security, although if this info was available, it would be a serious security concern.
The phone does not understand anything related to billing in a wireless/cellular network. The phone just tries to register on a network, but if the account is inactive or not in good standing, the network will generally reject an attempt to register.
Billing is pretty much handled by the operator's core network (usually the MSC in a circuit switched network, SGSN in a UMTS packet switched network, PDSN in a CDMA/EVDO packet switched network, or the MME in an LTE packet switched network), so it is impossible to get any information on remaining minutes or costs related to a phone call or data transfers. Any app that provides this information usually does it by approximating it. Usually it just tracks this info on the phone-level and it may not be official.
The Carrier Name might be available depending on the provider and the technology. In most technologies, the MCC & MNC of the network will be available, and you can access that carrier name. This link gives you an idea of how to do it for iOS4, but the short version is:
#import <CoreTelephony/CTCarrier.h>
#import <CoreTelephony/CTTelephonyNetworkInfo.h>
// Setup the Network Info and create a CTCarrier object
CTTelephonyNetworkInfo *networkInfo = [[[CTTelephonyNetworkInfo alloc] init] autorelease];
CTCarrier *carrier = [networkInfo subscriberCellularProvider];
// Get carrier name
NSString *carrierName = [carrier carrierName];
if (carrierName != nil)
NSLog(#"Carrier: %#", carrierName);
// Get mobile country code
NSString *mcc = [carrier mobileCountryCode];
if (mcc != nil)
NSLog(#"Mobile Country Code (MCC): %#", mcc);
// Get mobile network code
NSString *mnc = [carrier mobileNetworkCode];
if (mnc != nil)
NSLog(#"Mobile Network Code (MNC): %#", mnc);
No there isn't. No there shouldn't be. No there can't be. That stuff is confidential.

iOS iTunes store country

i am wondering if there is a solution to find out, in which country the user downloaded an application.
For example: app x has been downloaded in USA when the user opens up the app, the app will check in which country it was downloaded. In this example the the return would be "USA"
Does any one hase an idea on how to solve this?
If you have any In-App Purchases available, you can read the locale from the SKProduct. As a fallback, use the device's locale.
NSLocale *locale;
SKProduct *baseProduct = nil; // replace as applicable
if (baseProduct) {
locale = baseProduct.priceLocale; // from the user's credit card on iTunes
} else {
locale = [NSLocale currentLocale]; // from user preferences
}
NSString *countryCode = [locale objectForKey:NSLocaleCountryCode];
NSLog(#"Two-letter country code: %#", countryCode);
There might be a good enough correlation between the iTunes store country and the locale a user sets. This depends on your needs - if this does not suffice, I don't think there is a way to know which actual store an app was downloaded from.
To retrieve that locale, you could use:
NSString *localeIdentifier = [[NSLocale currentLocale] localeIdentifier];
Hope this is sufficient for your needs.
It's not possible to check "which" App Store an app was downloaded.
If you need to do anything location-based, you should look at CLLocation to obtain a user's current location, however it may seem intrusive for the app to ask a user for their location if it's not apparent why it would need the location.
You could also check for the language on a users device, such as en_gb for Britain, dk for Denmark, en_ca for Canada, etc. While this doesn't completely cover when people in some countries have set the language to something else than the countries native language, it's better than nothing.
SKStoreFront, introduced in iOS 13 SDK seems to do the job.
Swift
if let storefront = SKPaymentQueue.default().storefront {
print(storefront.countryCode) // Returns an Alpha-3 country code (USA, GBR etc.)
}
Obj C
[SKPaymentQueue defaultQueue].storefront.countryCode; // Returns an Alpha-3 country code (USA, GBR etc.)
You should be able to access the SKStoreFront instance by adding the StoreKit framework to your project, even if your app does not offer any purchases.

GPS location is on/off in iphone?

I want to do like, when the app start, app check for iPhone GPS ON or OFF? if GPS off then app quite.
What do you want exactly to know, location service or does user granted access to the location service?
If first, than depending on iOS version you can use:
on iOS pre 4.x:
CLLocationManager *testLocationManager = [[CLLocationManager alloc] init];
BOOL servicesEnabled = [testLocationManager locationServicesEnabled];
[testLocationManager release];
on iOS 4.x+:
BOOL servicesEnabled = [CLLocationManager locationServicesEnabled];
If second, than:
on iOS pre 4.x: there is no quick snippet, you have to wait if didFailWithError or didUpdateToLocation will be called and if second, than user granted access
on iOS 4.x+:
BOOL accessGranted = [CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorized;
And than easily use exit(0) if you option not reached. And yes, try notify user about what you is about to quit the app.
You need to create a CLLocationManager and ask it for locationServicesEnabled. This will tell you if location services are available.
Note however that Apple does not allow apps to quit on their own, the user needs to press the home button instead. If you discover location services are unavailable, you need to tell the user that your app needs them and they should be activated for your app to work properly.

Is there any API to find MCC for iPhone? [duplicate]

As per the subject - is there an API to get the MCC/MNC on iPhone OS 2.1 or above?
Added in iOS4
CTTelephonyNetworkInfo *netInfo = [[CTTelephonyNetworkInfo alloc] init];
CTCarrier *carrier = [netInfo subscriberCellularProvider];
NSString *mcc = [carrier mobileCountryCode];
NSString *mnc = [carrier mobileNetworkCode];
http://developer.apple.com/library/ios/#Documentation/NetworkingInternet/Reference/CTCarrier/Reference/Reference.html
No, mobile network information is not available through the API. If you're looking for a unique device ID, take a look at UIDevice's uniqueIdentifer method; if you're looking for the country the device is in, you need Location Services; if you want a good indication of the user's home region, take a look at NSLocale; for anything else, just ask the user.
I think you could just get the phone number of the iPhone and parse it out for the country code.