iphone - How to make phone call button? -


i stacking in phone call button. data project parsed json. in code bellow, data of phone number.

- (void)loaddata { // 1     nsdata *data = [nsdata datawithcontentsofurl:[nsurl urlwithstring:@"http://opendata.socrata.com/api/views/9ake-cdkn/rows.json"]];     nsdictionary *alldatadictionary = [nsjsonserialization jsonobjectwithdata:data options:0 error:nil];     nsarray *stationdata = [alldatadictionary objectforkey:@"data"];     nsuinteger stationcount = stationdata.count;     // 2     //nsinteger = 0;     //cllocationcoordinate2d *polylinecoords = malloc(sizeof(cllocationcoordinate2d) * stationcount);     _stations = [[nsmutablearray alloc] initwithcapacity:stationcount];     // 3     (nsmutablearray *stationdictionary in stationdata) { // 4         cllocationdegrees latitude =         [[[stationdictionary objectatindex:13]objectatindex:1] doublevalue];         cllocationdegrees longitude =         [[[stationdictionary objectatindex:13]objectatindex:2] doublevalue];         cllocationcoordinate2d coordinate = cllocationcoordinate2dmake(latitude, longitude);         //polylinecoords[i] = coordinate;         // 5         rwstation *station = [[rwstation alloc] init];         station.title =         [stationdictionary objectatindex:10];         //nslog(@"name: %@", station.title);         station.phoneformat = [stationdictionary objectatindex:12];         //nslog(@"phone: %@", station.phoneformat);         station.coordinate = coordinate;         [_stations addobject:station];         //i++;     } } 

and now, in mapview -> annotationview -> rightcalloutbutton, have actionsheet contains call phone number , cancel, code below:

- (void)mapview:(mkmapview *)mapview annotationview:(mkannotationview *)view calloutaccessorycontroltapped:(uicontrol *)control { if (view.rightcalloutaccessoryview.tag == 4)     {         _selectedstation = (rwstation*)view.annotation;         // 1         uiactionsheet *locationsheet = [[uiactionsheet alloc]                                 initwithtitle:@""                                 delegate:self cancelbuttontitle:nil destructivebuttontitle:nil                                 otherbuttontitles:@"call service", nil]; .... } 

and in diddismisswithbuttonindex, have

- (void)actionsheet:(uiactionsheet *)actionsheet diddismisswithbuttonindex:(nsinteger)buttonindex { ...... } 

how put number json data above diddismisswithbuttonindex function?

there many questions in relation "how make phone call in objective-c" here few of them.

how can make phone call in objective c?

https://stackoverflow.com/questions/12973545/how-to-make-phone-call-on-ios

make phone call on iphone , take user app? (uiwebview it)

the way can make phone call using objective-c simple can 1 of 2 ways can

    [[uiapplication sharedapplication] openurl:[nsurl urlwithstring:@"tel:+000"]]; 

doing way open dialer , dial number give, or can like

    [[uiapplication sharedapplication] openurl:[nsurl urlwithstring:@"telprompt:+000"]]; 

doing way open dialer first 1 return app after call ends. opinion way pointless unless allow app run in background.

so in case

- (void)actionsheet:(uiactionsheet *)actionsheet diddismisswithbuttonindex:(nsinteger)buttonindex {     if([[uiapplication sharedapplication] canopenurl:[nsurl urlwithstring:@"tel:+000"]]) {          [[uiapplication sharedapplication] openurl:[nsurl urlwithstring:@"tel:+000"]];     } } 

this assuming code have 1 button. if have more 1 button have checking find out button has been pressed add code button.

edit

i going assume phoneformat number want, going assume know station want ever user input or something. lets i = 0, want station i in _stations array. if don't know how getting station going have figure out don't have enough information that.

so need station object of sort doing rwstation *station = [_stations objectatindex:i]; have station store in station. can start accessing phoneformat coordinates , other stuff have store on it.

so (assuming phoneformat string)

- (void)actionsheet:(uiactionsheet *)actionsheet diddismisswithbuttonindex:(nsinteger)buttonindex {     // need have set `station` before here.     if([[uiapplication sharedapplication] canopenurl:[nsurl urlwithstring:[nsstring stringwithformat:@"tel:%@",station.phoneformat]]]) {          [[uiapplication sharedapplication] openurl:[nsurl urlwithstring:[nsstring stringwithformat:@"tel:%@",station.phoneformat]]];     } } 

if not after question not clear enough, hope helps.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -