520 sms cocoa-touch objective-c ios
是否有人知道这是可能的,以及如何以编程方式发送的短信从iPhone,与官方的SDK /可可触摸?
Ada*_*vis 401
如果您可以在iPhone上的程序中发送短信,您将能够编写在后台垃圾邮件的游戏.我确定你真的想要从你的朋友那里得到垃圾邮件,"试试这款新游戏吧!它会让我的箱子变得更好,而你的箱子也会出现!roxxersboxxers.com !!!!如果你现在注册,你将获得3,200 RB点!"
Apple对自动(甚至部分自动化)SMS和拨号操作有限制.(想象一下,如果游戏在一天的特定时间拨打了911)
您最好的办法是在互联网上设置一个使用在线短信发送服务的中间服务器,如果您需要完全自动化,则通过该路由发送短信.(即,你的iPhone程序发送UDP数据包到您的服务器,发送真正的短信)
但是,iOS 4现在提供了一个viewController可以导入到您的应用程序中的内容.您预填充SMS字段,然后用户可以在控制器内启动SMS发送.与使用"SMS:..."url格式不同,这允许您的应用程序保持打开状态,并允许您填充to和body字段.您甚至可以指定多个收件人.
这可以防止应用程序在用户没有明确意识到的情况下发送自动SMS.您仍然无法从iPhone本身发送完全自动化的短信,它需要一些用户互动.但这至少允许您填充所有内容,并避免关闭应用程序.
该MFMessageComposeViewController类是有据可查的,和教程显示它是多么容易实现.
iOS 5包括iPod touch和iPad设备的消息,因此虽然我自己还没有测试过,但可能是所有iOS设备都可以通过MFMessageComposeViewController发送短信.如果是这种情况,那么Apple正在运行一个SMS服务器,它代表没有蜂窝调制解调器的设备发送消息.
没有改变这个类.
您现在可以检查您正在使用的消息媒体是否接受主题或附件,以及它将接受哪种附件.您可以编辑主题并在介质允许的位置添加附加到消息.
没有改变这个类.
没有改变这个类.
没有改变这个类.
请记住,这不适用于没有iOS 4的手机,除了iOS 5之外,它无法在iPod touch或iPad上运行.您必须在使用此功能之前检测设备和iOS限制控制器,或将您的应用程序限制在最近升级的3G,3GS和4 iPhone的风险.
但是,发送SMS的中间服务器将允许任何和所有这些iOS设备发送SMS,只要它们具有Internet访问权限,因此它可能仍然是许多应用程序的更好解决方案.或者,使用两者,并且只有在设备不支持时才会回退到在线SMS服务.
Dan*_*tay 143
这是一个完全符合您要求的教程:MFMessageComposeViewController.
http://blog.mugunthkumar.com/coding/iphone-tutorial-how-to-send-in-app-sms/
实质上:
MFMessageComposeViewController *controller = [[[MFMessageComposeViewController alloc] init] autorelease];
if([MFMessageComposeViewController canSendText])
{
controller.body = @"SMS message here";
controller.recipients = [NSArray arrayWithObjects:@"1(234)567-8910", nil];
controller.messageComposeDelegate = self;
[self presentModalViewController:controller animated:YES];
}
Run Code Online (Sandbox Code Playgroud)
以及文档的链接.
https://developer.apple.com/documentation/messageui/mfmessagecomposeviewcontroller
Naj*_*hah 99
#import <MessageUI/MessageUI.h>在头文件中包含一个MFMessageComposeViewControllerDelegate &UINavigationControllerDelegateIBAction方法声明实例中MFMessageComposeViewController说messageInstance[MFMessageComposeViewController canSendText]在if条件下发送文本,它将返回是/否在这种if情况下做这些:
首先设置你的身体messageInstance:
messageInstance.body = @"Hello from Shah";
Run Code Online (Sandbox Code Playgroud)然后将消息的收件人确定为:
messageInstance.recipients = [NSArray arrayWithObjects:@"12345678", @"87654321", nil];
Run Code Online (Sandbox Code Playgroud)将您的messageInstance的委托设置为:
messageInstance.messageComposeDelegate = self;
Run Code Online (Sandbox Code Playgroud)在最后一行中这样做:
[self presentModalViewController:messageInstance animated:YES];
Run Code Online (Sandbox Code Playgroud)iso*_*sox 25
MacOS中的进程间通信系统之一是XPC.该系统层是基于使用libSystem和launchd传输plist结构而开发的用于进程间通信的.实际上,它是一个允许通过交换诸如字典之类的结构来管理进程的接口.由于遗传,iOS 5也拥有这种机制.
您可能已经理解了这个介绍的含义.是的,iOS中有系统服务,包括用于XPC通信的工具.我想用一个用于短信发送的守护进程来举例说明这项工作.但是,应该提到的是,这种能力在iOS 6中已得到修复,但与iOS 5.0-5.1.1相关.其利用不需要越狱,私人框架和其他非法工具.只需要来自目录/ usr/include/xpc/*的头文件集.
在iOS中发送SMS的元素之一是系统服务com.apple.chatkit,其任务包括生成,管理和发送短文本消息.为了便于控制,它具有公共可用的通信端口com.apple.chatkit.clientcomposeserver.xpc.使用XPC子系统,您可以在未经用户批准的情况下生成和发送消息.
好吧,让我们尝试创建一个连接.
xpc_connection_t myConnection;
dispatch_queue_t queue = dispatch_queue_create("com.apple.chatkit.clientcomposeserver.xpc", DISPATCH_QUEUE_CONCURRENT);
myConnection = xpc_connection_create_mach_service("com.apple.chatkit.clientcomposeserver.xpc", queue, XPC_CONNECTION_MACH_SERVICE_PRIVILEGED);
Run Code Online (Sandbox Code Playgroud)
现在我们将XPC连接myConnection设置为SMS发送服务.但是,XPC配置提供了挂起连接的创建 - 我们需要再激活一步.
xpc_connection_set_event_handler(myConnection, ^(xpc_object_t event){
xpc_type_t xtype = xpc_get_type(event);
if(XPC_TYPE_ERROR == xtype)
{
NSLog(@"XPC sandbox connection error: %s\n", xpc_dictionary_get_string(event, XPC_ERROR_KEY_DESCRIPTION));
}
// Always set an event handler. More on this later.
NSLog(@"Received a message event!");
});
xpc_connection_resume(myConnection);
Run Code Online (Sandbox Code Playgroud)
连接已激活.此时iOS 6将在电话日志中显示禁止此类通信的消息.现在我们需要生成一个类似于xpc_dictionary的字典,其中包含发送消息所需的数据.
NSArray *recipient = [NSArray arrayWithObjects:@"+7 (90*) 000-00-00", nil];
NSData *ser_rec = [NSPropertyListSerialization dataWithPropertyList:recipient format:200 options:0 error:NULL];
xpc_object_t mydict = xpc_dictionary_create(0, 0, 0);
xpc_dictionary_set_int64(mydict, "message-type", 0);
xpc_dictionary_set_data(mydict, "recipients", [ser_rec bytes], [ser_rec length]);
xpc_dictionary_set_string(mydict, "text", "hello from your application!");
Run Code Online (Sandbox Code Playgroud)
剩下的就是:将消息发送到XPC端口并确保它已交付.
xpc_connection_send_message(myConnection, mydict);
xpc_connection_send_barrier(myConnection, ^{
NSLog(@"The message has been successfully delivered");
});
Run Code Online (Sandbox Code Playgroud)
就这样.短信发送.
Bha*_*ati 23
添加MessageUI.Framework并使用以下代码
#import <MessageUI/MessageUI.h>
Run Code Online (Sandbox Code Playgroud)
然后:
if ([MFMessageComposeViewController canSendText]) {
MFMessageComposeViewController *messageComposer =
[[MFMessageComposeViewController alloc] init];
NSString *message = @"Your Message here";
[messageComposer setBody:message];
messageComposer.messageComposeDelegate = self;
[self presentViewController:messageComposer animated:YES completion:nil];
}
Run Code Online (Sandbox Code Playgroud)
和委托方法 -
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller
didFinishWithResult:(MessageComposeResult)result {
[self dismissViewControllerAnimated:YES completion:nil];
}
Run Code Online (Sandbox Code Playgroud)
小智 21
你可以使用这种方法:
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"sms:MobileNumber"]]
Run Code Online (Sandbox Code Playgroud)
iOS会自动从您的应用导航到消息应用的消息撰写页面.由于URL的方案以sms:开头,因此将其标识为消息应用程序识别并启动它的类型.
Rus*_*abh 12
//Add the Framework in .h file
#import <MessageUI/MessageUI.h>
#import <MessageUI/MFMailComposeViewController.h>
//Set the delegate methods
UIViewController<UINavigationControllerDelegate,MFMessageComposeViewControllerDelegate>
//add the below code in .m file
- (void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
MFMessageComposeViewController *controller =
[[[MFMessageComposeViewController alloc] init] autorelease];
if([MFMessageComposeViewController canSendText])
{
NSString *str= @"Hello";
controller.body = str;
controller.recipients = [NSArray arrayWithObjects:
@"", nil];
controller.delegate = self;
[self presentModalViewController:controller animated:YES];
}
}
- (void)messageComposeViewController:
(MFMessageComposeViewController *)controller
didFinishWithResult:(MessageComposeResult)result
{
switch (result)
{
case MessageComposeResultCancelled:
NSLog(@"Cancelled");
break;
case MessageComposeResultFailed:
NSLog(@"Failed");
break;
case MessageComposeResultSent:
break;
default:
break;
}
[self dismissModalViewControllerAnimated:YES];
}
Run Code Online (Sandbox Code Playgroud)
Tun*_*her 12
请遵循此程序
1,添加MessageUI.Framework到项目中
2.导入#import <MessageUI/MessageUI.h>.h文件.
3.复制此代码以发送消息
if ([MFMessageComposeViewController canSendText]) {
MFMessageComposeViewController *messageComposer =
[[MFMessageComposeViewController alloc] init];
NSString *message = @"Message!!!";
[messageComposer setBody:message];
messageComposer.messageComposeDelegate = self;
[self presentViewController:messageComposer animated:YES completion:nil];
}
Run Code Online (Sandbox Code Playgroud)
4.delegate如果你愿意,可以实现方法.
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result{
///your stuff here
[self dismissViewControllerAnimated:YES completion:nil];
}
Run Code Online (Sandbox Code Playgroud)
跑吧!
这是在iOS中发送SMS的Swift版本代码.请注意,它仅适用于实际设备.在iOS 7+中进行了代码测试.你可以在这里阅读更多.
1)创建一个继承MFMessageComposeViewControllerDelegate和NSObject的新类:
import Foundation
import MessageUI
class MessageComposer: NSObject, MFMessageComposeViewControllerDelegate {
// A wrapper function to indicate whether or not a text message can be sent from the user's device
func canSendText() -> Bool {
return MFMessageComposeViewController.canSendText()
}
// Configures and returns a MFMessageComposeViewController instance
func configuredMessageComposeViewController(textMessageRecipients:[String] ,textBody body:String) -> MFMessageComposeViewController {
let messageComposeVC = MFMessageComposeViewController()
messageComposeVC.messageComposeDelegate = self // Make sure to set this property to self, so that the controller can be dismissed!
messageComposeVC.recipients = textMessageRecipients
messageComposeVC.body = body
return messageComposeVC
}
// MFMessageComposeViewControllerDelegate callback - dismisses the view controller when the user is finished with it
func messageComposeViewController(controller: MFMessageComposeViewController!, didFinishWithResult result: MessageComposeResult) {
controller.dismissViewControllerAnimated(true, completion: nil)
}
}
Run Code Online (Sandbox Code Playgroud)
2)如何使用这个类:
func openMessageComposerHelper(sender:AnyObject ,withIndexPath indexPath: NSIndexPath) {
var recipients = [String]()
//modify your recipients here
if (messageComposer.canSendText()) {
println("can send text")
// Obtain a configured MFMessageComposeViewController
let body = Utility.createInvitationMessageText()
let messageComposeVC = messageComposer.configuredMessageComposeViewController(recipients, textBody: body)
// Present the configured MFMessageComposeViewController instance
// Note that the dismissal of the VC will be handled by the messageComposer instance,
// since it implements the appropriate delegate call-back
presentViewController(messageComposeVC, animated: true, completion: nil)
} else {
// Let the user know if his/her device isn't able to send text messages
self.displayAlerViewWithTitle("Cannot Send Text Message", andMessage: "Your device is not able to send text messages.")
}
}
Run Code Online (Sandbox Code Playgroud)