Skip to content

Commit 52d5d49

Browse files
TcoNDTcoND
authored andcommitted
chore: 🤖 nitro 0.29.3
fix ios
1 parent 450cebb commit 52d5d49

File tree

4 files changed

+47
-39
lines changed

4 files changed

+47
-39
lines changed

ios/NitroRestart.swift

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,50 +4,58 @@
44
//
55
// Created by tconns94 on 8/21/2025.
66
//
7-
87
import UIKit
98
import Foundation
109
import React
1110

1211
class NitroRestart: HybridNitroRestartSpec {
1312
func restartApp(moduleName: String) {
1413
DispatchQueue.main.async {
15-
guard let appDelegate = UIApplication.shared.delegate as? RCTAppDelegate,
16-
let bridge = appDelegate.bridge,
17-
let window = appDelegate.window else {
18-
print("NitroRestart Error: Unable to access app delegate, bridge, or window")
14+
guard let appDelegate = UIApplication.shared.delegate else {
15+
print("NitroRestart Error: Unable to access app delegate")
16+
return
17+
}
18+
19+
// Try to get window and factory using reflection
20+
guard let window = (appDelegate as? NSObject)?.value(forKey: "window") as? UIWindow,
21+
let factory = (appDelegate as? NSObject)?.value(forKey: "reactNativeFactory") else {
22+
print("NitroRestart Error: Unable to access window or React Native factory")
1923
return
2024
}
2125

22-
let rootView = RCTRootView(
23-
bridge: bridge,
24-
moduleName: moduleName,
25-
initialProperties: nil
26-
)
27-
let vc = UIViewController()
28-
vc.view = rootView
29-
window.rootViewController = vc
30-
window.makeKeyAndVisible()
26+
// Use reflection to call startReactNative method
27+
let factoryObject = factory as AnyObject
28+
let selector = Selector(("startReactNative:in:launchOptions:"))
29+
if factoryObject.responds(to: selector) {
30+
let method = factoryObject.method(for: selector)
31+
typealias StartReactNativeMethod = @convention(c) (AnyObject, Selector, String, UIWindow, [UIApplication.LaunchOptionsKey: Any]?) -> Void
32+
let startReactNative = unsafeBitCast(method, to: StartReactNativeMethod.self)
33+
startReactNative(factoryObject, selector, moduleName, window, nil)
34+
} else {
35+
print("NitroRestart Error: startReactNative method not found")
36+
}
3137
}
3238
}
3339

3440
func exitApp() {
3541
DispatchQueue.main.async {
36-
// Note: Direct app termination violates iOS guidelines and may cause App Store rejection
37-
// This implementation suspends the app instead of terminating it
38-
if let window = UIApplication.shared.windows.first {
39-
UIView.animate(withDuration: 0.3, animations: {
40-
window.alpha = 0
41-
window.transform = CGAffineTransform(scaleX: 0.8, y: 0.8)
42-
}) { _ in
43-
// Put app in suspended state (safer than exit)
44-
UIApplication.shared.perform(#selector(NSXPCConnection.suspend))
45-
}
42+
guard
43+
let scene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
44+
let window = scene.windows.first
45+
else { return }
46+
47+
UIView.animate(withDuration: 0.3, animations: {
48+
window.alpha = 0
49+
window.transform = CGAffineTransform(scaleX: 0.8, y: 0.8)
50+
}) { _ in
51+
// ⚠️ Lưu ý: Vi phạm guideline App Store nếu đưa lên store
52+
// Chỉ nên dùng trong app nội bộ hoặc dev
53+
UIApplication.shared.perform(#selector(NSXPCConnection.suspend))
4654
}
4755
}
4856
}
4957

5058
func getPid() -> Double {
51-
return Double(getpid())
59+
return Double(getpid())
5260
}
53-
}
61+
}

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-nitro-restart",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"description": "App restart and process management for React Native built with Nitro Modules. Provides native app restart, safe exit, and process ID functionality with cross-platform support for iOS and Android.",
55
"main": "lib/index",
66
"module": "lib/index",
@@ -86,11 +86,11 @@
8686
"@types/jest": "^29.5.12",
8787
"@types/react": "19.1.0",
8888
"conventional-changelog-conventionalcommits": "^9.1.0",
89-
"nitro-codegen": "^0.29.2",
89+
"nitro-codegen": "^0.29.3",
9090
"react": "19.1.0",
9191
"react-native": "0.80.2",
9292
"react-native-builder-bob": "^0.37.0",
93-
"react-native-nitro-modules": "^0.29.2",
93+
"react-native-nitro-modules": "^0.29.3",
9494
"semantic-release": "^24.2.6",
9595
"typescript": "5.0.4"
9696
},

tsconfig.tsbuildinfo

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

yarn.lock

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5770,13 +5770,13 @@ nerf-dart@^1.0.0:
57705770
resolved "https://registry.yarnpkg.com/nerf-dart/-/nerf-dart-1.0.0.tgz#e6dab7febf5ad816ea81cf5c629c5a0ebde72c1a"
57715771
integrity sha512-EZSPZB70jiVsivaBLYDCyntd5eH8NTSMOn3rB+HxwdmKThGELLdYv8qVIMWvZEFy9w8ZZpW9h9OB32l1rGtj7g==
57725772

5773-
nitro-codegen@^0.29.2:
5774-
version "0.29.2"
5775-
resolved "https://registry.yarnpkg.com/nitro-codegen/-/nitro-codegen-0.29.2.tgz#34324ccc8569ddf0a82f838f393a799a6dd732c6"
5776-
integrity sha512-Oi1iqt7C6XSDt2kn0SuWPagLxVGJHImgbxJ4T4lx5/0fl9JE3NbPfdQofF2dwfYoXYOZVDC3TNWwds1Dx6Ycvg==
5773+
nitro-codegen@^0.29.3:
5774+
version "0.29.3"
5775+
resolved "https://registry.yarnpkg.com/nitro-codegen/-/nitro-codegen-0.29.3.tgz#62975772b310d8f6a7545b82888f368535c11962"
5776+
integrity sha512-MgsnbZCJkSNxsDn5ziip9Cp8wscuSeeYS5cB8N7CYgYmI03xT8jXP8YJUlkTS5iPbXaI6rsRB1mQ84qNZgT9JQ==
57775777
dependencies:
57785778
chalk "^5.3.0"
5779-
react-native-nitro-modules "^0.29.2"
5779+
react-native-nitro-modules "^0.29.3"
57805780
ts-morph "^25.0.0"
57815781
yargs "^17.7.2"
57825782
zod "^4.0.5"
@@ -6636,10 +6636,10 @@ react-native-builder-bob@^0.37.0:
66366636
which "^2.0.2"
66376637
yargs "^17.5.1"
66386638

6639-
react-native-nitro-modules@^0.29.2:
6640-
version "0.29.2"
6641-
resolved "https://registry.yarnpkg.com/react-native-nitro-modules/-/react-native-nitro-modules-0.29.2.tgz#e1e419b7cfce875d83bbe0fda6a5a243b1f7719a"
6642-
integrity sha512-MdBiM+Rt/8T3xtstm1V7nkpwTEIXENjoU5Rb01Pkc4/tqP/6YQ3W0ZtVtZ6RwbRzBv9rJ12+7bgHeNNZ7WoRNw==
6639+
react-native-nitro-modules@^0.29.3:
6640+
version "0.29.3"
6641+
resolved "https://registry.yarnpkg.com/react-native-nitro-modules/-/react-native-nitro-modules-0.29.3.tgz#2352892770ddfcabe6e287d8d41b13d3a186342e"
6642+
integrity sha512-gGaCueHKaZSw2rlrKrPgMZE6O6qvsnTJwNysJgk4ZEHMwnVe6Auk5hc4+sJPQLOVd6o+HMHdVhVQhZZv1u19Eg==
66436643

66446644
react-native@0.80.2:
66456645
version "0.80.2"

0 commit comments

Comments
 (0)