Я новичок в iOS
разработке и xCode
. Раньше я разрабатывал Android и знаю, что должен работать с Intent, чтобы звонить и отправлять SMS в приложении для Android. Теперь я хочу разработать простое приложение, которое при нажатии Button
отправляет SMS
на определенный номер. Итак, я установил Mac OS 10.11
VM
на свой Ubuntu
. И могу подключить к нему мой iPhone
5 и запустить мое простое приложение Hello World
на реальном iPhone
устройстве, а не simulator
. Теперь я создал Button
в StoryBoard
и выполняю функции, следуя этой статье: Отправить SMS-сообщение Toturial
Также посмотрите другие ссылки и было похоже. Вот мой простой ViewController.swift
.
import UIKit
import MessageUI
class ViewController: UIViewController, MFMessageComposeViewControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func sendMessage(sender: AnyObject) {
print("Send button pressed") //display a text to make sure is calling
if MFMessageComposeViewController.canSendText() {
let controller = MFMessageComposeViewController()
controller.body = "TestMessage "
controller.recipients = ["xxxxxxxxx", "xxxxxxxxx"] // sending for two numbers
controller.messageComposeDelegate = self
self.presentViewController(controller, animated: true, completion: nil)
}
}
func messageComposeViewController(controller: MFMessageComposeViewController, didFinishWithResult result: MessageComposeResult) {
switch (result.rawValue) {
case MessageComposeResultCancelled.rawValue:
print("Message was cancelled")
self.dismissViewControllerAnimated(true, completion: nil)
case MessageComposeResultFailed.rawValue:
print("Message failed")
self.dismissViewControllerAnimated(true, completion: nil)
case MessageComposeResultSent.rawValue:
print("Message was sent")
self.dismissViewControllerAnimated(true, completion: nil)
default:
break;
}
}
}
А также создал кнопку Simple
и свяжите ее с sendMessage
выше. Когда я запускаю приложение, отображается кнопка, а когда я ее нажимаю, кажется, что оно что-то делает, но SMS не отправляется. Любая идея?? Я очень ценю это.
Обновление: как сказал наш друг, я добавил print("Send button pressed")
в sendMessage Button
, поэтому я узнаю, что кнопка вызывает sendMessage
, когда я ее нажимаю.
print("Send button pressed")
в своюsendMessage
функцию? Если вы не видите это сообщение в консоли, функция, вероятно, не вызывается. - person kabiroberai   schedule 24.07.2016print
в блокif
? - person kabiroberai   schedule 24.07.2016print
внутрьif (MFMessageComposeViewController.canSendText()) {...}
- person kabiroberai   schedule 24.07.2016