Skip to content

Commit

Permalink
[IMPROVEMENT] Create App Group property on Info.plist (#1858)
Browse files Browse the repository at this point in the history
Co-authored-by: Diego Mello <diegolmello@gmail.com>
  • Loading branch information
djorkaeffalexandre and diegolmello authored Mar 11, 2020
1 parent 9bea72f commit 1a35511
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 32 deletions.
3 changes: 0 additions & 3 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -605,9 +605,6 @@ export default class Root extends React.Component {
}

init = async() => {
if (isIOS) {
await RNUserDefaults.setName('group.ios.chat.rocket');
}
RNUserDefaults.objectForKey(THEME_PREFERENCES_KEY).then(this.setTheme);
const [notification, deepLinking] = await Promise.all([initializePushNotifications(), Linking.getInitialURL()]);
const parsedDeepLinkingURL = parseDeepLinking(deepLinking);
Expand Down
5 changes: 1 addition & 4 deletions app/share.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
import Navigation from './lib/ShareNavigation';
import store from './lib/createStore';
import sharedStyles from './views/Styles';
import { isNotch, isIOS, supportSystemTheme } from './utils/deviceInfo';
import { isNotch, supportSystemTheme } from './utils/deviceInfo';
import { defaultHeader, onNavigationStateChange, cardStyle } from './utils/navigation';
import RocketChat, { THEME_PREFERENCES_KEY } from './lib/rocketchat';
import { ThemeContext } from './theme';
Expand Down Expand Up @@ -77,9 +77,6 @@ class Root extends React.Component {
}

init = async() => {
if (isIOS) {
await RNUserDefaults.setName('group.ios.chat.rocket');
}
RNUserDefaults.objectForKey(THEME_PREFERENCES_KEY).then(this.setTheme);
const currentServer = await RNUserDefaults.get('currentServer');
const token = await RNUserDefaults.get(RocketChat.TOKEN_KEY);
Expand Down
4 changes: 2 additions & 2 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ PODS:
- React
- RNScreens (2.0.0-alpha.3):
- React
- RNUserDefaults (1.7.0):
- RNUserDefaults (1.8.1):
- React
- RNVectorIcons (6.6.0):
- React
Expand Down Expand Up @@ -786,7 +786,7 @@ SPEC CHECKSUMS:
RNReanimated: b2ab0b693dddd2339bd2f300e770f6302d2e960c
RNRootView: 895a4813dedeaca82db2fa868ca1c333d790e494
RNScreens: 402a99b0a27c0c32f079cec12d3ccbd35e20cd7f
RNUserDefaults: af71a1cdf1c12baf8210bc741c65f5faba9826d6
RNUserDefaults: c421fd97ad06b35c16608c5d0fe675db353f632d
RNVectorIcons: 0bb4def82230be1333ddaeee9fcba45f0b288ed4
RSKImageCropper: a446db0e8444a036b34f3c43db01b2373baa4b2a
SDWebImage: 4d5c027c935438f341ed33dbac53ff9f479922ca
Expand Down
2 changes: 1 addition & 1 deletion ios/Pods/Local Podspecs/RNUserDefaults.podspec.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions ios/Pods/Manifest.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion ios/RocketChatRN/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
<key>NSMicrophoneUsageDescription</key>
<string>Use your microphone to record audio messages</string>
<key>NSMotionUsageDescription</key>
<string>Allow $(PRODUCT_NAME) to access your device's accelerometer</string>
<string>Allow $(PRODUCT_NAME) to access your device&apos;s accelerometer</string>
<key>NSPhotoLibraryAddUsageDescription</key>
<string>Give $(PRODUCT_NAME) permission to save photos</string>
<key>NSPhotoLibraryUsageDescription</key>
Expand Down Expand Up @@ -110,5 +110,7 @@
<string>firefox</string>
<string>brave</string>
</array>
<key>AppGroup</key>
<string>group.ios.chat.rocket</string>
</dict>
</plist>
2 changes: 2 additions & 0 deletions ios/ShareRocketChatRN/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,7 @@
<array>
<string>custom.ttf</string>
</array>
<key>AppGroup</key>
<string>group.ios.chat.rocket</string>
</dict>
</plist>
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
"rn-extensions-share": "^2.3.10",
"rn-fetch-blob": "0.11.2",
"rn-root-view": "^1.0.3",
"rn-user-defaults": "1.7.0",
"rn-user-defaults": "^1.8.1",
"semver": "6.3.0",
"snyk": "1.210.0",
"strip-ansi": "5.2.0",
Expand Down
35 changes: 26 additions & 9 deletions patches/react-native+0.61.5.patch
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
diff --git a/node_modules/react-native/Libraries/Network/RCTHTTPRequestHandler.mm b/node_modules/react-native/Libraries/Network/RCTHTTPRequestHandler.mm
index e72e943..ec0a0ba 100644
index e72e943..ee0c7a1 100644
--- a/node_modules/react-native/Libraries/Network/RCTHTTPRequestHandler.mm
+++ b/node_modules/react-native/Libraries/Network/RCTHTTPRequestHandler.mm
@@ -55,6 +55,59 @@ - (BOOL)canHandleRequest:(NSURLRequest *)request
@@ -10,6 +10,7 @@
#import <mutex>

#import <React/RCTNetworking.h>
+#import "RNUserDefaults.h"

@interface RCTHTTPRequestHandler () <NSURLSessionDataDelegate>

@@ -55,6 +56,59 @@ - (BOOL)canHandleRequest:(NSURLRequest *)request
return [schemes containsObject:request.URL.scheme.lowercaseString];
}

Expand Down Expand Up @@ -62,14 +70,14 @@ index e72e943..ec0a0ba 100644
- (NSURLSessionDataTask *)sendRequest:(NSURLRequest *)request
withDelegate:(id<RCTURLRequestDelegate>)delegate
{
@@ -171,4 +224,20 @@ - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didComp
@@ -171,4 +225,20 @@ - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didComp
[delegate URLRequest:task didCompleteWithError:error];
}

+-(void)URLSession:(NSURLSession *)session didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential * _Nullable))completionHandler {
+
+ NSString *host = challenge.protectionSpace.host;
+ NSDictionary *clientSSL = [[[NSUserDefaults alloc] initWithSuiteName:@"group.ios.chat.rocket"] objectForKey:host];
+ NSDictionary *clientSSL = [[RNUserDefaults getDefaultUser] objectForKey:host];
+
+ NSURLCredential *credential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust];
+
Expand All @@ -84,10 +92,19 @@ index e72e943..ec0a0ba 100644
+
@end
diff --git a/node_modules/react-native/Libraries/WebSocket/RCTSRWebSocket.m b/node_modules/react-native/Libraries/WebSocket/RCTSRWebSocket.m
index a134d2e..a88c099 100644
index a134d2e..1526d60 100644
--- a/node_modules/react-native/Libraries/WebSocket/RCTSRWebSocket.m
+++ b/node_modules/react-native/Libraries/WebSocket/RCTSRWebSocket.m
@@ -481,6 +481,29 @@ - (void)didConnect
@@ -27,6 +27,8 @@
#import <React/RCTAssert.h>
#import <React/RCTLog.h>

+#import "RNUserDefaults.h"
+
typedef NS_ENUM(NSInteger, RCTSROpCode) {
RCTSROpCodeTextFrame = 0x1,
RCTSROpCodeBinaryFrame = 0x2,
@@ -481,6 +483,29 @@ - (void)didConnect
[self _readHTTPHeader];
}

Expand Down Expand Up @@ -117,12 +134,12 @@ index a134d2e..a88c099 100644
- (void)_initializeStreams;
{
assert(_url.port.unsignedIntValue <= UINT32_MAX);
@@ -518,6 +541,15 @@ - (void)_initializeStreams;
@@ -518,6 +543,15 @@ - (void)_initializeStreams;
RCTLogInfo(@"SocketRocket: In debug mode. Allowing connection to any root cert");
#endif

+ // SSL Pinning
+ NSDictionary *clientSSL = [[[NSUserDefaults alloc] initWithSuiteName:@"group.ios.chat.rocket"] objectForKey:host];
+ NSDictionary *clientSSL = [[RNUserDefaults getDefaultUser] objectForKey:host];
+ if (clientSSL != (id)[NSNull null]) {
+ NSString *path = [clientSSL objectForKey:@"path"];
+ NSString *password = [clientSSL objectForKey:@"password"];
Expand All @@ -133,7 +150,7 @@ index a134d2e..a88c099 100644
[_outputStream setProperty:SSLOptions
forKey:(__bridge id)kCFStreamPropertySSLSettings];
}
@@ -597,6 +629,7 @@ - (void)closeWithCode:(NSInteger)code reason:(NSString *)reason;
@@ -597,6 +631,7 @@ - (void)closeWithCode:(NSInteger)code reason:(NSString *)reason;
}
}

Expand Down
17 changes: 12 additions & 5 deletions patches/react-native-notifications+2.0.6.patch
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
diff --git a/node_modules/react-native-notifications/RNNotifications/RNNotificationEventHandler.m b/node_modules/react-native-notifications/RNNotifications/RNNotificationEventHandler.m
index edc4fd4..aeb5eaa 100644
index edc4fd4..7cd77f6 100644
--- a/node_modules/react-native-notifications/RNNotifications/RNNotificationEventHandler.m
+++ b/node_modules/react-native-notifications/RNNotifications/RNNotificationEventHandler.m
@@ -28,9 +28,92 @@ - (void)didReceiveForegroundNotification:(UNNotification *)notification withComp
@@ -3,6 +3,7 @@
#import "RNNotificationUtils.h"
#import "RCTConvert+RNNotifications.h"
#import "RNNotificationParser.h"
+#import "RNUserDefaults.h"

@implementation RNNotificationEventHandler {
RNNotificationsStore* _store;
@@ -28,9 +29,91 @@ - (void)didReceiveForegroundNotification:(UNNotification *)notification withComp
[RNEventEmitter sendEvent:RNNotificationReceivedForeground body:[RNNotificationParser parseNotification:notification]];
}

Expand Down Expand Up @@ -54,10 +62,9 @@ index edc4fd4..aeb5eaa 100644
+ NSString *msg = [(UNTextInputNotificationResponse *)response userText];
+
+ // get credentials
+ NSUserDefaults *userDefaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.ios.chat.rocket"];
+ NSString *TOKEN_KEY = @"reactnativemeteor_usertoken";
+ NSString *userId = [userDefaults stringForKey:[NSString stringWithFormat:@"%@-%@", TOKEN_KEY, [self serverURL:host]]];
+ NSString *token = [userDefaults stringForKey:[NSString stringWithFormat:@"%@-%@", TOKEN_KEY, userId]];
+ NSString *userId = [[RNUserDefaults getDefaultUser] stringForKey:[NSString stringWithFormat:@"%@-%@", TOKEN_KEY, [self serverURL:host]]];
+ NSString *token = [[RNUserDefaults getDefaultUser] stringForKey:[NSString stringWithFormat:@"%@-%@", TOKEN_KEY, userId]];
+
+ // background task - we need this because fetch doesn't work if app is closed/killed
+ UIApplication *app = [UIApplication sharedApplication];
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10379,10 +10379,10 @@ rn-root-view@^1.0.3:
resolved "https://registry.yarnpkg.com/rn-root-view/-/rn-root-view-1.0.3.tgz#a2cddc717278cb2175fb29b7c006e407b7f0d0e2"
integrity sha512-BIKm8hY5q8+pxK9B5ugYjqutoI9xn2JfxIZKWoaFmAl1bOIM4oXjwFQrRM1e6lFgzz99MN6Mf2dK3Alsywnvvw==

rn-user-defaults@1.7.0:
version "1.7.0"
resolved "https://registry.yarnpkg.com/rn-user-defaults/-/rn-user-defaults-1.7.0.tgz#8d1b79657dec3977e8f8983814b8591821f77236"
integrity sha512-Qo6sIH8wldmQ0oOMMvljec4WOa/a1Up1pdatoXZGaPG1gl8OKgKH5HPKyddcABYtxPeBUTPVzCxP/6S6wPCqGQ==
rn-user-defaults@^1.8.1:
version "1.8.1"
resolved "https://registry.yarnpkg.com/rn-user-defaults/-/rn-user-defaults-1.8.1.tgz#ccb8048f3ce43388ae40ac33eb063bfa93071702"
integrity sha512-pnUiB6Xn++5YGzSA1BKOsRAdz/GPkW3MViN5Yii6XGp5d6arcP4pOVIGmiFlOfxIFrHD3GU440WFnt5L7ogMSg==

rsvp@^3.3.3:
version "3.6.2"
Expand Down

0 comments on commit 1a35511

Please sign in to comment.