-1

Is it possible to send automatic text messages in iOS with Delphi Xe8? I have found examples to do so in Android, but none in iOS. Would I need to import headers to use in Delphi or is there already built in functionality to do so?

Danilo Casa
  • 506
  • 1
  • 9
  • 18
ThisGuy
  • 1,405
  • 1
  • 24
  • 51

2 Answers2

2

No. The SMS systems on the two platforms work differently.

On Android it is possible to send an SMS programmatically and entirely automatically.

On iOS (and WinPhone) you can only pre-compose an SMS message and then hand over to a system component to have it presented (by the system) to the user for them to confirm whether they wish to send the message or not.

The iOS code for this is:

var sms := new MFMessageComposeViewController;

sms.messageComposeDelegate := self;
sms.recipients  := ['7275']; // mobile #('s)
sms.body        := 'The message to send';

presentViewController(sms) animated(true) completion(nil); 

NOTE: This code is ObjectPascal, but it is RemObjects Oxygene, which compiles directly against the Cocoa framework and produces native iOS code, so no need to import headers etc. To convert this to FireMonkey you will need to find the corresponding declarations/headers in Delphi, assuming they are provided.

When converting to Delphi it might help to compare with the Objective-C version of this code, since Delphi provides none of the extended support for the syntax involved in Cocoa framework calls. For example, setting the recipients property in Objective-C:

sms.recipients = [NSArray arrayWithObjects:@"7275", nil];

Further discussion of the differences and how the above Oxygene code corresponds to the Objective-C, to help in the conversion to Delphi, is in a blog post I wrote about having developed an SMS based application for iOS, Android (and WinPhone).

Deltics
  • 22,162
  • 2
  • 42
  • 70
1

for ios use dpf ios native controls :)

this is my tested function ( dest number is in object itself ... )

procedure SEND_SMS(NUMBER, TEXT: string);
  {$IFDEF ANDROID}
   var SmsManager: JSmsManager;
       smsTo, txt: JString;
   begin
      SmsManager := TJSmsManager.JavaClass.getDefault;
      smsTo := StringToJString(NUMBER);
      txt := StringToJString(TEXT) ;
      SmsManager.sendTextMessage( smsTo, nil, txt, nil, nil);
   end;
  {$ENDIF}
  {$IFDEF iOS}
   var sms: TDPFMessageCompose;
   begin
   sms := TDPFMessageCompose.Create(application);
   SMS.MessageCompose( TEXT, [NUMBER] ) ;
   sms.free;
  end ;
 {$ENDIF}
 {$IF Defined(MSWINDOWS) }
  begin
    showmessage( 'sms ');
  end;
 {$ENDIF}
drcrck
  • 11
  • 1
  • 1