Hey guys, I just reproduce the bug
without Realm. It's all about holding
flock in App Group directory. You can follow these steps to quickly reproduce the weird crash:
Create a new iOS App project (Objective-C) using Xcode.
Add an App Group container in project setting page.
Paste this code snippet in application:didFinishLaunchingWithOptions::
Code Block objc // 1. prepare a non-empty file under App Group directory |
NSFileManager* fileManager = [NSFileManager defaultManager]; |
NSURL* dir = [fileManager containerURLForSecurityApplicationGroupIdentifier:@"group.***.***....."]; <= your group id here |
NSURL* fileUrl = [dir URLByAppendingPathComponent:@"file"]; |
[fileManager createFileAtPath:[fileUrl path] |
contents:[@"some data..." dataUsingEncoding:(NSUTF8StringEncoding)] |
attributes:nil]; |
|
// 2. hold a file lock |
int fd = open([fileUrl path].UTF8String, O_RDWR); |
int ret = flock(fd, LOCK_SH); |
4. Debug the project on a
physical device running iOS 14 b3/b4/b5.
5. The app will be killed after you return to home screen.
6. If you unlock the file by calling
flock(fd, LOCK_UN) before the app enters suspended state, the app won't be killed by iOS.
Note that:
This only crash on a physical device, not a simulator.
Xcode does not handle it like a normal crash. It just print a termination message in console and ends the debug session gracefully.