How to get IMEI on iPhone? - ios

I want to get IMEI on iPhone. I try to use the following code:
#import "Message/NetworkController.h"
NetworkController *ntc=[[NetworkController sharedInstance] autorelease];
NSString *imeistring = [ntc IMEI];
But NetworkController is not found.
I also find that I can get uniqueIdentifier using:
UIDevice *myDevice = [UIDevice currentDevice];
NSString *identifier = myDevice.uniqueIdentifier;
But this cannot help me to get IMEI.
How to get IMEI on iPhone?

You can't get IMEI on iPhone anymore. You may have to use UDID instead. See other answers.
In the past, you could use the header file "Message/NetworkController.h" posted on ericasadun.com.
http://ericasadun.com/iPhoneDocs300/_network_controller_8h-source.html (It's been removed now)
You would add the NetworkController.h file and the private framework "Message.framework" to your project, then import that header file to use the original method I found to get the imei number:
NetworkController *ntc = [NetworkController sharedInstance];
NSString *imeistring = [ntc IMEI];
That hack doesn't work anymore. App will be rejected by Apple.

You can't find the IMEI programmatically on the iPhone.

There is no official way to get it, but in Apples private framework CoreTelephony.framework there is a method CTGetIMEI that might help you.

I'm sure there are reasons you can't do this easily. Auto-unlocker app? I don't think so. I'm sure Apple and AT&T wouldn't like it too much either.
*#06# is the way to get it manually.

I made a search only here in stackoverflow and the conclusion is that Apple dont allow anymore to find phone EMEI after iOS 6.
You can identify a device using UDID.
I found my answer here https://stackoverflow.com/a/19927376/2283308

add a head file "CoreTelephony.h" to your project
CoreTelephony.h
struct CTServerConnection
{
int a;
int b;
CFMachPortRef myport;
int c;
int d;
int e;
int f;
int g;
int h;
int i;
};
struct CTResult
{
int flag;
int a;
};
struct CTServerConnection * _CTServerConnectionCreate(CFAllocatorRef, void *, int *);
void _CTServerConnectionCopyMobileIdentity(struct CTResult *, struct CTServerConnection *, NSString **);
add the following code to your class
#import "CoreTelephony.h"
struct CTServerConnection *sc=NULL;
struct CTResult result;
void callback() { }
now, you can get imei easily
NSString *imei;
_CTServerConnectionCopyMobileIdentity(&result, sc, &imei);

https://www.telesign.com/products/phone-id
There is an SDK by a company called TeleSign that can get a device's IMEI number (in addition to a list of other things such as carrier, the home address of the device's owner, etc.). Some of the biggest apps in the store use this provider (like Tinder and Evernote). I don't work for the company or ever have, or ever want to, and I've never used any of their products. I also don't know if Apple would reject this API usage. But if you want a Swift/Objecive-C interface for getting an IMEI number, this is one.

Related

With iOS, is it possible to detect when an iPhone is turned on?

It would be incredibly useful for a project I am working on that if, when the iOS device is turned on and boots up, I can save a timestamp of that occurrence. Is there any code I can run that will store this variable? If not, is there a way I can check without opening the app if an iPhone is on at a certain time?
Thanks!
Sorry for the confusion:
I want to make an app that has the capability to remember the last time an iOS device was turned on.
You can read the kern.boottime sysctl, which tells you when the system booted. I don't believe it would throw you out of the app store in this case:
#import <sys/sysctl.h>
- (time_t)bootTime
{
struct timeval boottime;
int item[2] = { CTL_KERN, KERN_BOOTTIME };
size_t size = sizeof(boottime);
int st = sysctl(item, 2, &boottime, &size, 0, 0);
if (st < 0)
return -1;
return boottime.tv_sec;
}
No this is not possibe in iOS.

Getting WIFI Signal strength in iPhone

I know this is a duplicate of many similar questions.But none of them were clear they where not giving proper solutions.My question is how to get WiFi signal strength in iOS devices?. I know it has done using Private API's but I don't know how to use?. Please can anyone help me please?
For ios9+
Register your app as Hotspot helper. (forums.developer.apple.com/message/30657#30657)
#import <NetworkExtension/NetworkExtension.h>
for(NEHotspotNetwork *hotspotNetwork in [NEHotspotHelper supportedNetworkInterfaces]) {
NSString *ssid = hotspotNetwork.SSID;
NSString *bssid = hotspotNetwork.BSSID;
BOOL secure = hotspotNetwork.secure;
BOOL autoJoined = hotspotNetwork.autoJoined;
double signalStrength = hotspotNetwork.signalStrength;
}
Reference:- https://stackoverflow.com/a/32971064/988169
Apple restrict (wireless private api) to use private api to find the strenth of wifi .

iOS Get Link Speed (Router Speed Test)

I want to test speed of connected router(wifi modem) from iOS app.
I've found something here Get link speed programmatically? but could not found sockios.h and ethtool.h
Is it possible to port this code to Objective-C or is there another way?
--
Sorry for the missing info and my poor english.
I want to test link speed (tx rate) between ios device and connected wifi modem.
There was a property named txRate in CWInterface class. I want to get that data in Cocoa Touch.
/*!
* #property
* #abstract Current transmit rate (Mbps) of the CoreWLAN interface.
* #discussion Dynamically queries the interface for the current transmit rate.
*/
#property(readonly) NSNumber *txRate NS_DEPRECATED_MAC(10_6, 10_7);
Finally I've found the solution.
#include <ifaddrs.h>
#include <net/if.h>
+ (double)getRouterLinkSpeed
{
BOOL success;
struct ifaddrs *addrs;
const struct ifaddrs *cursor;
const struct if_data *networkStatisc;
double linkSpeed = 0;
NSString *name = [[NSString alloc] init];
success = getifaddrs(&addrs) == 0;
if (success)
{
cursor = addrs;
while (cursor != NULL)
{
name=[NSString stringWithFormat:#"%s",cursor->ifa_name];
if (cursor->ifa_addr->sa_family == AF_LINK)
{
if ([name hasPrefix:#"en"])
{
networkStatisc = (const struct if_data *) cursor->ifa_data;
linkSpeed = networkStatisc->ifi_baudrate;
}
}
cursor = cursor->ifa_next;
}
freeifaddrs(addrs);
}
return linkSpeed;
}
You can use NSURLConnection to connect to your test server and download a preset file of something like 1 MB. Use the NSURLConnection delegate -connection:didReceiveData: and -connectionDidFinishLoading:to track the download 'so far' and compute the download speed from that.
There is currently no official (or Apple approved) way to get LinkSpeed on iOS. There were loop holes in the past which were closed unfortunately.
The most similar metric you can use to estimate LinkSpeed is measure wifi speed by sending UDP packets on the local network and measuring their sending rate. This is called IP packet sending bit rate and is defined in this ITU standard https://www.itu.int/rec/T-REC-Y.1540/en
The iOS implementation of that wifi speed measurement is in our iOS SDK which you can find here:
https://github.com/speedchecker/speedchecker-sdk-ios
This implementation is the closest you can get to estimate router wifi speed without actually placing any payload files on the router itself.

Any way to differentiate between code running on a iPhone simulator vs live device? [duplicate]

This question already has answers here:
How can I programmatically determine if my app is running in the iphone simulator?
(21 answers)
Closed 9 years ago.
I have some logic in my iOS application that I would like to execute differently when testing on an the iPhone simulator vs when its running on a live device.
Is there any way to determine in objective C whether the logic is being executed on one or the other?
Currently, I comment out some code before I deploy to my physical iPhone. Not convenient.
The reason behind the (slightly) different execution paths btw, is that my application utilizes data that is time/date dependent. On the simulator i have a static data set loaded so my testing takes that into account (i.e doesnt use current systems dates etc).
On the live device, the data is always fresh so no such issues.
It really should be known at compile time, as per TARGET_IPHONE_SIMULATOR macro. If you need to do a runtime check:
bool is_simulator()
{
NSString *model = [[UIDevice currentDevice] model];
return [model isEqualToString:#"iPhone Simulator"];
}
or without using objective C you could perhaps use sysctl as follows:
static int32_t sysctl_int32(const char* name)
{
int32_t val = 0;
size_t size = sizeof(val);
sysctlbyname(name, &val, &size, NULL, 0);
return val;
}
bool is_simulator()
{
int32_t cpu_type = sysctl_int32("hw.cputype");
return (cpu_type == CPU_TYPE_I386 || cpu_type == CPU_TYPE_X86_64)
}
Try
if (TARGET_IPHONE_SIMULATOR){
//Running on simulator
}else{
//Real one
}
Use
#if TARGET_IPHONE_SIMULATOR
// Using Simulator
#else
// Using device

Enable/Disable Wifi on non-jailbroken iOS device

This I needed for my internal app. I want to toggle wifi on ios device. Any framework is available.
I tried following code, but it provides me no help. This doesn't change my wifi settings.
{
Class BluetoothManager = objc_getClass("BluetoothManager");
id btCont = [BluetoothManager sharedInstance];
[self performSelector:#selector(toggle:) withObject:btCont afterDelay:0.1f] ;
}
- (void)toggle:(id)btCont
{
BOOL currentState = [btCont enabled] ;
[btCont setEnabled:!currentState] ;
[btCont setPowered:!currentState] ;
exit( EXIT_SUCCESS ) ;
}
From Application
notify_post("com.yourcompany.yourapp.yournotification");
From Dylib
#import <objc/runtime.h>
#import <SpringBoard/SBWiFiManager.h>
HOOK(SpringBoard, applicationDidFinishLaunching$, void, id app) {
//Listen for events via DARWIN NOTIFICATION CENTER
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL,
&NotificationReceivedCallback, CFSTR("com.yourcompany.yourapp.yournotification"), NULL,
CFNotificationSuspensionBehaviorCoalesce);
}
//THIS IS WHERE THE MAGIC HAPPENS
static void NotificationReceivedCallback(CFNotificationCenterRef center,
void *observer, CFStringRef name,
const void *object, CFDictionaryRef
userInfo)
{
[[objc_getClass("SBWiFiManager") sharedInstance] setWiFiEnabled:NO];
}
Note:
if you enounter any error on using Hook method you can refer this link it demonstrates how to hook init method found in SpringBoard to show a alert message when starting up the phone.
Warning:
You can not use this for appstore apps since private api is used.
Reference
Attribtuion
Hope this helps.
You're not going to be able to. iOS limits just how much third-party apps can interact with the underlying hardware. All applications written with the public SDK are sandboxed.
As 7KV7 says in their answer here:
They only have access to the properties and data which
Apple deems feasible to use within that sandbox. I am afraid Wi-fi
doesn't come in the list.

Resources