Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
490 views
in Technique[技术] by (71.8m points)

ios7 - iOS 7: How to get own number via private API?

Old ways don't work any more:

// way 1

void *lib = dlopen("/Symbols/System/Library/Framework/CoreTelephony.framework/CoreTelephony", RTLD_LAZY);
NSString* (*getPhoneNumber)() = dlsym(lib, "CTSettingCopyMyPhoneNumber");

if (getPhoneNumber == nil) {
    NSLog(@"getPhoneNumber is nil");
    return nil;
}
NSString* ownPhoneNumber = getPhoneNumber();

// way 2

extern NSString* CTSettingCopyMyPhoneNumber();
NSString *phone = CTSettingCopyMyPhoneNumber();

Related questions:

Is it possible to detect a phone number of the device in iOS?

[UPDATE]

Provided method works on iOS 6.1.4 without JB and iOS 7.1.2 with JB

Thanks to user creker for hint!

To get number you have to use following way:

1. Code

-(NSString*) getMyNumber {
    NSLog(@"Open CoreTelephony");
    void *lib = dlopen("/Symbols/System/Library/Framework/CoreTelephony.framework/CoreTelephony",RTLD_LAZY);
    NSLog(@"Get CTSettingCopyMyPhoneNumber from CoreTelephony");
    NSString* (*pCTSettingCopyMyPhoneNumber)() = dlsym(lib, "CTSettingCopyMyPhoneNumber");
    NSLog(@"Get CTSettingCopyMyPhoneNumber from CoreTelephony");

    if (pCTSettingCopyMyPhoneNumber == nil) {
        NSLog(@"pCTSettingCopyMyPhoneNumber is nil");
        return nil;
    }
    NSString* ownPhoneNumber = pCTSettingCopyMyPhoneNumber();
    dlclose(lib);
    return ownPhoneNumber;
}

2. Build application without signing: enter image description here

3. Create xml file (entitlements.xml) with following content:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
    <dict>
        <key>com.apple.coretelephony.Calls.allow</key>
        <true/>
        <key>com.apple.coretelephony.Identity.get</key>
        <true/>
    </dict>
</plist>

Where:

com.apple.coretelephony.Calls.allow — for calls

com.apple.coretelephony.Identity.get — for getting own number

4. Sing app with entitlements.xml Copy files in one folder:

./FolderForRunSinging/
    YourApp.app
    entitlements.xml

entitlements.xml - created xml

YourApp.app - binaries for your app copied from XCode files To find where your binaries you can use command:

$ls -la ~/Library/Developer/Xcode/DerivedData/ | grep YourApp

Path should be like this:

/Users/username/Library/Developer/Xcode/DerivedData/YourApp-cktasembftvbmqaaiiunvljdwocs/Build/Products/Debug-iphoneos/YourApp.app

Run singing command:

$codesign --sign='iPhone Developer: FirstName  SecondName (XXXXXXXX)’
--entitlements entitlements.xml YourApp.app

'iPhone Developer: FirstName SecondName (XXXXXXXX)' - name of your certificate in keychain

enter image description here

5. Copy application YourApp.app on your device using ssh to folder

/Applications

6. Restart springboard (run on device):

$su mobile -c uicache 1>/dev/null 2>&1

Working sample could be found on github

Result on iOS 7.1.2 (JB is required!):

enter image description here

Result on iOS 6.1.3 (works without JB and without special signature just build and run)

enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

In order to use this API you need to sign your app with entitlement com.apple.coretelephony.Identity.get with boolean value set to true.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...