source

iPhone에서 SMS를 프로그래밍 방식으로 전송하는 방법

manysource 2023. 4. 10. 22:03

iPhone에서 SMS를 프로그래밍 방식으로 전송하는 방법

SMS를 프로그램 방식으로 송신할 수 있는지, 그리고 어떻게 송신할 수 있는지 아는 사람이 있습니까?iPhone【SDK/Coco Touch】★★★★★★★★★★★★★★★★★★★?

제약 사항

iPhone의 프로그램 내에서 SMS를 보낼 수 있다면 백그라운드에서 스팸을 보내는 게임을 만들 수 있습니다.저는 여러분이 친구들에게 "이 새로운 게임을 시도해 보세요!내 박스박스도 록스하고, 너도 록스할 거야! roxxersboxxers.com!!!지금 가입하시면 3,200 RB 포인트를 드립니다!!"

Apple은 자동화된(또는 부분적으로 자동화된) SMS와 다이얼 조작에 제한이 있습니다.(게임에서 하루 중 특정 시간에 911에 전화를 걸었을 경우를 상상해 보십시오.)

인터넷상에 온라인 SMS 송신 서비스를 사용하는 중간 서버를 설정하고 완전한 자동화가 필요한 경우 해당 경로를 통해 SMS를 송신하는 것이 최선의 방법입니다.(즉, iPhone의 프로그램이 UDP 패킷을 서버로 전송하고, 서버가 실제 SMS를 전송합니다.)

iOS 4 업데이트

iOS 4를 하고 있습니다.viewController응용 프로그램으로 가져올 수 있습니다.SMS 필드를 미리 입력하면 사용자는 컨트롤러 내에서 SMS 전송을 시작할 수 있습니다."SMS:..." URL 형식을 사용하는 것과 달리, 이를 통해 응용 프로그램을 계속 열어 둘 수 있으며 to 필드와 body 필드를 모두 채울 수 있습니다.여러 수신인을 지정할 수도 있습니다.

이렇게 하면 응용 프로그램이 사용자가 명시적으로 인식하지 않고 자동화된 SMS를 보내는 것을 방지할 수 있습니다.iPhone 자체에서 완전히 자동화된 SMS를 보낼 수 없습니다. 사용자 조작이 필요합니다.그러나 적어도 모든 데이터를 채울 수 있고 애플리케이션을 닫지 않아도 됩니다.

MFMessage ComposeViewController 클래스는 문서화되어 있으며, 튜토리얼을 통해 구현이 얼마나 쉬운지 알 수 있습니다.

iOS 5 업데이트

iOS 5에는 iPod touch 및 iPad 장치용 메시지가 포함되어 있으므로 아직 직접 테스트하지 않았지만 모든 iOS 장치는 MFMessage Compose View Controller를 통해 SMS를 전송할 수 있습니다.이 경우, 애플은 셀룰러 모뎀이 없는 기기를 대신하여 메시지를 보내는 SMS 서버를 실행하고 있습니다.

iOS 6 업데이트

이 클래스는 변경되지 않습니다.

iOS 7 업데이트

사용 중인 메시지 미디어가 제목 또는 첨부 파일을 수락할지 여부와 수락할 첨부 파일의 종류를 확인할 수 있습니다.제목을 편집하고 미디어에 허용된 메시지에 첨부 파일을 추가할 수 있습니다.

iOS 8 업데이트

이 클래스는 변경되지 않습니다.

iOS 9 업데이트

이 클래스는 변경되지 않습니다.

iOS 10 업데이트

이 클래스는 변경되지 않습니다.

iOS 11 업데이트

이 클래스에 중요한 변경 사항은 없습니다.

이 클래스에 대한 제한 사항

iOS 4가 없는 전화에서는 작동하지 않으며 iOS 5를 제외하고 iPod touch나 iPad에서는 작동하지 않습니다. 이 컨트롤러를 사용하기 전에 장치와 iOS 제한을 감지하거나 최근 업그레이드된 3G, 3GS 및 4 iPhone으로 앱을 제한해야 합니다.

그러나 SMS를 보내는 중간 서버는 이러한 iOS 기기들이 인터넷에 접속할 수 있는 한 SMS를 보낼 수 있도록 하기 때문에 많은 애플리케이션에는 여전히 더 나은 솔루션이 될 수 있습니다.또는 둘 다 사용하고 장치가 지원하지 않는 경우에만 온라인 SMS 서비스로 폴백합니다.

.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];
}

문서 링크도 있고요

https://developer.apple.com/documentation/messageui/mfmessagecomposeviewcontroller

  1. 메시지를 추가해야 합니다.Xcode 프로젝트에 대한 UI.framework
  2. 음음음 include include include include include include include include include include include 를 포함합니다.#import <MessageUI/MessageUI.h> header file( 파일 내)
  3. 파일에 합니다.MFMessageComposeViewControllerDelegate&UINavigationControllerDelegate
  4. 고객님의 고객명IBAction of " " " " " " " 。MFMessageComposeViewController을 하다messageInstance
  5. 수 하려면 을 합니다.[MFMessageComposeViewController canSendText]아니오일 경우 예/아니오일 경우 예/아니오일 경우 입니다.
  6. 서서 if같이 한다: condition

    1. 번째 : ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★」messageInstance같이요.

      messageInstance.body = @"Hello from Shah";
      
    2. 그런 다음 메시지 수신인을 다음과 같이 결정합니다.

      messageInstance.recipients = [NSArray arrayWithObjects:@"12345678", @"87654321",         nil];
      
    3. 메시지에 위임자 설정인스턴스 이름:

      messageInstance.messageComposeDelegate = self;
      
    4. 마지막 줄에서 다음을 수행합니다.

      [self presentModalViewController:messageInstance animated:YES];
      

'어울리다'를 사용할 수 요.sms:[target phone number]SMS 응용 프로그램을 여는 URL이지만 SMS 본문을 텍스트로 프리필하는 방법에 대한 표시가 없습니다.

MacOS의 프로세스 간 통신 시스템 중 하나는 XPC입니다.이 시스템 계층은 libSystem 및 launchd를 사용한 plist 구조의 전송을 기반으로 프로세스 간 통신을 위해 개발되었습니다.실제로 사전과 같은 구조를 교환하여 프로세스를 관리할 수 있는 인터페이스입니다.iOS5는 유전으로 인해 이 메커니즘도 갖추고 있다.

이 소개의 의미는 이미 이해하셨을 수도 있습니다.네, iOS에는 XPC 통신 도구를 포함하는 시스템 서비스가 있습니다.그리고 저는 SMS 송신을 위한 데몬으로 작업을 예시하고 싶습니다.단, 이 기능은 iOS 6에서 수정되지만 iOS 5.0-5.1.1과 관련이 있습니다. 탈옥, 프라이빗 프레임워크 및 기타 불법적인 툴은 이용에 필요하지 않습니다./usr/include/xpc/* 디렉토리의 헤더 파일 세트만 필요합니다.

iOS에서 SMS를 전송하기 위한 요소 중 하나는 system service com.apple.chatkit입니다.이것들의 태스크에는 짧은 텍스트메시지 생성, 관리, 송신이 포함됩니다.제어를 용이하게 하기 위해 공용 통신 포트 com.apple.chatkit.client composeserver.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);

이것으로 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);

접속이 액티브하게 됩니다.이 시점에서 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!");

남은 것은 거의 없습니다.메시지를 XPC 포트로 송신해, 전달되고 있는 것을 확인해 주세요.

xpc_connection_send_message(myConnection, mydict);
xpc_connection_send_barrier(myConnection, ^{
NSLog(@"The message has been successfully delivered");
});

그게 다예요.SMS 전송 완료

메시지 추가UI.프레임워크 및 다음 코드 사용

#import <MessageUI/MessageUI.h> 

그 후:

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];
}

및 위임 방법 -

- (void)messageComposeViewController:(MFMessageComposeViewController *)controller
             didFinishWithResult:(MessageComposeResult)result {
      [self dismissViewControllerAnimated:YES completion:nil];
 }

다음의 어프로치를 사용할 수 있습니다.

[[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"sms:MobileNumber"]]


iOS는 자동으로 앱에서 메시지 앱의 메시지 작성 페이지로 이동합니다.URL의 스킴은 sms:로 시작하므로 메시지 앱에서 인식하여 실행하는 유형으로 식별됩니다.

다음의 순서에 따릅니다.

1. 추가MessageUI.Framework투사하다여기에 이미지 설명 입력

2. Import#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];
}

4. 실장delegate방법을 선택합니다.

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


   ///your stuff here 

    [self dismissViewControllerAnimated:YES completion:nil];
}

뛰어!

//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]; 
}

iOS에서 SMS를 보낼 수 있는 Swift 버전의 코드입니다.실제 기기에서만 작동한다는 점에 유의하시기 바랍니다.iOS 7+에서 코드가 테스트되었습니다.여기서 더 읽을 수 있습니다.

1) MFMessage ComposeViewControllerDelegate 및 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)
        }
}

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.")
    }
}

iOS 4에는 본문 및 응용 프로그램의 수신자와 함께 메시지 전송을 지원하는 클래스가 있습니다.이것은 메일을 보내는 것과 같습니다.매뉴얼은 링크텍스트를 참조해 주세요.

- (void)sendSMS:(NSString *)bodyOfMessage recipientList:(NSArray *)recipients
{
    UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
    UIImage *ui =resultimg.image;
    pasteboard.image = ui;
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sms:"]];
}

//이름과 번호를 사용하여 메서드를 호출합니다.

-(void)openMessageViewWithName:(NSString*)contactName withPhone:(NSString *)phone{

CTTelephonyNetworkInfo *networkInfo=[[CTTelephonyNetworkInfo alloc]init];

CTCarrier *carrier=networkInfo.subscriberCellularProvider;

NSString *Countrycode = carrier.isoCountryCode;

if ([Countrycode length]>0)     //Check If Sim Inserted
{

    [self sendSMS:msg recipientList:[NSMutableArray arrayWithObject:phone]];
}
else
{

    [AlertHelper showAlert:@"Message" withMessage:@"No sim card inserted"];
}

}

//메시지 전송 방법

- (void)sendSMS:(NSString *)bodyOfMessage recipientList:(NSMutableArray *)recipients{  
 MFMessageComposeViewController *controller1 = [[MFMessageComposeViewController alloc] init] ;
 controller1 = [[MFMessageComposeViewController alloc] init] ;
 if([MFMessageComposeViewController canSendText])
{
    controller1.body = bodyOfMessage;
    controller1.recipients = recipients;
    controller1.messageComposeDelegate = self;
    [self presentViewController:controller1 animated:YES completion:Nil];
 }
}

경우 개인 할 수 .CoreTelephony은 '아예'입니다.CTMessageCenter smssms를 에는 몇 가지가 있습니다.

사용방법:

- (void)showSMSPicker
{
    Class messageClass = (NSClassFromString(@"MFMessageComposeViewController"));

    if (messageClass != nil) {          
        // Check whether the current device is configured for sending SMS messages
        if ([messageClass canSendText]) {
           [self displaySMSComposerSheet];
        }   
    }
}

- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{       
    //feedbackMsg.hidden = NO;
    // Notifies users about errors associated with the interface
    switch (result)
    {
        case MessageComposeResultCancelled:
        {   
            UIAlertView *alert1 = [[UIAlertView alloc] initWithTitle:@"Message" message:@"SMS sending canceled!!!" delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
            [alert1 show];
            [alert1 release];
        }   

        // feedbackMsg.text = @"Result: SMS sending canceled";
        break;

        case MessageComposeResultSent:
        {
            UIAlertView *alert2 = [[UIAlertView alloc] initWithTitle:@"Message" message:@"SMS sent!!!" delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
            [alert2 show];
            [alert2 release];
        }   

        // feedbackMsg.text = @"Result: SMS sent";
        break;

        case MessageComposeResultFailed:
        {   
            UIAlertView *alert3 = [[UIAlertView alloc] initWithTitle:@"Message" message:@"SMS sending failed!!!" delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
            [alert3 show];
            [alert3 release];
        }   

        // feedbackMsg.text = @"Result: SMS sending failed";
        break;

        default:
        {   
            UIAlertView *alert4 = [[UIAlertView alloc] initWithTitle:@"Message" message:@"SMS not sent!!!" delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
            [alert4 show];
            [alert4 release];
        }   

        // feedbackMsg.text = @"Result: SMS not sent";
        break;
    }

    [self dismissModalViewControllerAnimated: YES];
}
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"sms:number"]] 

이것이 그것을 하기 위한 가장 빠르고 최선의 방법일 것이다.

MFMessage ComposeViewController를 표시할 수 있습니다.MFMessage ComposeViewController는 SMS를 전송할 수 있지만 사용자 프롬프트(탭 전송 버튼)를 사용합니다.사용자 허가 없이는 그렇게 할 수 없습니다.iOS 11 에서는, 수신 메시지의 필터와 같은 확장 기능을 사용해 iOS 에 스팸 여부를 통지할 수 있습니다.SMS로는 아무것도 할 수 없다

MFMessage ComposeViewController를 사용하여 자신의 앱에서 메시지를 만들고 보내는 방법을 보여줘야 합니다.

그렇지 않으면 shared Application 메서드를 사용할 수 있습니다.

언급URL : https://stackoverflow.com/questions/10848/how-to-programmatically-send-sms-on-the-iphone