Skip to content

Commit

Permalink
[PR-18437] Fix deprecation warnings (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgtv authored Oct 5, 2022
1 parent 275c3cc commit a2d093c
Show file tree
Hide file tree
Showing 16 changed files with 195 additions and 141 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ xcuserdata
project.xcworkspace
Intermediates
.DS_Store
.swiftpm
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import PackageDescription

let version = "1.4.13"
let version = "1.4.14"
// Checksum of the file at `sdkUrl` link. To generate: `swift package compute-checksum build/talkable_ios_sdk.zip`
let checksum = "eefa95b7a7b7c2ca12bdf837d958d0537f054541990dcdb79867259671c63495"
let checksum = "fb4a40393663845de2ed6b812916b634f179d0056d8d805e29768070bab88e97"
let sdkUrl = "https://github.com/talkable/ios-sdk/releases/download/\(version)/talkable_ios_sdk_\(version).zip"

let package = Package(
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Add Talkable SDK as a dependency to [`Package.swift`](https://www.swift.org/pack

```swift
dependencies: [
.package(url: "https://github.com/talkable/ios-sdk.git", .upToNextMajor(from: "1.4.13"))
.package(url: "https://github.com/talkable/ios-sdk.git", .upToNextMajor(from: "1.4.14"))
]
```

Expand All @@ -28,7 +28,7 @@ dependencies: [
To integrate Talkable SDK into your Xcode project using CocoaPods, specify it in your [`Podfile`](https://guides.cocoapods.org/using/the-podfile.html):

```ruby
pod 'TalkableSDK', '~> 1.4.13'
pod 'TalkableSDK', '~> 1.4.14'
```

## Manual building
Expand Down
2 changes: 1 addition & 1 deletion Talkable/TKBLConstants.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#import "TKBLConstants.h"

NSString* TKBLVersion = @"1.4.13";
NSString* TKBLVersion = @"1.4.14";

NSString* TKBLErrorDomain = @"com.talkable.ios-sdk";

Expand Down
31 changes: 21 additions & 10 deletions Talkable/TKBLContactsLoader.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ - (void)loadContactsWithCompletionHandler:(void(^)(NSArray* contacts))completion
}

- (void)presentPermissionAlert {
UIViewController *topController = [TKBLHelper topMostController];
if (!topController) {
return;
}

NSString *message = NSLocalizedString(@"This app requires access to your contacts to function properly. Please visit the Privacy section in the Settings app.", nil);
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"" message:message preferredStyle:UIAlertControllerStyleAlert];

Expand All @@ -45,8 +50,8 @@ - (void)presentPermissionAlert {
}];

[alert addAction:action];
[[TKBLHelper topMostController] presentViewController:alert animated:YES completion:nil];

[topController presentViewController:alert animated:YES completion:nil];
}

- (NSArray*)grabContacts {
Expand All @@ -58,7 +63,7 @@ - (NSArray*)grabContacts {
CNContactFetchRequest *request = [[CNContactFetchRequest alloc] initWithKeysToFetch:keys];
NSError *error;
NSMutableArray* contacts = [NSMutableArray array];

[store enumerateContactsWithFetchRequest:request error:&error usingBlock:^(CNContact * __nonnull contact, BOOL * __nonnull stop) {
if (error) {
TKBLLog(@"error while loading contacts - %@", [error localizedDescription]);
Expand All @@ -83,33 +88,39 @@ - (NSArray*)grabContacts {
[phoneNumbers addObject:phone];
}
}

for (CNLabeledValue *label in contact.emailAddresses) {
NSString *email = label.value;
if ([email length] > 0) {
[emailAddresses addObject:email];
}
}

[contacts addObject:@{TKBLContactFirstNameKey: firstName ? firstName : [NSNull null],
TKBLContactLastNameKey: lastName ? lastName : [NSNull null],
TKBLContactFullNameKey: fullName ? fullName : [NSNull null],
TKBLContactEmailKey: emailAddresses,
TKBLContactPhoneNumberKey: phoneNumbers}];
}
}];

return [NSArray arrayWithArray:contacts];
}

- (void)requestForAccessWithCompletion:(void(^)(BOOL granted))completionHandler {
NSString* contactsPermissions = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSContactsUsageDescription"];
if (!contactsPermissions) {
TKBLLog(@"ERROR! \"NSContactsUsageDescription\" key has to be defined inside the plist for accessing contacts. Please add the key and re-run the application.");
return;
}

CNAuthorizationStatus status = [CNContactStore authorizationStatusForEntityType:CNEntityTypeContacts];
CNContactStore *store = [[CNContactStore alloc] init];

switch (status) {
case CNAuthorizationStatusAuthorized:
completionHandler(YES);

break;
case CNAuthorizationStatusRestricted:
case CNAuthorizationStatusDenied:
Expand All @@ -118,10 +129,10 @@ - (void)requestForAccessWithCompletion:(void(^)(BOOL granted))completionHandler
if (error) {
TKBLLog(@"error while loading contacts - %@", [error localizedDescription]);
}

completionHandler(granted);
}];

break;
}
}
Expand Down
8 changes: 5 additions & 3 deletions Talkable/TKBLHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,21 @@

@interface TKBLHelper : NSObject

+ (NSString*)currentAppVersion;
+ (NSString* _Nullable)currentAppVersion;

+ (BOOL)wasAppUpdated;

+ (void)registerInstall;
+ (BOOL)installRegistered;

+ (NSDictionary*)featuresInfo;
+ (NSDictionary* _Nonnull)featuresInfo;

+ (BOOL)isFacebookMessengerInstalled;
+ (BOOL)isWhatsAppInstalled;
+ (BOOL)isFacebookSharingUsingSocialFrameworkAvailable;

+ (UIViewController*) topMostController;
+ (UIViewController* _Nullable)topMostController;
+ (UIWindow* _Nullable)keyWindow;
+ (void)openURL:(NSURL* _Nonnull)url;

@end
53 changes: 49 additions & 4 deletions Talkable/TKBLHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

@implementation TKBLHelper

+ (NSString*)currentAppVersion {
+ (NSString* _Nullable)currentAppVersion {
return [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
}

Expand Down Expand Up @@ -45,7 +45,7 @@ + (BOOL)installRegistered {
return [pref boolForKey:TKBLInstallRegisteredKey];
}

+ (NSDictionary*)featuresInfo {
+ (NSDictionary* _Nonnull)featuresInfo {
return @{
@"send_sms": [NSNumber numberWithBool:[self canSendSMS]],
@"copy_to_clipboard": [NSNumber numberWithBool:YES],
Expand Down Expand Up @@ -77,8 +77,16 @@ + (BOOL)isFacebookSharingUsingSocialFrameworkAvailable {
[[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"fbauth2://"]];;
}

+ (UIViewController*) topMostController {
UIViewController *topController = [UIApplication sharedApplication].keyWindow.rootViewController;
+ (UIViewController* _Nullable)topMostController {
UIWindow *keyWindow = [self keyWindow];
if (!keyWindow) {
return nil;
}

UIViewController *topController = keyWindow.rootViewController;
if (!topController) {
return nil;
}

while (topController.presentedViewController) {
topController = topController.presentedViewController;
Expand All @@ -87,6 +95,43 @@ + (UIViewController*) topMostController {
return topController;
}

+ (UIWindow* _Nullable)keyWindow {
if (@available(iOS 15, *)) {
for (UIScene *scene in UIApplication.sharedApplication.connectedScenes) {
if ([scene isKindOfClass:[UIWindowScene class]] &&
scene.activationState == UISceneActivationStateForegroundActive) {
return ((UIWindowScene *)scene).keyWindow;
}
}
} else {
#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_15_0
if (@available(iOS 13, *)) {
for (UIWindow *window in UIApplication.sharedApplication.windows) {
if (window.isKeyWindow) {
return window;
}
}
} else {
#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_13_0
return UIApplication.sharedApplication.keyWindow;
#endif // __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_13_0
}
#endif // __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_15_0
}
TKBLLog(@"Unable to get keyWindow", nil);
return nil;
}

+ (void)openURL:(NSURL* _Nonnull)url {
if (@available(iOS 10, *)) {
[UIApplication.sharedApplication openURL:url options:@{} completionHandler:nil];
} else {
#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_10_0
[UIApplication.sharedApplication openURL:url];
#endif // __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_10_0
}
}

#pragma mark - [Private]

+ (BOOL)canSendSMS {
Expand Down
2 changes: 1 addition & 1 deletion Talkable/TKBLKeychainHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ - (NSData*)dataForKey:(NSString*)key {
- (NSMutableDictionary*)keychainItem:(NSString*)key {
NSMutableDictionary* keychainItem = [[NSMutableDictionary alloc] init];
keychainItem[(__bridge id)kSecClass] = (__bridge id)kSecClassGenericPassword;
keychainItem[(__bridge id)kSecAttrAccessible] = (__bridge id)kSecAttrAccessibleAlways;
keychainItem[(__bridge id)kSecAttrAccessible] = (__bridge id)kSecAttrAccessibleAfterFirstUnlock;
keychainItem[(__bridge id)kSecAttrAccount] = key;
keychainItem[(__bridge id)kSecAttrService] = _serviceName;
return keychainItem;
Expand Down
46 changes: 34 additions & 12 deletions Talkable/TKBLOfferTarget.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,13 @@ - (void)tkblShareOfferViaNativeMail:(NSDictionary*)params sender:(id)sender {
[self shareSucceeded:(WKWebView*)sender withChannel:TKBLShareChannelNativeMail];
};
ctrl.mailComposeDelegate = watcher;
[[UIViewController currentViewController] presentViewController:ctrl animated:YES completion:nil];

UIViewController* currentViewController = [UIViewController currentViewController];
if (!currentViewController) {
return;
}

[currentViewController presentViewController:ctrl animated:YES completion:nil];
}
}

Expand Down Expand Up @@ -83,13 +89,11 @@ - (void)tkblShareOfferViaFacebookMessage:(NSDictionary*)params sender:(id)sender
// There is no way to pass a text to fb messenger, only an url.
NSString* claimURL = [params objectForKey:TKBLOfferClaimUrlKey];
NSString* escapedClaimURL = [claimURL stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLHostAllowedCharacterSet]];
UIApplication* app = [UIApplication sharedApplication];

// There is no way to check whether user shared a message or not
[self shareSucceeded:(WKWebView*)sender withChannel:TKBLShareChannelFacebookMessage];

[app openURL:[NSURL URLWithString:[NSString stringWithFormat:@"fb-messenger://share?link=%@", escapedClaimURL]]];

[TKBLHelper openURL:[NSURL URLWithString:[NSString stringWithFormat:@"fb-messenger://share?link=%@", escapedClaimURL]]];
}

- (void)tkblShareOfferViaWhatsapp:(NSDictionary*)params sender:(id)sender {
Expand All @@ -110,12 +114,11 @@ - (void)tkblShareOfferViaWhatsapp:(NSDictionary*)params sender:(id)sender {
}

NSString* escapedMessage = [message stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLHostAllowedCharacterSet]];
UIApplication* app = [UIApplication sharedApplication];

// There is no way to check whether the user shared a message or not
[self shareSucceeded:(WKWebView*)sender withChannel:TKBLShareChannelWhatsApp];

[app openURL:[NSURL URLWithString:[NSString stringWithFormat:@"whatsapp://send?text=%@", escapedMessage]]];
[TKBLHelper openURL:[NSURL URLWithString:[NSString stringWithFormat:@"whatsapp://send?text=%@", escapedMessage]]];
}

- (void)tkblShareOfferViaSms:(NSDictionary*)params sender:(id)sender {
Expand All @@ -125,6 +128,11 @@ - (void)tkblShareOfferViaSms:(NSDictionary*)params sender:(id)sender {
return;
}

UIViewController* currentViewController = [UIViewController currentViewController];
if (!currentViewController) {
return;
}

NSString* message = [params objectForKey:TKBLShareMessage];
if (!message) {
message = [NSString string];
Expand Down Expand Up @@ -156,15 +164,14 @@ - (void)tkblShareOfferViaSms:(NSDictionary*)params sender:(id)sender {
[self shareSucceeded:(WKWebView*)sender withChannel:TKBLShareChannelSMS];
};
controller.messageComposeDelegate = watcher;
[[UIViewController currentViewController] presentViewController:controller animated:YES completion:nil];

[currentViewController presentViewController:controller animated:YES completion:nil];
}

- (void)tkblPutToClipboard:(NSDictionary*)params sender:(id)sender {
NSString* text = [params objectForKey:TKBLClipboardTextKey];
if (text) {
UIPasteboard* pasteBoard = [UIPasteboard generalPasteboard];
pasteBoard.persistent = YES;
[pasteBoard setString:text];
[UIPasteboard generalPasteboard].string = text;
} else {
TKBLLog(@"Specify URL for key '%@'", TKBLClipboardTextKey);
}
Expand Down Expand Up @@ -252,7 +259,17 @@ - (void)shareOnFacebookUsingSocialFrameworkWithParams:(NSDictionary*)params comp
return;
}

UIViewController* currentViewController = [UIViewController currentViewController];
if (!currentViewController) {
return;
}

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
// Will be reworked in PR-18567, ignore for now
SLComposeViewController* shareController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
#pragma clang diagnostic pop

NSString* claimURL = [params objectForKey:TKBLOfferClaimUrlKey];
if (claimURL) {
[shareController addURL:[NSURL URLWithString:claimURL]];
Expand All @@ -269,7 +286,7 @@ - (void)shareOnFacebookUsingSocialFrameworkWithParams:(NSDictionary*)params comp
}
}];

[[UIViewController currentViewController] presentViewController:shareController animated:YES completion:nil];
[currentViewController presentViewController:shareController animated:YES completion:nil];

}

Expand All @@ -282,6 +299,11 @@ - (void)publishFeaturesInfo:(id)sender {
}

- (void)shareViaLinkWithParams:(NSDictionary*)params andSender:(id)sender {
UIViewController* currentViewController = [UIViewController currentViewController];
if (!currentViewController) {
return;
}

NSMutableArray* activityItems = [NSMutableArray array];

NSString* message = [params objectForKey:TKBLShareMessage];
Expand All @@ -306,7 +328,7 @@ - (void)shareViaLinkWithParams:(NSDictionary*)params andSender:(id)sender {

[controller setExcludedActivityTypes:@[UIActivityTypePostToFacebook, UIActivityTypePostToTwitter]];

[[UIViewController currentViewController] presentViewController:controller animated:YES completion:nil];
[currentViewController presentViewController:controller animated:YES completion:nil];
}

@end
3 changes: 2 additions & 1 deletion Talkable/TKBLOfferViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#import "TKBLOfferViewController.h"
#import "TKBLOfferTarget.h"
#import "TKBLHelper.h"
#import "UIViewControllerExt.h"

@implementation TKBLOfferViewController {
Expand Down Expand Up @@ -80,7 +81,7 @@ - (void)webView:(WKWebView*)webView decidePolicyForNavigationAction:(WKNavigatio
NSURL *url = navigationAction.request.URL;
UIApplication *app = [UIApplication sharedApplication];
if (![self isAnchorNavigation:webView.URL to:url] && [app canOpenURL:url]) {
[app openURL:url];
[TKBLHelper openURL:url];
decisionHandler(WKNavigationActionPolicyCancel);
return;
}
Expand Down
Loading

0 comments on commit a2d093c

Please sign in to comment.