@@ -46,7 +46,7 @@ + (void)load {
4646 if (!NSUserDefaults .standardUserDefaults .flex_disableOSLog ) {
4747 return ;
4848 }
49-
49+
5050 // Thanks to @Ram4096 on GitHub for telling me that
5151 // os_log is conditionally enabled by the SDK version
5252 void *addr = __builtin_return_address (0 );
@@ -61,23 +61,23 @@ + (void)load {
6161 (void *)my_os_log_shim_enabled,
6262 (void **)&orig_os_log_shim_enabled
6363 }}, 1 ) == 0 ;
64-
64+
6565 if (FLEXDidHookNSLog && orig_os_log_shim_enabled != nil ) {
6666 // Check if our rebinding worked
6767 FLEXNSLogHookWorks = my_os_log_shim_enabled (addr) == NO ;
6868 }
69-
69+
7070 // So, just because we rebind the lazily loaded symbol for
7171 // this function doesn't mean it's even going to be used.
7272 // While it seems to be sufficient for the simulator, for
7373 // whatever reason it is not sufficient on-device. We need
7474 // to actually hook the function with something like Substrate.
75-
75+
7676 // Check if we have substrate, and if so use that instead
7777 void *handle = dlopen (" /usr/lib/libsubstrate.dylib" , RTLD_LAZY);
7878 if (handle) {
7979 MSHookFunction = dlsym (handle, " MSHookFunction" );
80-
80+
8181 if (MSHookFunction) {
8282 // Set the hook and check if it worked
8383 void *unused;
@@ -96,16 +96,16 @@ - (id)init {
9696
9797- (void )viewDidLoad {
9898 [super viewDidLoad ];
99-
99+
100100 self.showsSearchBar = YES ;
101101 self.showSearchBarInitially = NO ;
102102
103103 __weak __typeof (self) weakSelf = self;
104104 id logHandler = ^(NSArray <FLEXSystemLogMessage *> *newMessages) {
105- __strong __typeof (weakSelf) self = weakSelf;
106- [self handleUpdateWithNewMessages: newMessages];
105+ __strong __typeof (weakSelf) strongSelf = weakSelf;
106+ [strongSelf handleUpdateWithNewMessages: newMessages];
107107 };
108-
108+
109109 if (FLEXOSLogAvailable () && !FLEXNSLogHookWorks) {
110110 _logController = [FLEXOSLogController withUpdateHandler: logHandler];
111111 } else {
@@ -114,9 +114,9 @@ - (void)viewDidLoad {
114114
115115 self.tableView .separatorStyle = UITableViewCellSeparatorStyleNone;
116116 self.title = @" Waiting for Logs..." ;
117-
117+
118118 // Toolbar buttons //
119-
119+
120120 UIBarButtonItem *scrollDown = [UIBarButtonItem
121121 itemWithImage: FLEXResources.scrollToBottomIcon
122122 target: self
@@ -127,7 +127,7 @@ - (void)viewDidLoad {
127127 target: self
128128 action: @selector (showLogSettings )
129129 ];
130-
130+
131131 [self addToolbarItems: @[scrollDown, settings]];
132132}
133133
@@ -138,26 +138,30 @@ - (void)viewWillAppear:(BOOL)animated {
138138}
139139
140140- (NSArray <FLEXTableViewSection *> *)makeSections {
141+ __weak __typeof (self) weakSelf = self;
141142 _logMessages = [FLEXMutableListSection list: @[]
142143 cellConfiguration: ^(FLEXSystemLogCell *cell, FLEXSystemLogMessage *message, NSInteger row) {
143- cell.logMessage = message;
144- cell.highlightedText = self.filterText ;
145-
146- if (row % 2 == 0 ) {
147- cell.backgroundColor = FLEXColor.primaryBackgroundColor ;
148- } else {
149- cell.backgroundColor = FLEXColor.secondaryBackgroundColor ;
144+ __strong __typeof (self) strongSelf = weakSelf;
145+ if (strongSelf) {
146+ cell.logMessage = message;
147+ cell.highlightedText = strongSelf.filterText ;
148+
149+ if (row % 2 == 0 ) {
150+ cell.backgroundColor = FLEXColor.primaryBackgroundColor ;
151+ } else {
152+ cell.backgroundColor = FLEXColor.secondaryBackgroundColor ;
153+ }
150154 }
151155 } filterMatcher: ^BOOL (NSString *filterText, FLEXSystemLogMessage *message) {
152156 NSString *displayedText = [FLEXSystemLogCell displayedTextForLogMessage: message];
153157 return [displayedText localizedCaseInsensitiveContainsString: filterText];
154158 }
155159 ];
156-
160+
157161 self.logMessages .cellRegistrationMapping = @{
158162 kFLEXSystemLogCellIdentifier : [FLEXSystemLogCell class ]
159163 };
160-
164+
161165 return @[self .logMessages];
162166}
163167
@@ -198,27 +202,27 @@ - (void)showLogSettings {
198202
199203 NSString *aslToggle = disableOSLog ? @" Enable os_log (default)" : @" Disable os_log" ;
200204 NSString *persistence = persistent ? @" Disable persistent logging" : @" Enable persistent logging" ;
201-
205+
202206 NSString *title = @" System Log Settings" ;
203207 NSString *body = @" In iOS 10 and up, ASL has been replaced by os_log. "
204208 " The os_log API is much more limited. Below, you can opt-into the old behavior "
205209 " if you want cleaner, more reliable logs within FLEX, but this will break "
206210 " anything that expects os_log to be working, such as Console.app. "
207211 " This setting requires the app to restart to take effect. \n\n "
208-
212+
209213 " To get as close to the old behavior as possible with os_log enabled, logs must "
210214 " be collected manually at launch and stored. This setting has no effect "
211215 " on iOS 9 and below, or if os_log is disabled. "
212216 " You should only enable persistent logging when you need it." ;
213-
217+
214218 FLEXOSLogController *logController = (FLEXOSLogController *)self.logController ;
215-
219+
216220 [FLEXAlert makeAlert: ^(FLEXAlert *make) {
217221 make.title (title).message (body);
218222 make.button (aslToggle).destructiveStyle ().handler (^(NSArray <NSString *> *strings) {
219223 [defaults toggleBoolForKey: kFLEXDefaultsDisableOSLogForceASLKey ];
220224 });
221-
225+
222226 make.button (persistence).handler (^(NSArray <NSString *> *strings) {
223227 [defaults toggleBoolForKey: kFLEXDefaultsiOSPersistentOSLogKey ];
224228 logController.persistent = !persistent;
0 commit comments