我正在编写一些代码,它将在我的应用程序内编写一条文本消息,如下所示:
MFMessageComposeViewController *messageComposer = [[MFMessageComposeViewController alloc] init];
[messageComposer setMessageComposeDelegate:self];
// Check The Device Can Send Text Messages
if ([MFMessageComposeViewController canSendText]) {
[messageComposer setRecipients:[NSArray arrayWithObjects: nil]];
[messageComposer setBody:messageBodyText];
[self presentViewController:messageComposer animated:YES completion:NULL];
} else {
// Need to add an alert view
NSLog(@"TEXT ISNT WORKING");
}
}
因此,我目前有一个if语句,用于检查设备是否可以发送消息,但是如何在其中添加另一个if语句呢?我基本上想根据视图中的开关位置来决定消息主体是什么,例如:
如果左开关:消息正文为A
如果右开关:消息正文为B
尝试给定的代码。检查您的开关值在左边还是右边,我认为您的开关变量是yourSwitchIsRightSide。
MFMessageComposeViewController *messageComposer = [[MFMessageComposeViewController alloc] init];
[messageComposer setMessageComposeDelegate:self];
// Check The Device Can Send Text Messages
if ([MFMessageComposeViewController canSendText]) {
[messageComposer setRecipients:[NSArray arrayWithObjects: nil]]
//yourSwitchIsRightSide should be bool value
if(yourSwitchIsRightSide){
[messageComposer setBody:yourRightMessageBodyText];
}
else{
[messageComposer setBody:yourLeftMessageBodyText];
}
[self presentViewController:messageComposer animated:YES completion:NULL];
} else {
// Need to add an alert view
NSLog(@"TEXT ISNT WORKING");
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句