在iOS中拨打电话时调用标头的方法是什么?

我正在通过ios open dev的徽标模板开发一个调整,但是我一直在查看现有框架中的所有头文件,而我找不到正确的头文件,这些头文件的方法是在有人拨打电话后调用的? 有谁知道它是哪个? 我正在尝试做类似“AskToCall”的东西,它可以在Cydia中提供,在拨打电话时提示UIAlertView,正好是按下绿色按钮时。

谢谢!

1)首先,您需要链接私有框架CoreTelephony:在您的徽标项目的Makefile中确保包含yourprojectname_PRIVATE_FRAMEWORKS = CoreTelephony。 还要确保您的MobileSubstrate .plist文件过滤“com.apple.mobilephone”

2)iPhone上的手机应用程序使用CoreTelephony的CTCallDialWithID函数进行调用。 你可以简单地挂钩function并做你的事情。

#import "substrate.h" // for MSHookFunction definition extern "C" void CTCallDialWithID(NSString *numberToDial); // function declaration static void (*original_CTCallDialWithID)(NSString *numberToDial); //define a function pointer on which you'll assign the original call later static void replaced_CTCallDialWithID(NSString *numberToDial){ UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Verify New Call" message:[NSString stringWithFormat:@"Are you sure you want to call %@",numberToDial] delegate:YOUR_OBJECT cancelButtonTitle:@"No" otherButtonTitles:@"Yes,please",nil]; [alert show]; [alert release]; } 

在你的构造函数中:

 %ctor{ %init(); MSHookFunction((void *)CTCallDialWithID,(void *)replaced_CTCallDialWithID,(void **)&original_CTCallDialWithID); // Replace original function implementation with your replaced_ one. } 

要在替换函数实现后最终实际拨打该号码(例如在您的alertview的委托中),请使用

 CTCallDial(NSString *number); 

因为CTCallDialWithID需要{…}参数,并且无法正常运行。

请注意,这是一个用于CTCallDialWithID的Phone.app中的全局钩子(我适用于所有拨出的呼叫,包括点击最近拨打它的电话,或者喜欢的等等

如果您只是在按下“呼叫”按钮时需要一个挂钩:

 %hook DialerController -(void)_callButtonPressed:(id)pressed{ UIView *dialerView=MSHookIvar(self,"_dialerView"); UILabel *lcd=MSHookIvar(dialerView,"_lcd"); NSString *numberToBeDialed=[lcd text]; // do your thing with the number in here. } %end 

我注意到你提到你之前发现了这种方法并且没有用。 它可能不适合你,因为你没有注入MobilePhone.app。

您的theos项目中的.plist文件应如下所示:

 Filter = { Bundles = ("com.apple.mobilephone");}; 

要做到这一点,你必须从文件系统,iPhone或解密的ipsw文件转储MobilePhone.app(位于/Applications/MobilePhone.app)标题,然后你必须通过THOSE标题。 你一定会找到你想要的东西。 要转储标头,您需要来自此repo的class-dumpclass-dump-z (首选):

ininjas.com/repo/

然后你必须安装Mobile Terminal (来自Cydia)并运行

class-dump-z -H /Applications/MobilePhone.app/MobilePhone -O / var / mobile / somefolder(这也适用于iPod touch 4)

获取/ var / mobile / somefolder中的标头

然后你必须将所有标题放在/ var / theos / include / MobilePhone中(无论你的theos文件夹在哪里,因此在我的设备上/ var / theos / include)

之后你必须添加该行

 #import  

在你的tweak.xm中

好的,希望我能理解你的问题。

你只想显示一个警告弹出窗口“真的拨打电话吗?” 使用是和否按钮。

这就是你要做的事情:

 // View Controller Header File (.h file) @interface MyViewController  { UIButton *callButton; } // View Controller Implementation File (.m file) -(void)viewDidLoad { ... [callButton addTarget:self selector:@selector(confirmCall) forControlEvent:UIControlTouchUpInside]; ... } -(void)confirmCall { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Confirm Call" message:@"Really make call?" delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil ]; [alert show]; [alert release]; } // UIAlertViewDelegate callback method -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { // --------------------------------------------------------------------------- // Alert view button indexes starts from 0 (left most button) // and increments for the next button. // // In our case, "No" button would have index 0 because it is the first button // followed by the "Yes" button having an index 1 // // So what we're saying below is if user presses on the "Yes" button // for an alert that has the title "Confirm Call", then call that number // --------------------------------------------------------------------------- if([alertView.title isEqualToString:@"Confirm Call"] && buttonIndex == 1) { [self callNumber]; } } -(void)callNumber { NSString *rawNumber = [[NSString alloc] initWithString:@"+61 8 9123 4567"]; NSString *cleanedString = [[NSString alloc] initWithString:[[rawNumber componentsSeparatedByCharactersInSet:[[NSCharacterSet characterSetWithCharactersInString:@"0123456789-+()"] invertedSet]] componentsJoinedByString:@""]]; NSString *escapedPhoneNumber = [[NSString alloc] initWithString:[cleanedString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; NSString *properPhoneNumber = [[NSString alloc] initWithFormat:@"tel://%@",escapedPhoneNumber]; NSURL *telURL = [[NSURL alloc] initWithString:properPhoneNumber]; // prevent non phone iOS device from trying to making calls (iPod, iPad) if([[UIApplication sharedApplication] canOpenURL:telURL]) { // make call now [[UIApplication sharedApplication] openURL:telURL]; } else { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Device Cannot Call" message:@"This device cannot make phone calls. Would you like to send an email instead ?" delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil]; [alert show]; [alert release]; } [telURL release]; [properPhoneNumber release]; [escapedPhoneNumber release]; [cleanedString release]; [rawNumber release]; }