Skip to content
This repository was archived by the owner on Mar 18, 2025. It is now read-only.

Commit b9a3742

Browse files
committed
fix ios build and run
1 parent 840351b commit b9a3742

File tree

5 files changed

+127
-97
lines changed

5 files changed

+127
-97
lines changed
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
#import <RCTAppDelegate.h>
1+
#import <React/RCTBridgeDelegate.h>
22
#import <UIKit/UIKit.h>
33

4-
@interface AppDelegate : RCTAppDelegate
4+
@interface AppDelegate : UIResponder <UIApplicationDelegate, RCTBridgeDelegate>
5+
6+
@property(nonatomic, strong) UIWindow *window;
57

68
@end
Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,49 @@
11
#import "AppDelegate.h"
22

3+
#import <React/RCTBridge.h>
34
#import <React/RCTBundleURLProvider.h>
45
#import <React/RCTLinkingManager.h>
6+
#import <React/RCTRootView.h>
7+
8+
#ifdef FB_SONARKIT_ENABLED
9+
#import <FlipperKit/FlipperClient.h>
10+
#import <FlipperKitLayoutPlugin/FlipperKitLayoutPlugin.h>
11+
#import <FlipperKitUserDefaultsPlugin/FKUserDefaultsPlugin.h>
12+
#import <FlipperKitNetworkPlugin/FlipperKitNetworkPlugin.h>
13+
#import <SKIOSNetworkPlugin/SKIOSNetworkAdapter.h>
14+
#import <FlipperKitReactPlugin/FlipperKitReactPlugin.h>
15+
static void InitializeFlipper(UIApplication *application) {
16+
FlipperClient *client = [FlipperClient sharedClient];
17+
SKDescriptorMapper *layoutDescriptorMapper = [[SKDescriptorMapper alloc] initWithDefaults];
18+
[client addPlugin:[[FlipperKitLayoutPlugin alloc] initWithRootNode:application withDescriptorMapper:layoutDescriptorMapper]];
19+
[client addPlugin:[[FKUserDefaultsPlugin alloc] initWithSuiteName:nil]];
20+
[client addPlugin:[FlipperKitReactPlugin new]];
21+
[client addPlugin:[[FlipperKitNetworkPlugin alloc] initWithNetworkAdapter:[SKIOSNetworkAdapter new]]];
22+
[client start];
23+
}
24+
#endif
525

626
@implementation AppDelegate
727

828
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
929
{
10-
self.moduleName = @"CryptrReactNativeExample";
11-
// You can add your custom initial props in the dictionary below.
12-
// They will be passed down to the ViewController used by React Native.
13-
self.initialProps = @{};
14-
15-
return [super application:application didFinishLaunchingWithOptions:launchOptions];
30+
#ifdef FB_SONARKIT_ENABLED
31+
InitializeFlipper(application);
32+
#endif
33+
34+
RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
35+
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
36+
moduleName:@"CryptrReactNativeExample"
37+
initialProperties:nil];
38+
39+
rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];
40+
41+
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
42+
UIViewController *rootViewController = [UIViewController new];
43+
rootViewController.view = rootView;
44+
self.window.rootViewController = rootViewController;
45+
[self.window makeKeyAndVisible];
46+
return YES;
1647
}
1748

1849
- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
@@ -29,11 +60,4 @@ - (NSURL *)bundleURL
2960
#endif
3061
}
3162

32-
33-
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url
34-
options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options
35-
{
36-
return [RCTLinkingManager application:app openURL:url options:options];
37-
}
38-
3963
@end
Lines changed: 55 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,58 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="15702" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
3-
<device id="retina4_7" orientation="portrait" appearance="light"/>
4-
<dependencies>
5-
<deployment identifier="iOS"/>
6-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="15704"/>
7-
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
8-
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
9-
</dependencies>
10-
<scenes>
11-
<!--View Controller-->
12-
<scene sceneID="EHf-IW-A2E">
13-
<objects>
14-
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
15-
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
16-
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
17-
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
18-
<subviews>
19-
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="CryptrReactNativeExample" textAlignment="center" lineBreakMode="middleTruncation" baselineAdjustment="alignBaselines" minimumFontSize="18" translatesAutoresizingMaskIntoConstraints="NO" id="GJd-Yh-RWb">
20-
<rect key="frame" x="0.0" y="202" width="375" height="43"/>
21-
<fontDescription key="fontDescription" type="boldSystem" pointSize="36"/>
22-
<nil key="highlightedColor"/>
23-
</label>
24-
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Powered by React Native" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="9" translatesAutoresizingMaskIntoConstraints="NO" id="MN2-I3-ftu">
25-
<rect key="frame" x="0.0" y="626" width="375" height="21"/>
26-
<fontDescription key="fontDescription" type="system" pointSize="17"/>
27-
<nil key="highlightedColor"/>
28-
</label>
29-
</subviews>
30-
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
31-
<constraints>
32-
<constraint firstItem="Bcu-3y-fUS" firstAttribute="bottom" secondItem="MN2-I3-ftu" secondAttribute="bottom" constant="20" id="OZV-Vh-mqD"/>
33-
<constraint firstItem="Bcu-3y-fUS" firstAttribute="centerX" secondItem="GJd-Yh-RWb" secondAttribute="centerX" id="Q3B-4B-g5h"/>
34-
<constraint firstItem="MN2-I3-ftu" firstAttribute="centerX" secondItem="Bcu-3y-fUS" secondAttribute="centerX" id="akx-eg-2ui"/>
35-
<constraint firstItem="MN2-I3-ftu" firstAttribute="leading" secondItem="Bcu-3y-fUS" secondAttribute="leading" id="i1E-0Y-4RG"/>
36-
<constraint firstItem="GJd-Yh-RWb" firstAttribute="centerY" secondItem="Ze5-6b-2t3" secondAttribute="bottom" multiplier="1/3" constant="1" id="moa-c2-u7t"/>
37-
<constraint firstItem="GJd-Yh-RWb" firstAttribute="leading" secondItem="Bcu-3y-fUS" secondAttribute="leading" symbolic="YES" id="x7j-FC-K8j"/>
38-
</constraints>
39-
<viewLayoutGuide key="safeArea" id="Bcu-3y-fUS"/>
40-
</view>
41-
</viewController>
42-
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
43-
</objects>
44-
<point key="canvasLocation" x="52.173913043478265" y="375"/>
45-
</scene>
46-
</scenes>
3+
<device id="retina4_7" orientation="portrait" appearance="light"/>
4+
<dependencies>
5+
<deployment identifier="iOS"/>
6+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="15704"/>
7+
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
8+
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
9+
</dependencies>
10+
<scenes>
11+
<!--View Controller-->
12+
<scene sceneID="EHf-IW-A2E">
13+
<objects>
14+
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
15+
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
16+
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
17+
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
18+
<subviews>
19+
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="9" translatesAutoresizingMaskIntoConstraints="NO" id="obG-Y5-kRd">
20+
<rect key="frame" x="0.0" y="647" width="375" height="0.0"/>
21+
<fontDescription key="fontDescription" type="system" pointSize="17"/>
22+
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
23+
<nil key="highlightedColor"/>
24+
</label>
25+
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="react-native-cryptr-example" textAlignment="center" lineBreakMode="middleTruncation" baselineAdjustment="alignBaselines" minimumFontSize="18" translatesAutoresizingMaskIntoConstraints="NO" id="GJd-Yh-RWb">
26+
<rect key="frame" x="0.0" y="202" width="375" height="43"/>
27+
<fontDescription key="fontDescription" type="boldSystem" pointSize="36"/>
28+
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
29+
<nil key="highlightedColor"/>
30+
</label>
31+
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Powered by React Native" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="9" translatesAutoresizingMaskIntoConstraints="NO" id="MN2-I3-ftu">
32+
<rect key="frame" x="0.0" y="626" width="375" height="21"/>
33+
<fontDescription key="fontDescription" type="system" pointSize="17"/>
34+
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
35+
<nil key="highlightedColor"/>
36+
</label>
37+
</subviews>
38+
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
39+
<constraints>
40+
<constraint firstItem="Bcu-3y-fUS" firstAttribute="centerX" secondItem="obG-Y5-kRd" secondAttribute="centerX" id="5cz-MP-9tL"/>
41+
<constraint firstItem="Bcu-3y-fUS" firstAttribute="bottom" secondItem="MN2-I3-ftu" secondAttribute="bottom" constant="20" id="OZV-Vh-mqD"/>
42+
<constraint firstItem="Bcu-3y-fUS" firstAttribute="centerX" secondItem="GJd-Yh-RWb" secondAttribute="centerX" id="Q3B-4B-g5h"/>
43+
<constraint firstItem="obG-Y5-kRd" firstAttribute="leading" secondItem="Bcu-3y-fUS" secondAttribute="leading" symbolic="YES" id="SfN-ll-jLj"/>
44+
<constraint firstAttribute="bottom" secondItem="obG-Y5-kRd" secondAttribute="bottom" constant="20" id="Y44-ml-fuU"/>
45+
<constraint firstItem="MN2-I3-ftu" firstAttribute="centerX" secondItem="Bcu-3y-fUS" secondAttribute="centerX" id="akx-eg-2ui"/>
46+
<constraint firstItem="MN2-I3-ftu" firstAttribute="leading" secondItem="Bcu-3y-fUS" secondAttribute="leading" id="i1E-0Y-4RG"/>
47+
<constraint firstItem="GJd-Yh-RWb" firstAttribute="centerY" secondItem="Ze5-6b-2t3" secondAttribute="bottom" multiplier="1/3" constant="1" id="moa-c2-u7t"/>
48+
<constraint firstItem="GJd-Yh-RWb" firstAttribute="leading" secondItem="Bcu-3y-fUS" secondAttribute="leading" symbolic="YES" id="x7j-FC-K8j"/>
49+
</constraints>
50+
<viewLayoutGuide key="safeArea" id="Bcu-3y-fUS"/>
51+
</view>
52+
</viewController>
53+
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
54+
</objects>
55+
<point key="canvasLocation" x="52.173913043478265" y="375"/>
56+
</scene>
57+
</scenes>
4758
</document>

ios/CryptrReactNative.mm renamed to ios/CryptrReactNative.m

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -121,46 +121,44 @@ - (void)openInSafari:(NSURL *)URL {
121121
}
122122
RCTLogInfo(@"You specified a url.");
123123

124-
// if (@available(iOS 12.0, *)) {
125-
// ASWebAuthenticationSession* session =
126-
// [[ASWebAuthenticationSession alloc] initWithURL:url
127-
// callbackURLScheme: @"cryptr"
128-
// completionHandler:^(NSURL * _Nullable callbackURL,
129-
// NSError * _Nullable error) {
130-
// _authenticationVCC = nil;
131-
132-
// if (callbackURL) {
133-
// successCallback(@[callbackURL.absoluteString]);
134-
// } else if(error) {
135-
// errorCallback(@[[error localizedDescription]]);
136-
// }
137-
138-
// }];
139-
140-
// #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
141-
// if (@available(iOS 13.0, *)) {
142-
// session.presentationContextProvider = self;
143-
// if (prefersEphemeralWebBrowserSession) {
144-
// session.prefersEphemeralWebBrowserSession = true;
145-
// }
146-
// }
147-
// #endif
148-
149-
// _authenticationVCC = session;
150-
151-
// [session start];
152-
// } else {
124+
if (@available(iOS 12.0, *)) {
125+
ASWebAuthenticationSession* session =
126+
[[ASWebAuthenticationSession alloc] initWithURL:url
127+
callbackURLScheme: @"cryptr"
128+
completionHandler:^(NSURL * _Nullable callbackURL,
129+
NSError * _Nullable error) {
130+
_authenticationVCC = nil;
131+
132+
if (callbackURL) {
133+
successCallback(@[callbackURL.absoluteString]);
134+
} else if(error) {
135+
errorCallback(@[[error localizedDescription]]);
136+
}
137+
138+
}];
139+
140+
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
141+
if (@available(iOS 13.0, *)) {
142+
session.presentationContextProvider = self;
143+
if (prefersEphemeralWebBrowserSession) {
144+
session.prefersEphemeralWebBrowserSession = true;
145+
}
146+
}
147+
#endif
148+
149+
_authenticationVCC = session;
150+
151+
[session start];
152+
} else {
153153
[self openInSafari:url];
154154
return;
155-
// }
155+
}
156156
}
157157

158-
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
159158
#pragma mark - ASWebAuthenticationPresentationContextProviding
160159

161160
- (ASPresentationAnchor)presentationAnchorForWebAuthenticationSession:(ASWebAuthenticationSession *)session API_AVAILABLE(ios(13.0)){
162161
return [UIApplication sharedApplication].keyWindow;
163162
}
164-
#endif
165163

166164
@end

ios/CryptrReactNative.swift

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,9 @@ import AuthenticationServices
66
@objc(CryptrReactNative)
77
class CryptrReactNative: NSObject {
88

9-
// @objc(multiply:withB:withResolver:withRejecter:)
10-
// func multiply(a: Float, b: Float, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) -> Void {
11-
// resolve(a*b)
12-
// }
13-
149
override init() {
1510
super.init()
16-
}
11+
}
1712

1813
@objc static func requiresMainQueueSetup() -> Bool {
1914
return true

0 commit comments

Comments
 (0)