2015-03-03 36 views
0

我已經設置了作曲者,因此郵件正文已經填充,但是收件人爲空,因此可以手動填充。Objective-c SMS收件人爲空陣列

API沒有委託方法,我可以找到允許我收到收件人數組更改的通知。

委託方法:

- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result; 

是被髮送的消息後調用的唯一方法,但接收者數組爲空。

任何人都可以告訴我另一種方式訪問​​此屬性?

NSString *message = [NSString stringWithFormat:@"Message"]; 
    MFMessageComposeViewController *messageController = [[MFMessageComposeViewController alloc] init]; 
    messageController.messageComposeDelegate = self; 
    //[messageController setRecipients:recipients];// This set to nil so the textfield can be filled manually and this the problem 
    [messageController setBody:message]; 

    // Present message view controller on screen 
    [self presentViewController:messageController animated:YES completion:nil]; 

回答

0

我們可以初始化MessageComposer內容和現在,但不幸的是我們不能更改到收件人陣列或呈現控制器之後,訪問任何價值。 - 沒有getter方法可用。

但你可以檢查郵件是否發送到糾正下面的代碼接受者,並與正確的身體:

- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result { 
NSLog(@"Message: %@", controller.body); 

NSLog(@"Recipients:"); 
for (NSString *recipient in controller.recipients) { 
    NSLog(recipient); 
} 
switch (result) { 
    case MessageComposeResultCancelled: 
    NSLog(@"Result: canceled"); 
    break; 
    case MessageComposeResultSent: 
    NSLog(@"Result: sent"); 
    // Check that the correct message has been sent 
    if([controller.body isEqualToString:correctMessage]) { 
    BOOL correctRecipient = NO; 
    for (NSString *recipient in controller.recipients) { 
    if([recipient isEqualToString:correctRecipient]) { 
     correctRecipient = YES; 
    } 
    } 

    if(correctRecipient) { 
    NSLog(@"Correct message sent to correct recipient!"); 
    } else { 
    NSLog(@"Message or recipient was wrong"); 
    } 
    } 

    break; 
    case MessageComposeResultFailed: 
    NSLog(@"Result: failed"); 
    break; 
    default: 
    NSLog(@"Result: not sent"); 
    break; 
} 

[self dismissModalViewControllerAnimated:YES]; 

} 
+0

這正是我在委託方法在做,但controller.recipient陣列始終是零。正文是一個靜態消息,所以它真的沒關係。我假設私人api會將手動輸入的數字添加到收件人數組中,但似乎沒有。 – user3912072 2015-03-03 08:31:07