ios - Buddy name in SMS? (Obj-C) -
i'm making app user can send sms prefilled phone numbers. loadstring, loadstring2, , loadstring3 strings uitextfields user can fill in , save. however, if user fills in 1 or 2 fields, , leaves 1 empty, recipients chosen phone numbers, , 1 contact called buddy name.
my question is, how rid of strange contact, called "buddy name"?
my code:
if ([mfmessagecomposeviewcontroller cansendtext]) { [controller setrecipients:[nsarray arraywithobjects:loadstring, loadstring2, loadstring3, nil]]; [controller setbody:thelocation]; [self presentviewcontroller:controller animated:yes completion:null]; } else { nslog(@"can't open text."); }
"buddy name" shows if array contains string isn't valid contact empty string. add strings recipients array if non-empty:
if ([mfmessagecomposeviewcontroller cansendtext]) { nsmutablearray *recipents = [nsmutablearray array]; if ([self isvalidphonenumber:loadstring]) { [recipents addobject:loadstring]; } if ([self isvalidphonenumber:loadstring2]) { [recipents addobject:loadstring2]; } if ([self isvalidphonenumber:loadstring3]) { [recipents addobject:loadstring3]; } [controller setrecipients:recipents]; [controller setbody:thelocation]; [self presentviewcontroller:controller animated:yes completion:null]; } else { nslog(@"can't open text."); }
...
- (bool)isvalidphonenumber:(nsstring *)phonenumberstring { // if length 0 it's invalid. may want add other checks here make sure it's not invalid other reasons. if (phonenumberstring.length == 0) { return no; } else { return yes; } }
Comments
Post a Comment