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
789 views
in Technique[技术] by (71.8m points)

ios - iPhone mobile number using Core telephony

As far as my understanding, there is no public API available in iPhone SDK to find the users mobile number.

Can we find the mobile number of iPhone user using the Core telephony framework added in 4.0 SDK?

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

Yes, you can, but it's tricky. It involves using iOS private API, which will determine Apple to reject your app in case you want to post it on the App Store.

Here's what I did:

  1. download and install the class-dump utility: http://www.codethecode.com/projects/class-dump/
  2. in the command line go to this folder: /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk/System/Library/Frameworks/CoreTelephony.framework and perform the following command:

    class-dump CoreTelephony > CoreTelephony.h

    This will create a header file in the current directory. Move this file in the desired directory.

  3. in your Xcode project, import the CoreTelephony.framework (Xcode 4: click on the project target -> Build Phases tab -> Link Binary With Libraries -> + -> select the CoreTelephony.framework in the iOS list -> click Add)
  4. import the CoreTelephony.h file using the same method as above Xcode 4: click on the project target -> Build Phases tab -> Link Binary With Libraries -> + -> Add Other -> select your file in the Finder)
  5. at the end of the CoreTelephony.h file, add the following:

    extern NSString *CTSettingCopyMyPhoneNumber();
    
  6. import the CoreTelephony.h in your code and call the above function.
  7. when building the project, you may find that there are compilation errors in the CoreTelephony.h - usually an interface declaration that needs to be moved before another interface declaration or protocol sequences written incorrectly
  8. in case you have linking errors, use the following linking flags in the build settings of your project target:

    -force_flat_namespace 
    -undefined suppress 
    

    (Xcode 4: click on the project target -> Build Settings tab -> Linking -> double-click on the values section of the Other Linker Flags property -> + -> add flags above -> Done

  9. by now you should be able to get that phone number :)

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

...