3

我正在通过 ios open dev 的徽标模板进行调整,但我一直在查看现有框架中的所有头文件,但我没有找到正确的头文件,该头文件具有在某人拨打电话后调用的方法?有谁知道它是什么?我正在尝试做类似 Cydia 中可用的“AskToCall”之类的操作,它会在拨打电话时提示 UIAlertView,确切地说是在按下绿色按钮时。

谢谢!

4

3 回答 3

8

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

2) iPhone 上的电话应用程序使用CoreTelephony 的CTCallDialWithID 函数拨打电话。您可以简单地挂钩该功能并做您的事情。

#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.

}

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

CTCallDial(NSString *number);

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

请注意,这是 Phone.app 中 CTCallDialWithID 的全局挂钩(我适用于所有拨出电话,包括点击最近的通话以拨打它,或收藏夹等

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

%hook DialerController
-(void)_callButtonPressed:(id)pressed{

   UIView *dialerView=MSHookIvar<UIView *>(self,"_dialerView");
   UILabel *lcd=MSHookIvar<UILabel *>(dialerView,"_lcd");
   NSString *numberToBeDialed=[lcd text];

  // do your thing with the number in here.
}
%end

我注意到您提到您之前找到了这种方法并且没有用。它可能对您不起作用,因为您没有注入 MobilePhone.app。

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

Filter = { Bundles = ("com.apple.mobilephone");};
于 2012-10-26T23:19:14.230 回答
1

为此,您必须将文件系统中的 MobilePhone.app(位于 /Applications/MobilePhone.app)标头转储到 iPhone 或解密的 ipsw 文件中,然后您必须通过 THOSE 标头。你一定会在那里找到你正在寻找的东西。要从这个 repo 中转储您需要class-dumpclass-dump-z(首选)的标头:

ininjas.com/repo/

然后你必须安装移动终端(来自 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 <MobilePhone/MobilePhone.h>

在你的tweak.xm

于 2012-10-26T09:26:51.127 回答
0

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

您只是想显示一个警报弹出窗口,上面写着“真的打电话吗?” 是和否按钮。

这就是你将如何去做:

// View Controller Header File (.h file)
@interface MyViewController <UIAlertViewDelegate>
{
    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];
}
于 2012-10-26T08:32:29.763 回答