Add a class method, and then call directly
+ (void) Callphonestr: (nsstring*) phonestr WITHVC: (Uiviewcontroller *) selfvc{if (Phonestr.length >=) {NSString *
STR2 = [[Uidevice currentdevice] systemversion]; if ([str2 compare:@ "10.2" options:nsnumericsearch] = = Nsordereddescending | | [Str2 compare:@ "10.2" options:nsnumericsearch] = = nsorderedsame) {nsstring* phonestr = [NSString stringwithformat:@]
telprompt://%@ ", Phonestr]; [[UIApplication sharedapplication] Openurl:[nsurl urlwithstring:phonestr] options:@{} completionHandler:^ (BOOL
Success) {NSLog (@ "phone success"); }else {nsmutablestring* str1 = [[nsmutablestring alloc]initwithstring:phonestr];//exists heap area, variable string if (Phonestr.length = 10) {[Str1 insertstring:@ "-" atindex:3];//inserts a string into one of the other strings [str1 insertstring:@ "-" atindex:7];// Inserts a string into one of the other strings}else {[str1 insertstring:@ "-" atindex:3];//inserts a string into one of the other strings [str1 insertstring:@ "-"
atindex:8];//inserts a string into one of the other strings} NSString * str = [NSString stringwithformat:@ "Call \n%@", str1]; Uialertcontroller *alert= [Uialertcontroller alertcontrollerwithtitle:str message:nil Preferredstyle:uialertcontrollerstylealert];
Set PopOver to point to item alert.popoverPresentationController.barButtonItem = Selfvc.navigationItem.leftBarButtonItem; Add button [Alert addaction:[uialertaction actionwithtitle:@ ' call ' style:uialertactionstyledestructive handler:^ (
Uialertaction *action) {NSLog (@ "Click on Call Button 10.2");
nsstring* phonestr = [NSString stringwithformat:@ "tel://%@", phonestr]; if ([Phonestr hasprefix:@ "SMS:"] | | [Phonestr hasprefix:@ "Tel:"]) {uiapplication * app = [uiapplication sharedapplication]; if ([App Canopenurl:[nsurl Urlwithstring:phonestr]]) {app Ope
Nurl:[nsurl Urlwithstring:phonestr]];
}
}
}]]; [Alert addaction:[uialertaction actionwithtitle:@ "Cancel" Style:uialertactionstylecancel handler:^ (UIAlertAction *
Action) {NSLog (@ "clicked Cancel button");}];
[SELFVC Presentviewcontroller:alert Animated:yes Completion:nil]; }
}
}