yandexads-flutter
275 строк · 9.2 Кб
1// Autogenerated from Pigeon (v14.0.0), do not edit directly.
2// See also: https://pub.dev/packages/pigeon
3
4import Foundation
5#if os(iOS)
6import Flutter
7#elseif os(macOS)
8import FlutterMacOS
9#else
10#error("Unsupported platform.")
11#endif
12
13private func wrapResult(_ result: Any?) -> [Any?] {
14return [result]
15}
16
17private func wrapError(_ error: Any) -> [Any?] {
18if let flutterError = error as? FlutterError {
19return [
20flutterError.code,
21flutterError.message,
22flutterError.details
23]
24}
25return [
26"\(error)",
27"\(type(of: error))",
28"Stacktrace: \(Thread.callStackSymbols)"
29]
30}
31
32private func isNullish(_ value: Any?) -> Bool {
33return value is NSNull || value == nil
34}
35
36private func nilOrValue<T>(_ value: Any?) -> T? {
37if value is NSNull { return nil }
38return value as! T?
39}
40
41/// Generated class from Pigeon that represents data sent in messages.
42struct NativeError {
43var code: Int64
44var description: String
45
46static func fromList(_ list: [Any?]) -> NativeError? {
47let code = list[0] is Int64 ? list[0] as! Int64 : Int64(list[0] as! Int32)
48let description = list[1] as! String
49
50return NativeError(
51code: code,
52description: description
53)
54}
55func toList() -> [Any?] {
56return [
57code,
58description,
59]
60}
61}
62
63/// Generated class from Pigeon that represents data sent in messages.
64struct NativeImpression {
65var data: String
66
67static func fromList(_ list: [Any?]) -> NativeImpression? {
68let data = list[0] as! String
69
70return NativeImpression(
71data: data
72)
73}
74func toList() -> [Any?] {
75return [
76data,
77]
78}
79}
80
81private class YandexAdsNativeCodecReader: FlutterStandardReader {
82override func readValue(ofType type: UInt8) -> Any? {
83switch type {
84case 128:
85return NativeError.fromList(self.readValue() as! [Any?])
86case 129:
87return NativeImpression.fromList(self.readValue() as! [Any?])
88default:
89return super.readValue(ofType: type)
90}
91}
92}
93
94private class YandexAdsNativeCodecWriter: FlutterStandardWriter {
95override func writeValue(_ value: Any) {
96if let value = value as? NativeError {
97super.writeByte(128)
98super.writeValue(value.toList())
99} else if let value = value as? NativeImpression {
100super.writeByte(129)
101super.writeValue(value.toList())
102} else {
103super.writeValue(value)
104}
105}
106}
107
108private class YandexAdsNativeCodecReaderWriter: FlutterStandardReaderWriter {
109override func reader(with data: Data) -> FlutterStandardReader {
110return YandexAdsNativeCodecReader(data: data)
111}
112
113override func writer(with data: NSMutableData) -> FlutterStandardWriter {
114return YandexAdsNativeCodecWriter(data: data)
115}
116}
117
118class YandexAdsNativeCodec: FlutterStandardMessageCodec {
119static let shared = YandexAdsNativeCodec(readerWriter: YandexAdsNativeCodecReaderWriter())
120}
121
122/// Generated protocol from Pigeon that represents a handler of messages from Flutter.
123protocol YandexAdsNative {
124func make(id: String) throws
125func load(id: String, width: Int64, height: Int64) throws
126func onAdLoaded(id: String, completion: @escaping (Result<Void, Error>) -> Void)
127func onAdFailedToLoad(id: String, completion: @escaping (Result<NativeError, Error>) -> Void)
128func onAdClicked(id: String, completion: @escaping (Result<Void, Error>) -> Void)
129func onLeftApplication(id: String, completion: @escaping (Result<Void, Error>) -> Void)
130func onReturnedToApplication(id: String, completion: @escaping (Result<Void, Error>) -> Void)
131func onImpression(id: String, completion: @escaping (Result<NativeImpression, Error>) -> Void)
132}
133
134/// Generated setup class from Pigeon to handle messages through the `binaryMessenger`.
135class YandexAdsNativeSetup {
136/// The codec used by YandexAdsNative.
137static var codec: FlutterStandardMessageCodec { YandexAdsNativeCodec.shared }
138/// Sets up an instance of `YandexAdsNative` to handle messages through the `binaryMessenger`.
139static func setUp(binaryMessenger: FlutterBinaryMessenger, api: YandexAdsNative?) {
140let makeChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.flutter_yandex_ads.YandexAdsNative.make", binaryMessenger: binaryMessenger, codec: codec)
141if let api = api {
142makeChannel.setMessageHandler { message, reply in
143let args = message as! [Any?]
144let idArg = args[0] as! String
145do {
146try api.make(id: idArg)
147reply(wrapResult(nil))
148} catch {
149reply(wrapError(error))
150}
151}
152} else {
153makeChannel.setMessageHandler(nil)
154}
155let loadChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.flutter_yandex_ads.YandexAdsNative.load", binaryMessenger: binaryMessenger, codec: codec)
156if let api = api {
157loadChannel.setMessageHandler { message, reply in
158let args = message as! [Any?]
159let idArg = args[0] as! String
160let widthArg = args[1] is Int64 ? args[1] as! Int64 : Int64(args[1] as! Int32)
161let heightArg = args[2] is Int64 ? args[2] as! Int64 : Int64(args[2] as! Int32)
162do {
163try api.load(id: idArg, width: widthArg, height: heightArg)
164reply(wrapResult(nil))
165} catch {
166reply(wrapError(error))
167}
168}
169} else {
170loadChannel.setMessageHandler(nil)
171}
172let onAdLoadedChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.flutter_yandex_ads.YandexAdsNative.onAdLoaded", binaryMessenger: binaryMessenger, codec: codec)
173if let api = api {
174onAdLoadedChannel.setMessageHandler { message, reply in
175let args = message as! [Any?]
176let idArg = args[0] as! String
177api.onAdLoaded(id: idArg) { result in
178switch result {
179case .success:
180reply(wrapResult(nil))
181case .failure(let error):
182reply(wrapError(error))
183}
184}
185}
186} else {
187onAdLoadedChannel.setMessageHandler(nil)
188}
189let onAdFailedToLoadChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.flutter_yandex_ads.YandexAdsNative.onAdFailedToLoad", binaryMessenger: binaryMessenger, codec: codec)
190if let api = api {
191onAdFailedToLoadChannel.setMessageHandler { message, reply in
192let args = message as! [Any?]
193let idArg = args[0] as! String
194api.onAdFailedToLoad(id: idArg) { result in
195switch result {
196case .success(let res):
197reply(wrapResult(res))
198case .failure(let error):
199reply(wrapError(error))
200}
201}
202}
203} else {
204onAdFailedToLoadChannel.setMessageHandler(nil)
205}
206let onAdClickedChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.flutter_yandex_ads.YandexAdsNative.onAdClicked", binaryMessenger: binaryMessenger, codec: codec)
207if let api = api {
208onAdClickedChannel.setMessageHandler { message, reply in
209let args = message as! [Any?]
210let idArg = args[0] as! String
211api.onAdClicked(id: idArg) { result in
212switch result {
213case .success:
214reply(wrapResult(nil))
215case .failure(let error):
216reply(wrapError(error))
217}
218}
219}
220} else {
221onAdClickedChannel.setMessageHandler(nil)
222}
223let onLeftApplicationChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.flutter_yandex_ads.YandexAdsNative.onLeftApplication", binaryMessenger: binaryMessenger, codec: codec)
224if let api = api {
225onLeftApplicationChannel.setMessageHandler { message, reply in
226let args = message as! [Any?]
227let idArg = args[0] as! String
228api.onLeftApplication(id: idArg) { result in
229switch result {
230case .success:
231reply(wrapResult(nil))
232case .failure(let error):
233reply(wrapError(error))
234}
235}
236}
237} else {
238onLeftApplicationChannel.setMessageHandler(nil)
239}
240let onReturnedToApplicationChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.flutter_yandex_ads.YandexAdsNative.onReturnedToApplication", binaryMessenger: binaryMessenger, codec: codec)
241if let api = api {
242onReturnedToApplicationChannel.setMessageHandler { message, reply in
243let args = message as! [Any?]
244let idArg = args[0] as! String
245api.onReturnedToApplication(id: idArg) { result in
246switch result {
247case .success:
248reply(wrapResult(nil))
249case .failure(let error):
250reply(wrapError(error))
251}
252}
253}
254} else {
255onReturnedToApplicationChannel.setMessageHandler(nil)
256}
257let onImpressionChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.flutter_yandex_ads.YandexAdsNative.onImpression", binaryMessenger: binaryMessenger, codec: codec)
258if let api = api {
259onImpressionChannel.setMessageHandler { message, reply in
260let args = message as! [Any?]
261let idArg = args[0] as! String
262api.onImpression(id: idArg) { result in
263switch result {
264case .success(let res):
265reply(wrapResult(res))
266case .failure(let error):
267reply(wrapError(error))
268}
269}
270}
271} else {
272onImpressionChannel.setMessageHandler(nil)
273}
274}
275}
276