@@ -12,6 +12,7 @@ public class SwiftFlutterShareMePlugin: NSObject, FlutterPlugin, SharingDelegate
12
12
let _methodTwitter = " twitter_share " ;
13
13
let _methodInstagram = " instagram_share " ;
14
14
let _methodSystemShare = " system_share " ;
15
+ let _methodTelegramShare = " telegram_share " ;
15
16
16
17
var result : FlutterResult ?
17
18
var documentInteractionController : UIDocumentInteractionController ?
@@ -55,7 +56,6 @@ public class SwiftFlutterShareMePlugin: NSObject, FlutterPlugin, SharingDelegate
55
56
}
56
57
else if ( call. method. elementsEqual ( _methodWhatsAppPersonal) ) {
57
58
let args = call. arguments as? Dictionary < String , Any >
58
-
59
59
shareWhatsAppPersonal ( message: args![ " msg " ] as! String , phoneNumber: args![ " phoneNumber " ] as! String , result: result)
60
60
}
61
61
else if ( call. method. elementsEqual ( _methodFaceBook) ) {
@@ -70,6 +70,10 @@ public class SwiftFlutterShareMePlugin: NSObject, FlutterPlugin, SharingDelegate
70
70
let args = call. arguments as? Dictionary < String , Any >
71
71
shareInstagram ( args: args!)
72
72
}
73
+ else if ( call. method. elementsEqual ( _methodTelegramShare) ) {
74
+ let args = call. arguments as? Dictionary < String , Any >
75
+ shareToTelegram ( message: args![ " msg " ] as! String )
76
+ }
73
77
else {
74
78
let args = call. arguments as? Dictionary < String , Any >
75
79
systemShare ( message: args![ " msg " ] as! String , result: result)
@@ -218,10 +222,27 @@ public class SwiftFlutterShareMePlugin: NSObject, FlutterPlugin, SharingDelegate
218
222
}
219
223
}
220
224
221
-
222
-
223
225
}
226
+ //share via telegram
227
+ //@ text that you want to share.
228
+ func shareToTelegram( message: String , result: @escaping FlutterResult )
229
+ {
230
+ let telegram = " tg://msg?text= \( message) "
231
+ var characterSet = CharacterSet . urlQueryAllowed
232
+ characterSet. insert ( charactersIn: " ?& " )
233
+ let telegramURL = NSURL ( string: telegram. addingPercentEncoding ( withAllowedCharacters: characterSet) !)
234
+ if UIApplication . shared. canOpenURL ( telegramURL! as URL )
235
+ {
236
+ result ( " Sucess " ) ;
237
+ UIApplication . shared. openURL ( telegramURL! as URL )
238
+ }
239
+ else
240
+ {
241
+ result ( FlutterError ( code: " Not found " , message: " WhatsAppBusiness is not found " , details: " WhatsAppBusiness not intalled or Check url scheme. " ) ) ;
242
+ }
224
243
244
+ }
245
+
225
246
//share via system native dialog
226
247
//@ text that you want to share.
227
248
func systemShare( message: String , result: @escaping FlutterResult ) {
0 commit comments