Define actions When you click the Dial button
- -(void) callaction{
- NSString *number = @""; Read the phone number in here
- NSString *num = [[NSString alloc]initwithformat:@ "tel://%@", number]; Number is a string if you end the call using this method, the contact list is entered
- NSString *num = [[NSString alloc]initwithformat:@"telprompt://%@", number];//And this method is used to call the box before calling and then return to the program after the call. The internet says the method may not be legal and cannot be audited.
- [[UIApplication sharedapplication] openurl:[nsurlurlwithstring:num]; //Dialing
- }
The following code can add a phone button to the app and tap to call the phone number. It's also useful for iPhone developers. Add Phone icon button
- UIButton *btnphone = [[Uibuttonbuttonwithtype:uibuttontyperoundedrect]retain];
- Btnphone.frame =cgrectmake (280,10,30,30);
- [Btnphone Setbackgroundcolor:[uicolor Redcolor];
- Tap the Dial button to dial directly
- [Btnphone addtarget:self Action: @selector (Callaction) forcontrolevents:uicontroleventtouchupinside];
- [Self.window Addsubview:btnphone];
The third way to hit the electricity
- -(void) callphone{
- NSString *phonenum = @""; Phone number
- Nsurl *phoneurl = [Nsurl urlwithstring:[nsstringstringwithformat:@"tel:%@", Phonenum]];
- if (!phonecallwebview) {
- Phonecallwebview = [[UIWebView Alloc]initwithframe:cgrectzero]; //This webview is just a backstage easy don't need add to page effect with method two but this method is legal
- }
- [Phonecallwebview Loadrequest:[nsurlrequestrequestwithurl:phoneurl]];
- }