update flutter_sms to the latest version
This commit is contained in:
@@ -0,0 +1,135 @@
|
||||
// Autogenerated from Pigeon (v26.1.5), do not edit directly.
|
||||
// See also: https://pub.dev/packages/pigeon
|
||||
|
||||
import Foundation
|
||||
|
||||
#if os(iOS)
|
||||
import Flutter
|
||||
#elseif os(macOS)
|
||||
import FlutterMacOS
|
||||
#else
|
||||
#error("Unsupported platform.")
|
||||
#endif
|
||||
|
||||
/// Error class for passing custom error details to Dart side.
|
||||
final class PigeonError: Error {
|
||||
let code: String
|
||||
let message: String?
|
||||
let details: Sendable?
|
||||
|
||||
init(code: String, message: String?, details: Sendable?) {
|
||||
self.code = code
|
||||
self.message = message
|
||||
self.details = details
|
||||
}
|
||||
|
||||
var localizedDescription: String {
|
||||
return
|
||||
"PigeonError(code: \(code), message: \(message ?? "<nil>"), details: \(details ?? "<nil>")"
|
||||
}
|
||||
}
|
||||
|
||||
private func wrapResult(_ result: Any?) -> [Any?] {
|
||||
return [result]
|
||||
}
|
||||
|
||||
private func wrapError(_ error: Any) -> [Any?] {
|
||||
if let pigeonError = error as? PigeonError {
|
||||
return [
|
||||
pigeonError.code,
|
||||
pigeonError.message,
|
||||
pigeonError.details,
|
||||
]
|
||||
}
|
||||
if let flutterError = error as? FlutterError {
|
||||
return [
|
||||
flutterError.code,
|
||||
flutterError.message,
|
||||
flutterError.details,
|
||||
]
|
||||
}
|
||||
return [
|
||||
"\(error)",
|
||||
"\(type(of: error))",
|
||||
"Stacktrace: \(Thread.callStackSymbols)",
|
||||
]
|
||||
}
|
||||
|
||||
private func isNullish(_ value: Any?) -> Bool {
|
||||
return value is NSNull || value == nil
|
||||
}
|
||||
|
||||
private func nilOrValue<T>(_ value: Any?) -> T? {
|
||||
if value is NSNull { return nil }
|
||||
return value as! T?
|
||||
}
|
||||
|
||||
|
||||
private class MessagesPigeonCodecReader: FlutterStandardReader {
|
||||
}
|
||||
|
||||
private class MessagesPigeonCodecWriter: FlutterStandardWriter {
|
||||
}
|
||||
|
||||
private class MessagesPigeonCodecReaderWriter: FlutterStandardReaderWriter {
|
||||
override func reader(with data: Data) -> FlutterStandardReader {
|
||||
return MessagesPigeonCodecReader(data: data)
|
||||
}
|
||||
|
||||
override func writer(with data: NSMutableData) -> FlutterStandardWriter {
|
||||
return MessagesPigeonCodecWriter(data: data)
|
||||
}
|
||||
}
|
||||
|
||||
class MessagesPigeonCodec: FlutterStandardMessageCodec, @unchecked Sendable {
|
||||
static let shared = MessagesPigeonCodec(readerWriter: MessagesPigeonCodecReaderWriter())
|
||||
}
|
||||
|
||||
|
||||
/// Generated protocol from Pigeon that represents a handler of messages from Flutter.
|
||||
protocol SmsHostApi {
|
||||
func sendSms(message: String, recipients: [String], completion: @escaping (Result<String, Error>) -> Void)
|
||||
func canSendSms(completion: @escaping (Result<Bool, Error>) -> Void)
|
||||
}
|
||||
|
||||
/// Generated setup class from Pigeon to handle messages through the `binaryMessenger`.
|
||||
class SmsHostApiSetup {
|
||||
static var codec: FlutterStandardMessageCodec { MessagesPigeonCodec.shared }
|
||||
/// Sets up an instance of `SmsHostApi` to handle messages through the `binaryMessenger`.
|
||||
static func setUp(binaryMessenger: FlutterBinaryMessenger, api: SmsHostApi?, messageChannelSuffix: String = "") {
|
||||
let channelSuffix = messageChannelSuffix.count > 0 ? ".\(messageChannelSuffix)" : ""
|
||||
let sendSmsChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.flutter_sms.SmsHostApi.sendSms\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
|
||||
if let api = api {
|
||||
sendSmsChannel.setMessageHandler { message, reply in
|
||||
let args = message as! [Any?]
|
||||
let messageArg = args[0] as! String
|
||||
let recipientsArg = args[1] as! [String]
|
||||
api.sendSms(message: messageArg, recipients: recipientsArg) { result in
|
||||
switch result {
|
||||
case .success(let res):
|
||||
reply(wrapResult(res))
|
||||
case .failure(let error):
|
||||
reply(wrapError(error))
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
sendSmsChannel.setMessageHandler(nil)
|
||||
}
|
||||
let canSendSmsChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.flutter_sms.SmsHostApi.canSendSms\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
|
||||
if let api = api {
|
||||
canSendSmsChannel.setMessageHandler { _, reply in
|
||||
api.canSendSms { result in
|
||||
switch result {
|
||||
case .success(let res):
|
||||
reply(wrapResult(res))
|
||||
case .failure(let error):
|
||||
reply(wrapError(error))
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
canSendSmsChannel.setMessageHandler(nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,60 +2,50 @@ import Flutter
|
||||
import UIKit
|
||||
import MessageUI
|
||||
|
||||
public class SwiftFlutterSmsPlugin: NSObject, FlutterPlugin, UINavigationControllerDelegate, MFMessageComposeViewControllerDelegate {
|
||||
var result: FlutterResult?
|
||||
public class SwiftFlutterSmsPlugin: NSObject, FlutterPlugin, SmsHostApi, UINavigationControllerDelegate, MFMessageComposeViewControllerDelegate {
|
||||
var result: ((Result<String, Error>) -> Void)?
|
||||
var _arguments = [String: Any]()
|
||||
|
||||
public static func register(with registrar: FlutterPluginRegistrar) {
|
||||
let channel = FlutterMethodChannel(name: "flutter_sms", binaryMessenger: registrar.messenger())
|
||||
let instance = SwiftFlutterSmsPlugin()
|
||||
registrar.addMethodCallDelegate(instance, channel: channel)
|
||||
SmsHostApiSetup.setUp(binaryMessenger: registrar.messenger(), api: instance)
|
||||
}
|
||||
|
||||
public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
|
||||
switch call.method {
|
||||
case "sendSMS":
|
||||
_arguments = call.arguments as! [String : Any];
|
||||
#if targetEnvironment(simulator)
|
||||
result(FlutterError(
|
||||
code: "message_not_sent",
|
||||
message: "Cannot send message on this device!",
|
||||
details: "Cannot send SMS and MMS on a Simulator. Test on a real device."
|
||||
)
|
||||
)
|
||||
#else
|
||||
if (MFMessageComposeViewController.canSendText()) {
|
||||
self.result = result
|
||||
let controller = MFMessageComposeViewController()
|
||||
controller.body = _arguments["message"] as? String
|
||||
controller.recipients = _arguments["recipients"] as? [String]
|
||||
controller.messageComposeDelegate = self
|
||||
UIApplication.shared.keyWindow?.rootViewController?.present(controller, animated: true, completion: nil)
|
||||
} else {
|
||||
result(FlutterError(
|
||||
code: "device_not_capable",
|
||||
message: "The current device is not capable of sending text messages.",
|
||||
details: "A device may be unable to send messages if it does not support messaging or if it is not currently configured to send messages. This only applies to the ability to send text messages via iMessage, SMS, and MMS."
|
||||
)
|
||||
)
|
||||
}
|
||||
#endif
|
||||
public func sendSms(message: String, recipients: [String], completion: @escaping (Result<String, Error>) -> Void) {
|
||||
#if targetEnvironment(simulator)
|
||||
completion(.failure(FlutterError(
|
||||
code: "message_not_sent",
|
||||
message: "Cannot send message on this device!",
|
||||
details: "Cannot send SMS and MMS on a Simulator. Test on a real device."
|
||||
)))
|
||||
#else
|
||||
if (MFMessageComposeViewController.canSendText()) {
|
||||
self.result = completion
|
||||
let controller = MFMessageComposeViewController()
|
||||
controller.body = message
|
||||
controller.recipients = recipients
|
||||
controller.messageComposeDelegate = self
|
||||
UIApplication.shared.keyWindow?.rootViewController?.present(controller, animated: true, completion: nil)
|
||||
} else {
|
||||
completion(.failure(FlutterError(
|
||||
code: "device_not_capable",
|
||||
message: "The current device is not capable of sending text messages.",
|
||||
details: "A device may be unable to send messages if it does not support messaging or if it is not currently configured to send messages. This only applies to the ability to send text messages via iMessage, SMS, and MMS."
|
||||
)))
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
case "canSendSMS":
|
||||
#if targetEnvironment(simulator)
|
||||
result(false)
|
||||
#else
|
||||
if (MFMessageComposeViewController.canSendText()) {
|
||||
result(true)
|
||||
} else {
|
||||
result(false)
|
||||
}
|
||||
#endif
|
||||
|
||||
default:
|
||||
result(FlutterMethodNotImplemented)
|
||||
break
|
||||
}
|
||||
public func canSendSms() -> Bool {
|
||||
#if targetEnvironment(simulator)
|
||||
return false
|
||||
#else
|
||||
if (MFMessageComposeViewController.canSendText()) {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public func messageComposeViewController(_ controller: MFMessageComposeViewController, didFinishWith result: MessageComposeResult) {
|
||||
@@ -65,7 +55,7 @@ public class SwiftFlutterSmsPlugin: NSObject, FlutterPlugin, UINavigationControl
|
||||
MessageComposeResult.failed: "failed",
|
||||
]
|
||||
if let callback = self.result {
|
||||
callback(map[result])
|
||||
callback(.success(map[result] ?? "unknown"))
|
||||
}
|
||||
UIApplication.shared.keyWindow?.rootViewController?.dismiss(animated: true, completion: nil)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
#
|
||||
# Generated file, do not edit.
|
||||
#
|
||||
|
||||
import lldb
|
||||
|
||||
def handle_new_rx_page(frame: lldb.SBFrame, bp_loc, extra_args, intern_dict):
|
||||
"""Intercept NOTIFY_DEBUGGER_ABOUT_RX_PAGES and touch the pages."""
|
||||
base = frame.register["x0"].GetValueAsAddress()
|
||||
page_len = frame.register["x1"].GetValueAsUnsigned()
|
||||
|
||||
# Note: NOTIFY_DEBUGGER_ABOUT_RX_PAGES will check contents of the
|
||||
# first page to see if handled it correctly. This makes diagnosing
|
||||
# misconfiguration (e.g. missing breakpoint) easier.
|
||||
data = bytearray(page_len)
|
||||
data[0:8] = b'IHELPED!'
|
||||
|
||||
error = lldb.SBError()
|
||||
frame.GetThread().GetProcess().WriteMemory(base, data, error)
|
||||
if not error.Success():
|
||||
print(f'Failed to write into {base}[+{page_len}]', error)
|
||||
return
|
||||
|
||||
def __lldb_init_module(debugger: lldb.SBDebugger, _):
|
||||
target = debugger.GetDummyTarget()
|
||||
# Caveat: must use BreakpointCreateByRegEx here and not
|
||||
# BreakpointCreateByName. For some reasons callback function does not
|
||||
# get carried over from dummy target for the later.
|
||||
bp = target.BreakpointCreateByRegex("^NOTIFY_DEBUGGER_ABOUT_RX_PAGES$")
|
||||
bp.SetScriptCallbackFunction('{}.handle_new_rx_page'.format(__name__))
|
||||
bp.SetAutoContinue(True)
|
||||
print("-- LLDB integration loaded --")
|
||||
@@ -0,0 +1,5 @@
|
||||
#
|
||||
# Generated file, do not edit.
|
||||
#
|
||||
|
||||
command script import --relative-to-command-file flutter_lldb_helper.py
|
||||
Reference in New Issue
Block a user