diff --git a/BGSessionFix/.gitignore b/BGSessionFix/.gitignore new file mode 100644 index 0000000..faf8687 --- /dev/null +++ b/BGSessionFix/.gitignore @@ -0,0 +1,3 @@ +.theos/ +packages/ +.DS_Store diff --git a/BGSessionFix/BGSessionFix.plist b/BGSessionFix/BGSessionFix.plist new file mode 100644 index 0000000..84758bd --- /dev/null +++ b/BGSessionFix/BGSessionFix.plist @@ -0,0 +1,7 @@ +{ + Filter = { + Bundles = ( + "app.bundle.id", + ); + }; +} diff --git a/BGSessionFix/Makefile b/BGSessionFix/Makefile new file mode 100644 index 0000000..26a92ff --- /dev/null +++ b/BGSessionFix/Makefile @@ -0,0 +1,14 @@ +TARGET = iphone:latest:15.0 +ARCHS = arm64 +INSTALL_TARGET_PROCESSES = app.bundle.id + +include $(THEOS)/makefiles/common.mk + +TWEAK_NAME = BGSessionFix +BGSessionFix_FILES = Tweak.x +BGSessionFix_CFLAGS = -fobjc-arc -Wno-deprecated-declarations -std=c++11 -x objective-c++ +BGSessionFix_CXXFLAGS = -std=c++11 +BGSessionFix_FRAMEWORKS = Foundation UIKit +BGSessionFix_LDFLAGS = -lstdc++ + +include $(THEOS_MAKE_PATH)/tweak.mk \ No newline at end of file diff --git a/BGSessionFix/Tweak.x b/BGSessionFix/Tweak.x new file mode 100644 index 0000000..2852677 --- /dev/null +++ b/BGSessionFix/Tweak.x @@ -0,0 +1,16 @@ +#import + +%hook NSURLSessionConfiguration + ++ (NSURLSessionConfiguration *)backgroundSessionConfigurationWithIdentifier:(NSString *)identifier { + NSLog(@"[BGSessionFix] Redirecting background session '%@' to a default (foreground) config", identifier); + return [NSURLSessionConfiguration defaultSessionConfiguration]; +} + +// // Deprecated pre-iOS8 entry point +// + (NSURLSessionConfiguration *)backgroundSessionConfiguration:(NSString *)identifier { +// NSLog(@"[BGSessionFix] backgroundSessionConfiguration:'%@' (deprecated API) -> forcing default config", identifier); +// return [NSURLSessionConfiguration defaultSessionConfiguration]; +// } + +%end \ No newline at end of file diff --git a/BGSessionFix/control b/BGSessionFix/control new file mode 100644 index 0000000..bb689b0 --- /dev/null +++ b/BGSessionFix/control @@ -0,0 +1,9 @@ +Package: xyz.nohamr.bgsessionfix +Name: BGSessionFix +Version: 1.0.0 +Architecture: iphoneos-arm +Description: Redirects background NSURLSession configs to foreground configs (Simulator dev use) +Maintainer: NohamR +Author: NohamR +Section: Tweaks +Depends: mobilesubstrate (>= 0.9.5000) diff --git a/BGSessionFix/index.md b/BGSessionFix/index.md new file mode 100644 index 0000000..023ce60 --- /dev/null +++ b/BGSessionFix/index.md @@ -0,0 +1,12 @@ +Tweak that redirects background NSURLSession configurations to foreground (default) configurations, for use when developing/debugging apps in the iOS Simulator. + +The iOS Simulator does not run `nsurlsessiond`, the system daemon that backs `NSURLSession` background transfers. Any app that uses `backgroundSessionConfigurationWithIdentifier:` to download or upload files (so the transfer can survive app suspension/termination on a real device) will fail in the Simulator with errors such as: + +``` +No XPC connection in Simulator +BackgroundSession <...> an error occurred on the xpc connection to setup +the background session: ... connection to service named com.apple.nsurlsessiond +BackgroundSession <...> failed to create a background NSURLSessionDownloadTask, +as remote session is unavailable +Task <...> finished with error [-1] "unknown error" +``` \ No newline at end of file diff --git a/README.md b/README.md index effe76e..98bc310 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,7 @@ iOS tweaks built with [Theos](https://theos.dev), injected into IPAs via [cyan]( | [GPXViewer2](GPXViewer2) | GPXViewer 2 | iOS 14+ | | [RMHook](RMHook/index.md) | reMarkable | iOS | | [HatchDragons](HatchDragons/index.md) | HatchDragons 1.2.1 | iOS 18+ | +| [BGSessionFix](BGSessionFix/index.md) | BGSessionFix | iOS 15+ | ## Build