I have tried the accepted answer of
How to get IMEI on iPhone?
but I got an empty string.
I saw somebody suggested to use CoreTelephony framework,
but I am not sure how to use it to obtain the IMEI.
Any suggestion on how to use this private API?
NOTE: this does not work anymore!
Haven't tested on any new iOS.
You have to add CoreTelephony.h to your project.
Make sure the header has
int * _CTServerConnectionCopyMobileEquipmentInfo (
struct CTResult * Status,
struct __CTServerConnection * Connection,
CFMutableDictionaryRef * Dictionary
);
Then you can try this code:
#import "CoreTelephony.h"
void getImei() {
struct CTResult it;
CFMutableDictionaryRef kCTDict;
conn = _CTServerConnectionCreate(kCFAllocatorDefault, ConnectionCallback,NULL);
_CTServerConnectionCopyMobileEquipmentInfo(&it, conn, &kCTDict);
NSLog (# "kCTDict is %#", kCTDict);
CFStringRef meid = CFDictionaryGetValue(kCTDict, CFSTR("kCTMobileEquipmentInfoMEID"));
NSLog (# "kCTMobileEquipmentInfoMEID is %#", meid);
CFStringRef mobileId = CFDictionaryGetValue(kCTDict, CFSTR("kCTMobileEquipmentInfoCurrentMobileId"));
NSLog (# "kCTMobileEquipmentInfoCurrentMobileId is %#", mobileId);
}
Here's the CoreTelephony.h
You can check my example project.
Note: I don't think the code works on the simulator and your app might get rejected.
Related
I use Zxing library for Barcode, QRCode and Data matrix scanning. scanning process is work fine.
I also get result string from didScanResult delegate method of ZXingWidgetController.
- (void)zxingController:(ZXingWidgetController*)controller didScanResult:(NSString *)result {
}
But I have one problem...
how to get type (Text, URL, Address book, Phone Number, Email address etc..) and format (QRCode, Data matrix or Barcode) of result.
please help...
and thanks in advance...
Assuming that currently you are using ZXingWidget right?
Since there is no way to get barcode format in this library. So what i have done is i replaced this library with ZXingObjC library to get barcode type as well as format.
-(void)captureResult:(ZXCapture *)capture result:(ZXResult *)result
{
if (!result) return;
// We got a result. Display information about the result onscreen.
NSString *formatString = [self barcodeFormatToString:result.barcodeFormat];
NSString *display = [NSString stringWithFormat:#"Scanned!\n\nFormat:
%#\n\nContents:\n%#", formatString, result.text];
}
I'm following the suggestion in the answer here for redirecting NSLog output on an iOS device to a file, which works great. The problem is that it no longer shows up in the console on the device. What I'd really like is a way to tee the stderr stream to both the console and the file. Does anyone have an idea how to do that?
I found an acceptable answer on another thread (NSLog() to both console and file).
The solution provided there is to only redirect to a file if a debugger is not detected, like this:
if (!isatty(STDERR_FILENO))
{
// Redirection code
}
Thanks to Sailesh for that answer.
Once you freopen() the file descriptor, you can read from it and do as you please with the data. Some ideas from this will be useful to you.
You could either write it back out to stdout, or try to write directly to /dev/console. I've never tried to open /dev/console on an iPhone, but I'm guessing it's possible despite being outside of the sandbox. I'm not sure how the app review process will treat it.
Or you can redirect to a TCP socket and view on a remote telnet client. No need for XCode this way!
Basically:
Create a standard C function which calls an Obj-C static method:
void tcpLogg_log(NSString* fmt, ...)
{
va_list args;
va_start(args, fmt);
[TCPLogger tcpLog:fmt :args];
va_end(args);
}
The static Obj-C method:
(void)tcpLog:(NSString*)fmt :(va_list)args
{
NSLogv(fmt, args);
if(sharedSingleton != nil && sharedSingleton.socket != nil)
{
NSString *time = [sharedSingleton.dateFormat stringFromDate:[NSDate date]];
NSString *msg = [[NSString alloc] initWithFormat:fmt arguments:args];
mach_port_t tid = pthread_mach_thread_np(pthread_self());
NSString *str = [NSString stringWithFormat:#"%#[%X]: %#\r\n", time, tid, msg];
NSData *data = [str dataUsingEncoding:NSUTF8StringEncoding];
[sharedSingleton.socket writeData:data
withTimeout:NETWORK_CLIENT_TIMEOUT_PERIOD
tag:0];
}
}
Then in your .pch file, add the following lines to override NSLog()
define NSLog(...) tcpLogg_log(__VA_ARGS__);
void tcpLogg_log(NSString* fmt, ...);
Of course more details are required to handle the TCP Socket. Working source code is available here:
https://github.com/driedler/iOS-TCP-Logger/wiki/About
I'm trying to get the caller number (for jailbroken devices) with this code:
extern CFTypeRef CTCallCopyName(void*, CTCall* call);
NSLog(#"%#", CTCallCopyName(NULL, (CTCall*)call));
I receive the error:
"CTCallCopyName(void*, CTCall*)", referenced from:
ld: symbol(s) not found for architecture armv6
I have Core Telephony linked with my project.
Maybe my prototype is wrong... i don't know. Any ideas?
Xcode 3, sdk 4
If you're calling this API in a .mm file, you have to declare it like extern "C" void foo(void); As far as I know, on iOS 5 ~ 7, you should use CTCallCopyAddress instead, the prototype is:
extern "C" CFStringRef CTCallCopyAddress(CFAllocatorRef, CTCallRef);
Notice that the second arg is a CTCallRef rather than a CTCall, which means you can't send it CTCall class methods (although some of them work). Besides linking CoreTelephony.framework, you can also load this symbol dynamically, as shown below:
static CFStringRef (*CTCallCopyAddress)(CFAllocatorRef, CTCallRef);
void Foo(CTCallRef call)
{
void *libHandle = dlopen("/System/Library/Frameworks/CoreTelephony.framework/CoreTelephony", RTLD_LAZY);
CTCallCopyAddress = (CFStringRef (*)(CFAllocatorRef, CTCallRef))dlsym(libHandle, "CTCallCopyAddress");
NSString *address = (NSString *)CTCallCopyAddress(kCFAllocatorDefault, call);
NSLog(#"The caller's address is %#", address);
[address release];
dlclose(libHandle);
}
BTW, I can't get CTCallCopyName to work in SpringBoard on iOS 5, haven't figured it out or tried on other systems yet. Hope this information helps!
EDIT: Just give it another try on iOS 5, CTCallGetID is the right function to get the caller ID in the addressbook, whose prototype is ABRecordID CTCallGetID(CTCallRef). iOS 6 and 7 are possibly the same.
typedef struct _protocol1
{
int type;
CGPoint pos;
} Protocol1;
-(void)sendData {
NSError *error;
Protocol1 msg;
msg.pos = ccp(100,100);
msg.type = 1;
NSData *packet = [NSData dataWithBytes:&msg length:sizeof(Protocol1)];
[self.myMatch sendDataToAllPlayers: packet withDataMode: GKMatchSendDataReliable error:&error];
if (error != nil)
{
NSLog(#"error"]);
}
}
That is a chunk of code from my project.
And I'm getting an error. However, I am unsure how to retrieve more information to help me debug. Can someone help me?
Sorry, I'm quite new with iOS development...
Using Cocos2d for a game.
EDIT
I am using the Simulator and my iPhone to test this. I doubt that is the problem, I already got the match working and everything...
To print out your error, try this!
NSLog(#"here is the error material: %#", [error localizedDescription])
if you have trouble, just click on NSError in your XCode4.
Then look at the right column, and click to get to the documentation.
(Or just search "NSError" in the Xcode documentation.)
Bring up "NSError Class Reference". It is very simple.
Be sure to look at the VARIOUS EXAMPLE CODE given.
For example scroll down to "localizedDescription" ad see the three sample codes. ("LazyTableImages, SeismicXML, URLCache")
You can download and look at the example projects. Search on "localizedDescription" and you'll see examples, if you're having trouble!
If you teach a man to fish ... Lol have fun.
I want to know the serial number of my iPhone using my application. I have writen code below.
- (NSString*)getSerialNumber
{
CFTypeRef serialNumberAsCFString;
io_service_t platformExpert = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("IOPlatformExpertDevice"));
if (platformExpert)
{
serialNumberAsCFString = IORegistryEntryCreateCFProperty(platformExpert, CFSTR(kIOPlatformUUIDKey), kCFAllocatorDefault, 0);
}
IOObjectRelease(platformExpert);
NSString *serial = [[NSString alloc] initWithFormat:#"%#",serialNumberAsCFString];
NSLog(#"serail no==>%#",serialNumberAsCFString);
NSLog(#"serail no==>%#",serial);
}
Why am I still getting wrong serial number?
You should change the argument 2 of IORegistryEntryCreateCFProperty from CFSTR (kIOPlatformUUIDKey) to CFSTR (kIOPlatformSerialNumberKey). Then you will get the correct serial number(with length of 11 characters).
Are you linking the IOKit framework?
Try the
id getValue(NSString *iosearch);
function, available at
http://blogs.oreilly.com/iphone/2008/08/retrieving-device-information.html
You can also use the UIDevice class to retrieve other useful information
For instance, you can do:
NSString *id = [[UIDevice currentDevice] uniqueIdentifier];
Other useful properties are the following ones:
name
systemName
systemVersion
model
localizedModel
Ready to use category on UIDevice: UIDevice+serialNumber. Not sure this would be accepted on the App Store.