i'm trying use mfmessagecomposer pre-fill sms user. trying use variable stored in mutable array , use number pre-fill phone number. doesn't work code below @ recipient part. i've tried changing string, adding array. phone doesn't anything.
however if manual number using @[@"123132131235"]; recipients work.
- (ibaction)smssend:(id)sender { { mfmessagecomposeviewcontroller *controller = [[mfmessagecomposeviewcontroller alloc] init]; [controller setmessagecomposedelegate:self]; if([mfmessagecomposeviewcontroller cansendtext]) { controller.recipients = [[nsarray alloc] initwithobjects:[detail valueforkey:@"phone"], nil]; nslog(@"%@",[detail valueforkey:@"phone"]); controller.body = @"hello testing"; [self presentviewcontroller:controller animated:yes completion:null]; } else { nslog(@"cannot send"); } } }
please me.
cheers, tony.
try this:
- (ibaction)smssend:(id)sender { { mfmessagecomposeviewcontroller *controller = [[mfmessagecomposeviewcontroller alloc] init]; [controller setmessagecomposedelegate:self]; if([mfmessagecomposeviewcontroller cansendtext]) { controller.recipients = [nsarray arraywithobjects:[detail valueforkey:@"phone"], nil]; controller.body = @"hello testing"; [self presentviewcontroller:controller animated:yes completion:null]; } else { nslog(@"cannot send"); } } }
the change have made recipient array allocation. recipient array not array own instead of [nsarray alloc]
should directly initialise array objects.
initwithobject
returns array retain count of 1, i.e. own array , must release @ point prevent memory leaks.
arraywithobject
returns autoreleased array not have worry releasing when don't need anymore (but if store in instance variable, should retain prevent autorelease pool freeing it)
Comments
Post a Comment