用private api发送短信和获得IMEI

一段时间以前,有个项目需要获得手机的IMEI,结果当时由于不清楚如何使用private api且项目需要上到App Store上,因此只好用UDID替代。可是对IMEI的获取方法仍然心存好奇,随着weiphone等论坛使用private api的开发者数目增多,对于classdump(一个私有框架的头文件生成工具)了解的人越来越多,终于找到了正确使用private api的方法。本贴举出两个例子(发短信和获取IMEI)说明如何使用私有框架中的方法。

使用private framework的一般方法为:

  1. Add->Existing Frameworks...->PrivateFrameworks->选择私有框架
  2. 到ericasadun.com网站找到需要的头文件代码,新建一个头文件,粘贴进去
  3. #import此头文件,便可使用其中的类和方法了
复制代码

例一. 发送短信

  1. 在项目中加入private framework:CoreTelephony.framework
  2. 创建头文件sms.h
  3. 从http://ericasadun.com/iPhoneDocs300/_c_t_message_center_8h-source.html复制头文件代码
复制代码
  1. // CoreTelephony/CTMessageCenter.h
  2. @interface CTMessageCenter : NSObject
  3. {
  4. }
  5.  
  6. + (id)sharedMessageCenter;
  7. - (id)init;
  8. - (id)sendSMS:(id)fp8;
  9. - (id)sendMMSFromData:(id)fp8 messageId:(unsigned int)fp12;
  10. - (id)sendMMS:(id)fp8;
  11. - (id)send:(id)fp8;
  12. - (id)incomingMessageWithId:(unsigned int)fp8 telephonyCenter:( id)fp12 isDeferred:(BOOL)fp16;
  13. - (int)incomingMessageCount;
  14. - (id)allIncomingMessages;
  15. - (void)acknowledgeIncomingMessageWithId:(unsigned int)fp8;
  16. - (void)acknowledgeOutgoingMessageWithId:(unsigned int)fp8;
  17. - (id)incomingMessageWithId:(unsigned int)fp8;
  18. - (id)deferredMessageWithId:(unsigned int)fp8;
  19. - (id)statusOfOutgoingMessages;
  20. - (id)encodeMessage:(id)fp8;
  21. - (id)decodeMessage:(id)fp8;
  22. - (BOOL)isMmsEnabled;
  23. - (BOOL)isMmsConfigured;
  24. - (BOOL)sendSMSWithText:(id)fp8 serviceCenter:(id)fp12 toAddress:(id)fp16;
  25.  
  26. @end
复制代码
  1. #import "sms.h"
  2. // 发送123到10086
  3. [[CTMessageCenter sharedMessageCenter] sendSMSWithText:@"123" serviceCenter:nil toAddress:@"10086"];  
复制代码

例二. 获取IMEI

  1. 在项目中加入:Message.framework
  2. 创建头文件network.h
  3. 从http://ericasadun.com/iPhoneDocs300/_network_controller_8h-source.html复制头文件代码
复制代码
  1. // Message/NetWorkController.h
  2.  
  3. @class NSString, NSTimer;
  4. @interface NetworkController : NSObject
  5. {
  6.         struct __SCDynamicStore *_store;
  7.         NSString *_domainName;
  8.         unsigned int _waitingForDialToFinish:1;
  9.         unsigned int _checkedNetwork:1;
  10.         unsigned int _isNetworkUp:1;
  11.         unsigned int _isFatPipe:1;
  12.         unsigned int _edgeRequested:1;
  13.         NSTimer *_notificationTimer;
  14. }
  15.  
  16. + (id)sharedInstance;
  17. - (void)dealloc;
  18. - (id)init;
  19. - (BOOL)isNetworkUp;
  20. - (BOOL)isFatPipe;
  21. - (BOOL)inAirplaneMode;
  22. - (id)domainName;
  23. - (BOOL)isHostReachable:(id)fp8;
  24. - (id)primaryEthernetAddressAsString;
  25. - (id)IMEI;
  26. - (id)edgeInterfaceName;
  27. - (BOOL)isEdgeUp;
  28. - (void)bringUpEdge;
  29. - (void)keepEdgeUp;
  30. - (void *)createPacketContextAssertionWithIdentifier:(id)fp8;
  31.  
  32. @end
复制代码
  1. #import "network.h"
  2. // 获得IMEI
  3. NetworkController *ntc = [NetworkController sharedInstance];
  4. NSString *imeistring = [ntc IMEI];
  5. // show IMEI
  6. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Your IMEI Is"
  7.                      message:imeistring 
  8.                      delegate:nil 
  9.                      cancelButtonTitle:@"OK" 
  10.                      otherButtonTitles:nil];
  11. [alert show];
  12. [alert release];
复制代码

你可能感兴趣的:(sms)