// Define the operation when the dial button is clicked
[CPP]View
Plaincopy
- -(Void) callaction {
- Nsstring * number = @ ""; // enter the phone number here
- // Nsstring * num = [[nsstring alloc] initwithformat: @ "Tel: // % @", number]; // number is the number string. If this method is used to end the call, the contact list is displayed.
- Nsstring * num = [[nsstring alloc] initwithformat: @ "telprompt: // % @", number]; // This method is used to check whether or not the method is valid and then return to the program online.
- [[Uiapplication sharedapplication] Openurl: [nsurlurlwithstring: num]; // dial
- }
// The following Code adds a call button in the application and click it to call the phone number. It is useful for iPhone developers. // Add the phone icon button[CPP]View
Plaincopy
- Uibutton * btnphone = [[uibuttonbuttonwithtype: uibuttontyperoundedrect] retain];
- Btnphone. Frame = cgrectmake (280,10, 30,30 );
- [Btnphone setbackgroundcolor: [uicolor redcolor];
- // Click the dialing button to directly dial
- [Btnphone addtarget: Self action: @ selector (callaction) forcontrolevents: uicontroleventtouchupinside];
- [Self. Window addsubview: btnphone];
//Method 3 call[CPP]View
Plaincopy
- -(Void) callphone {
- Nsstring * phonenum = @ ""; // phone number
- Nsurl * phoneurl = [nsurl urlwithstring: [nsstringstringwithformat: @ "Tel: % @", phonenum];
- If (! Phonecallwebview ){
- Phonecallwebview = [[uiwebview alloc] initwithframe: cgrectzero]; // This webview is only a background and easy to add to the page. The effect is the same as method 2, but this method is legal.
- }
- [Phonecallwebview loadrequest: [nsurlrequestrequestwithurl: phoneurl];
- }