From acf97f61f78b546a6f45b15b7d2378244d6189b6 Mon Sep 17 00:00:00 2001 From: kiok46 Date: Mon, 15 Aug 2016 10:03:50 +0530 Subject: [PATCH] sms for ios --- README.rst | 2 +- plyer/platforms/ios/sms.py | 48 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) mode change 100644 => 100755 README.rst create mode 100644 plyer/platforms/ios/sms.py diff --git a/README.rst b/README.rst old mode 100644 new mode 100755 index 9071312e5..6dcfd437c --- a/README.rst +++ b/README.rst @@ -28,7 +28,7 @@ Notifications X X X X Text to speech X X X X X Email (open mail client) X X X X X Vibrator X X -Sms (send messages) X +Sms (send messages) X X Compass X X Unique ID X X X X X Gyroscope X X diff --git a/plyer/platforms/ios/sms.py b/plyer/platforms/ios/sms.py new file mode 100644 index 000000000..ae18da6c8 --- /dev/null +++ b/plyer/platforms/ios/sms.py @@ -0,0 +1,48 @@ +''' +IOS Sms +---------- +''' + +try: + from urllib.parse import quote +except ImportError: + from urllib import quote + +from plyer.facades import Sms +from pyobjus import autoclass, objc_str +from pyobjus.dylib_manager import load_framework + +NSURL = autoclass('NSURL') +NSString = autoclass('NSString') +UIApplication = autoclass('UIApplication') +load_framework('/System/Library/Frameworks/MessageUI.framework') + + +class IOSSms(Sms): + + def _send(self, **kwargs): + ''' + This method provides sending messages to recipients. + + Expects 2 parameters in kwargs: + - recipient: String type + - message: String type + + Opens a mesage interface with recipient and message information. + ''' + recipient = kwargs.get('recipient') + message = kwargs.get('message') + url = "sms:" + if recipient: + # Apple has not supported multiple recipients yet. + url += str(recipient) + if message: + # Apple has to supported it yet. + pass + + nsurl = NSURL.alloc().initWithString_(objc_str(url)) + UIApplication.sharedApplication().openURL_(nsurl) + + +def instance(): + return IOSSms()