-
Notifications
You must be signed in to change notification settings - Fork 923
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add shareSingle telegram (iOS only) (#1061)
* feat: add telegram share on ios (text and number) * feat: telegram share ios url and url with message * docs: add telegram share single ios
- Loading branch information
Showing
10 changed files
with
538 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
example/ | ||
website/ | ||
|
||
# generated by bob | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// | ||
// TelegranShare.h | ||
// RNShare | ||
// | ||
// Created by Akinn Rosa on 07-27-21. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
// import RCTConvert | ||
#if __has_include(<React/RCTConvert.h>) | ||
#import <React/RCTConvert.h> | ||
#elif __has_include("RCTConvert.h") | ||
#import "RCTConvert.h" | ||
#else | ||
#import "React/RCTConvert.h" // Required when used as a Pod in a Swift project | ||
#endif | ||
// import RCTBridge | ||
#if __has_include(<React/RCTBridge.h>) | ||
#import <React/RCTBridge.h> | ||
#elif __has_include("RCTBridge.h") | ||
#import "RCTBridge.h" | ||
#else | ||
#import "React/RCTBridge.h" // Required when used as a Pod in a Swift project | ||
#endif | ||
// import RCTUIManager | ||
#if __has_include(<React/RCTUIManager.h>) | ||
#import <React/RCTUIManager.h> | ||
#elif __has_include("RCTUIManager.h") | ||
#import "RCTUIManager.h" | ||
#else | ||
#import "React/RCTUIManager.h" // Required when used as a Pod in a Swift project | ||
#endif | ||
// import RCTLog | ||
#if __has_include(<React/RCTLog.h>) | ||
#import <React/RCTLog.h> | ||
#elif __has_include("RCTLog.h") | ||
#import "RCTLog.h" | ||
#else | ||
#import "React/RCTLog.h" // Required when used as a Pod in a Swift project | ||
#endif | ||
// import RCTUtils | ||
#if __has_include(<React/RCTUtils.h>) | ||
#import <React/RCTUtils.h> | ||
#elif __has_include("RCTUtils.h") | ||
#import "RCTUtils.h" | ||
#else | ||
#import "React/RCTUtils.h" // Required when used as a Pod in a Swift project | ||
#endif | ||
@interface TelegramShare : NSObject <RCTBridgeModule> | ||
|
||
- (void) shareSingle:(NSDictionary *)options failureCallback:(RCTResponseErrorBlock)failureCallback successCallback:(RCTResponseSenderBlock)successCallback; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// | ||
// TelegramShare.m.m | ||
// RNShare | ||
// | ||
// Created by Akinn Rosa on 07-27-21. | ||
// | ||
|
||
#import "TelegramShare.h" | ||
#import <AVFoundation/AVFoundation.h> | ||
@import Photos; | ||
|
||
@implementation TelegramShare | ||
RCT_EXPORT_MODULE(); | ||
- (void)shareSingle:(NSDictionary *)options | ||
failureCallback:(RCTResponseErrorBlock)failureCallback | ||
successCallback:(RCTResponseSenderBlock)successCallback { | ||
|
||
NSString *text = [RCTConvert NSString:options[@"message"]]; | ||
text = (NSString*)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(NULL,(CFStringRef) text, NULL,CFSTR("!*'();:@&=+$,/?%#[]"),kCFStringEncodingUTF8)); | ||
|
||
NSString *url = [RCTConvert NSString:options[@"url"]]; | ||
|
||
NSString *telegramMsg = [NSString stringWithFormat:@"tg://msg?text=%@", text]; | ||
NSString *telegramMsgUrl = [NSString stringWithFormat:@"tg://msg_url?text=%@&url=%@", text, url]; | ||
|
||
NSString * urlTelegram = url ? telegramMsgUrl : telegramMsg; | ||
NSURL * shareURL = [NSURL URLWithString:urlTelegram]; | ||
|
||
if ([[UIApplication sharedApplication] canOpenURL: shareURL]) { | ||
[[UIApplication sharedApplication] openURL: shareURL]; | ||
successCallback(@[]); | ||
} else { | ||
// Cannot open telegram | ||
NSString *stringURL = @"https://itunes.apple.com/app/telegram-messenger/id686449807"; | ||
NSURL *url = [NSURL URLWithString:stringURL]; | ||
|
||
[[UIApplication sharedApplication] openURL:url options:@{} completionHandler:^(BOOL success) {}]; | ||
|
||
NSString *errorMessage = @"Not installed"; | ||
NSDictionary *userInfo = @{NSLocalizedFailureReasonErrorKey: NSLocalizedString(errorMessage, nil)}; | ||
NSError *error = [NSError errorWithDomain:@"com.rnshare" code:1 userInfo:userInfo]; | ||
|
||
NSLog(@"%@", errorMessage); | ||
failureCallback(error); | ||
} | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.