Frameworks

RSS for tag

Ask questions about APIs that can drive features in your apps.

Posts under Frameworks tag

200 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

Obtaining CPU usage by process
Hi there, I'm working on an app that contains a mini system monitoring utility. I would like to list the top CPU-using processes. As Quinn “The Eskimo!” has repeatedly cautioned, relying on private frameworks is just begging for maintenance effort in the future. Ideally, I want to go through public headers/frameworks. I've gone to great lengths to try to find this information myself, and at this point I'm just struggling. I detail my research below. Any pointers in the right direction would be much appreciated! Attempts Libproc First I looked at libproc. Using proc_pidinfo with PROC_PIDTHREADINFO, I'm able to get each thread of an app, with its associated CPU usage percentage. Summing these, I could get the total for an app. Unfortunately, this has two downsides: Listing a table of processes now takes O(proces_count) rather than just O(process_count), and causes way more syscalls to be made It doesn't work for processes owned by other users. Perhaps running as root could alleviate that, but that would involve making a priviliedged helper akin to the existing sysmond that Activity Monitor.app uses. I'm a little scared of that, because I don't want to put my users at risk. Sysctl Using the keys [CTL_KERN, KERN_PROC, KERN_PROC_PID, someProcessID], I'm able to get a kinfo_proc - https://github.com/apple-opensource/xnu/blob/24525736ba5b8a67ce3a8a017ced469abe101ad5/bsd/sys/sysctl.h#L750-L776 instance. Accessing its .kp_proc - https://github.com/apple-opensource/xnu/blob/24525736ba5b8a67ce3a8a017ced469abe101ad5/bsd/sys/proc.h#L96-L150.p_pctcpu - https://github.com/apple-opensource/xnu/blob/24525736ba5b8a67ce3a8a017ced469abe101ad5/bsd/sys/proc.h#L123 looked really promising, but that value is always zero. Digging deeper, I found the kernel code that fills this struct in (fill_user64_externproc - https://github.com/apple-opensource/xnu/blob/c76cff20e09b8d61688d1c3dfb8cc855cccb93ad/bsd/kern/kern_sysctl.c#L1121-L1168). The assignment of p_pctcpu - https://github.com/apple-opensource/xnu/blob/c76cff20e09b8d61688d1c3dfb8cc855cccb93ad/bsd/kern/kern_sysctl.c#L1149 is in a conditional region, relying on the _PROC_HAS_SCHEDINFO_ flag. Disassembling the kernel on my mac, I could confirm that the assignment of that field never happens (thus _PROC_HAS_SCHEDINFO_ wasn't set during compilation, and the value will always stay zero) Reverse engineering Activity Monitor.app Activity Monitor.app makes proc_info and sysctl system calls, but from looking at the disassembly, it doesn't look like that's where its CPU figures come from. From what I can tell, it's using private functions from /usr/lib/libsysmon.dylib. That's a user library which wraps an XPC connection to sysmond (/usr/libexec/sysmond), allowing you to create requests (sysmon_request_create), add specific attributes you want to retrieve (sysmon_request_add_attribute), and then functions to query that data out (sysmon_row_get_value). Getting the data "striaght from the horses mouth" like this sounds ideal. But unfortunately, the only documentation/usage I can find of sysmond is from bug databases demonstrating a privilege escalation vulnerability lol. There are some partial reverse engineered header files floating around, but they're incomplete, and have the usual fragility/upkeep issues associated with using private APIs. On one hand, I don't want to depend on a private API, because that takes a lot of time to reverse engineer, keep up with changes, etc. On the other, making my own similar privileged helper would be duplicating effort, and expose a bigger attack surface. Needless to say, I have no confidence in being able to make a safer privileged helper than Apple's engineers lol Reverse engineering iStat Menus Looks like they're using proc_pid_rusage - https://github.com/apple-opensource/xnu/blob/24525736ba5b8a67ce3a8a017ced469abe101ad5/libsyscall/wrappers/libproc/libproc.h#L103-L108 . However, I don't know how to convert the cpu_*_time fields of the resulting struct rusage_info_v4 - https://github.com/apple-opensource/xnu/blob/24525736ba5b8a67ce3a8a017ced469abe101ad5/bsd/sys/resource.h#L306-L343 to compute a "simple" percentage. Even if I came up with some formula that produces plausible looking results, I have no real guarantee it's correct or equivalent to what Activity Monitor shows.
5
1
4.8k
Mar ’24
Why isn't an XCFramework's Info.plist "stable"?
(By "stable," I don't mean in a crashing or breaking sense; I mean it in the sense of a stable sorting algorithm, where duplicate elements will be kept in the same order in which they appeared in the unsorted collection.) I have a script that builds an XCFramework for iOS & tvOS, on simulator & device. It never changes the order in which the -framework arguments are passed to xcodebuild -create-xcframework. If I regenerate the XCFramework without any code or config changes, however, the order of entries in Info.plist always changes. Sample git diff: <string>x86_64</string> </array> <key>SupportedPlatform</key> - <string>tvos</string> + <string>ios</string> <key>SupportedPlatformVariant</key> <string>simulator</string> </dict> <dict> <key>LibraryIdentifier</key> - <string>ios-x86_64-simulator</string> + <string>ios-arm64</string> <key>LibraryPath</key> <string>Foo.framework</string> <key>SupportedArchitectures</key> <array> - <string>x86_64</string> + <string>arm64</string> </array> <key>SupportedPlatform</key> <string>ios</string> - <key>SupportedPlatformVariant</key> - <string>simulator</string> </dict> <dict> <key>LibraryIdentifier</key> - <string>ios-arm64</string> + <string>tvos-x86_64-simulator</string> <key>LibraryPath</key> <string>Foo.framework</string> <key>SupportedArchitectures</key> <array> - <string>arm64</string> + <string>x86_64</string> </array> <key>SupportedPlatform</key> - <string>ios</string> + <string>tvos</string> + <key>SupportedPlatformVariant</key> + <string>simulator</string> </dict> </array> <key>CFBundlePackageType</key> It doesn't affect the runtime in any way, as far as I know, but it's a minor irritation that I have to commit the changes to source control every time. Is there a way for xcodebuild -create-xcframework to either honor the order in which I passed the -framework arguments in, or at least keep the Info.plist file "stable" between script invocations? (This behavior is the same on Xcode 12.x & the XCode 13 beta versions.)
1
1
1.5k
Oct ’23
Xcode 13 app archiving is modifying framework plist
When archiving & exporting App with Xcode 13. The Frameworks of the created app will have their Info.plist modified. CFBundleShortVersionString is being changed to have the same value as the application version. Steps to reproduce: Create iOS App project with v1.0.0 Add dynamic framework dependencies. ex: Framework A v3.0.0, Framework B v12.0.0. Archive Project. Distribute app AppStore Connect Export Finish the rest of the process with default values. Investigate generated IPA file Investigate .app file inside IPA Investigate frameworks inside .app file. CFBundleShortVersionString of all the frameworks is 1.0.0
12
3
18k
May ’24
Impact of Disable Generate Debug Symbols
Hello there, i would like to ask a question related xcode build confinguration. So i have create a Common.framework that i used in other project, because of the .framework file is quite large then i want to generate Common.framework but with Generate Debug Symbols is NO, and the result Common.framework size is reduced The question is there any negative impact that will happen to my app that use Common.framework?
2
0
2.3k
Jan ’24
"Invalid Bundle. The bundle <bundle name> does not support the minimum OS Version specified in the Info.plist"
I have been working with a framework to add multiplayer support to my app. The app runs on test devices, simulators, and archives perfectly fine and the app is fine without the framework. But when I go to distribute the app, I see get this error related to the multiplayer framework I have added. I have tried updating the minimumOSVersion to 9.0, 10.0, 12.0, and 13.0 everywhere (info.plist, deployment info, build settings, etc) and they all match with each build/archive but no matter what I can't get fix this error. This error only shows up when I go to distribute the app to the store. Any ideas on what to try or how to fix this issue? I've attached a screenshot of the issue below.
10
3
12k
May ’24
Upgrade from xCode 14.2 to 14.3 PhaseScriptExecution failed with a nonzero exit code
Hello, I've upgraded from xcode 14.2 to xcode 14.3 beta, and now I can't archive anymore for Any iOS Device (arm64) with the following error : PhaseScriptExecution [CP]\ Embed\ Pods\ Frameworks mkdir -p /Users/max/Library/Developer/Xcode/DerivedData/Max-dmwafkgdrzqavzcmbdjbjgmmuxby/Build/Intermediates.noindex/ArchiveIntermediates/Release_preprod/BuildProductsPath/Release_preprod-iphoneos/MaxApp.app/Frameworks Symlinked... rsync --delete -av --filter P .*.?????? --links --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "../../../IntermediateBuildFilesPath/UninstalledProducts/iphoneos/ActionSheetPicker_3_0.framework" "/Users/max/Library/Developer/Xcode/DerivedData/Max-dmwafkgdrzqavzcmbdjbjgmmuxby/Build/Intermediates.noindex/ArchiveIntermediates/Release_preprod/InstallationBuildProductsLocation/Applications/MaxApp.app/Frameworks" building file list ... rsync: link_stat "/Users/max/Workspace/MaxApp/../../../IntermediateBuildFilesPath/UninstalledProducts/iphoneos/ActionSheetPicker_3_0.framework" failed: No such file or directory (2) done sent 29 bytes received 20 bytes 98.00 bytes/sec total size is 0 speedup is 0.00 rsync error: some files could not be transferred (code 23) at /AppleInternal/Library/BuildRoots/9e200cfa-7d96-11ed-886f-a23c4f261b56/Library/Caches/com.apple.xbs/Sources/rsync/rsync/main.c(996) [sender=2.6.9] Command PhaseScriptExecution failed with a nonzero exit code Any idea why it works fine with xCode 14.2 and not with xCode 14.3 beta please ? I tryed to delete the [CP] Embed Pods Frameworks script, but it has re-created it and get the same issue. I tryed to build and debug in a simulator, and it works fine. I tryed to delete "EXCLUDED_ARCHS[sdk=iphonesimulator*]" = arm64; in the .pbxproj file
58
33
87k
Jul ’23
How to import FBX SDK into my Swift project?
Hello everyone, I want to add FBX capabilities to my app so I downloaded and installed the FBX SDK for iOS from the Autodesk website. But when it came to setting up the sdk for my Xcode project, the only article I could find was from 2014 and the guide is outdated and doesn't work anymore. I do not know a lot about c or working with frameworks/APIs, so I need some help getting this set up... Thanks for any help in advance!
1
0
1k
Jan ’24
IOPSCopyPowerSourcesInfo → kIOPSBatteryHealthKey returning incorrect value
IOPSCopyPowerSourcesInfo → kIOPSBatteryHealthKey returning incorrect value Background: I write software to monitor computer system health. I'm having problems getting battery health information on my new M2 notebook. Given the following Objective-C program: #include <Foundation/NSObjCRuntime.h> #include <IOKit/ps/IOPSKeys.h> #include <IOKit/ps/IOPowerSources.h> #include <assert.h> int main() { CFTypeRef psInfo = IOPSCopyPowerSourcesInfo(); assert(psInfo != NULL); CFArrayRef list = IOPSCopyPowerSourcesList(psInfo); assert(list != NULL); long count = CFArrayGetCount(list); for(long i = 0; i < count; i++) { CFDictionaryRef ps = IOPSGetPowerSourceDescription( psInfo, CFArrayGetValueAtIndex(list, i)); assert(ps != NULL); CFStringRef deviceName = (CFStringRef)CFDictionaryGetValue( ps, CFSTR(kIOPSNameKey)); assert(deviceName != NULL); CFStringRef serialNumber = (CFStringRef)CFDictionaryGetValue( ps, CFSTR(kIOPSHardwareSerialNumberKey)); assert(serialNumber != NULL); CFStringRef health = (CFStringRef)CFDictionaryGetValue( ps, CFSTR(kIOPSBatteryHealthKey)); assert(health != NULL); NSLog(@"\nName=\"%@\"\nSerialNumber=\"%@\"\n" "BatteryHealth=\"%@\"\n", (__bridge NSString*)deviceName, (__bridge NSString*)serialNumber, (__bridge NSString*)health); } CFRelease(list); CFRelease(psInfo); return 0; } and looking at the IOPSKeys.h header, I expect to get one of "Poor", "Fair", or "Good" for the value of kIOPSBatteryHealthKey. https://opensource.apple.com/source/IOKitUser/IOKitUser-1845.81.1/ps.subproj/IOPSKeys.h.auto.html Instead, on my 2022 M2 Macbook Air running 13.2.1 (22D68), I get the following output: Name="InternalBattery-0" SerialNumber="F8Y2422145S10X2A7" BatteryHealth="Check Battery" At the same time, the "System Information app says "Condition: Normal". Am I missing something? This seems to be a bug, right? Should I look into filing a Technical Support Incident?
2
0
1k
Aug ’23
Resuming a file download in the background on iOS sometimes corrupts the file
To download files, we have two NSURLSession objects. One configured for foreground downloads and one for background downloads. Initially, we download user-requested files in the foreground using downloadTaskWithRequest, because foreground downloads are faster than background downloads. We then also start a background task for each download using beginBackgroundTaskWithName:expirationHandler:. This background task's expiration handler starts a background download if the download didn't complete in the foreground. It cancels the foreground download with resume data using cancelByProducingResumeData. A background download task is then started using downloadTaskWithResumeData. Now, testing has shown that background download tasks resume correctly (the urlSession(_:downloadTask:didResumeAtOffset:expectedTotalBytes:) callback is called by iOS) if the background task is started immediately. However, iOS can decide to start these background download tasks later. As a sidenote, the isDiscretionary property of our background download session is set to the default, which should be false. The issue we have is that background downloads that are resumed several minutes (6,5 minutes in the session I'm currently looking at) after their original foreground download was cancelled, are not resumed properly. They download the remaining part of the file, but the first part that was downloaded in the foreground is lost. What could have happened? Perhaps the temporary file has been deleted in the meantime? Is there some way to maintain this file or detect this case?
6
1
1.1k
Mar ’24
Apple demo code lacking view models
All demo code from Apple that I know lacks view models. Every time model data is directly injected into the view and even modified from the view via the new @Bindable macro. Is Apple not using ViewModels and therefore MVVM at all? I understand it might not really be required for the small demos, but it would still be helpful to understand, e. g. how the new @Model, @Observable, @Binding fit into the MVVM model.
4
0
1.7k
Oct ’23
App Crash at launch -> NO_CRASH_STACK (crash log attached)
App crashes at launch for some of our live users (NOT TESTFLIGHT). I have managed to extract the error log: Incident Identifier: B1F06CCD-4AAB-402F-9909-11FA7E1C54F3 Hardware Model: iPhone14,3 Process: *** [549] Path: /private/var/containers/Bundle/Application/DAE1AAC4-2150-46EF-B7B9-29553EA7346E/***.app/*** Identifier: com.XX.XX Version: 9.0 (70) AppStoreTools: 14E221 AppVariant: 1:iPhone14,3:15 Code Type: ARM-64 (Native) Role: Foreground Parent Process: launchd [1] Coalition: com.XX [580] Date/Time: 2023-06-12 15:59:45.2595 +1000 Launch Time: 2023-06-12 15:59:45.2060 +1000 OS Version: iPhone OS 15.6.1 (19G82) Release Type: User Baseband Version: 1.70.01 Report Version: 104 Exception Type: EXC_CRASH (SIGABRT) Exception Codes: 0x0000000000000000, 0x0000000000000000 Exception Note: EXC_CORPSE_NOTIFY Termination Reason: DYLD 4 Symbol missing Symbol not found: (_objc_claimAutoreleasedReturnValue) Referenced from: '/Volumes/VOLUME/*/***.app/Frameworks/GoogleUtilities.framework/GoogleUtilities' Expected in: '/usr/lib/libobjc.A.dylib' (terminated at launch; ignore backtrace) Triggered by Thread: 0 Thread 0 Crashed: 0 dyld 0x00000001034bcb14 __abort_with_payload + 8 1 dyld 0x00000001034c26cc abort_with_payload_wrapper_internal + 104 (terminate_with_reason.c:102) 2 dyld 0x00000001034c2700 abort_with_payload + 16 (terminate_with_reason.c:124) 3 dyld 0x0000000103492a00 dyld4::halt(char const*) + 580 (DyldProcessConfig.cpp:2102) 4 dyld 0x000000010348fa20 dyld4::prepare(dyld4::APIs&amp;, dyld3::MachOAnalyzer const*) + 3560 (dyldMain.cpp:0) 5 dyld 0x000000010348dd84 start + 488 (dyldMain.cpp:864) Thread 0 crashed with ARM Thread State (64-bit): x0: 0x0000000000000006 x1: 0x0000000000000004 x2: 0x000000016ddc56c8 x3: 0x00000000000000e4 x4: 0x000000016ddc52c8 x5: 0x0000000000000000 x6: 0x0000000000000000 x7: 0x000000016ddc4d40 x8: 0x0000000000000020 x9: 0x0000000000000009 x10: 0x000000016ddc53b8 x11: 0x0000000000000108 x12: 0x0000000000000000 x13: 0x0000000000000035 x14: 0x0000000248f2d99d x15: 0x000000016ddc47e8 x16: 0x0000000000000209 x17: 0x00000001034b71c8 x18: 0x0000000000000000 x19: 0x0000000000000000 x20: 0x000000016ddc52c8 x21: 0x00000000000000e4 x22: 0x000000016ddc56c8 x23: 0x0000000000000004 x24: 0x0000000000000006 x25: 0x000000016ddc52c8 x26: 0x0000000000000400 x27: 0x0000000000000400 x28: 0x00000000000000f0 fp: 0x000000016ddc5290 lr: 0x00000001034c26cc sp: 0x000000016ddc5250 pc: 0x00000001034bcb14 cpsr: 0x1000 esr: 0x56000080 Address size fault Binary Images: 0x103474000 - 0x1034cbfff dyld arm64e &lt;66e1fb2668f8379ba052eb8b8291b5e1&gt; /usr/lib/dyld EOF Any help in fixing this issue with GoogleUtilities.framework/GoogleUtilities will be highly appreciated.
5
1
1.4k
Aug ’23
Error: Command analyse failed with a nonzero exit code.
I am receiving the error as Command analyse failed with a nonzero exit code. It is appearing in the package of RealmDatabase > src > realm > alloc_slab.cpp There is no red highlighted line to identify the error inside that cpp file. I added the package from the GitHub link which is as : https://github.com/realm/realm-swift.git Version: master Name: Realm Attached is the Clang's .ips file for further information Please suggest any possibility. Thanks in advance!
1
0
834
Jul ’23
2 different frameworks uses same framework
Hi All, I created our own framework called Framework A (which has its own Podspec and googlecast as dependency in it). I also created framework B (which has its own Podspec))and framework c (which has its own Podspec))where both uses the Framework A (using the pod). Since googlecast is dependent, it is inside Framework A, Framework B and Framework C I am created the sampleApplication and add Framework A , Framework B and Framework C in the pod file pod filee : pod 'framework A' pod 'Framework B' pod 'Framework C' After pod install, While trying to run thee application I am getting this error Class GCKUICastButton is implemented in both /private/var/containers/Bundle/Application/B4F23931-F41B-45C2-AEFA-4587C81D9474/sampleApp.app/Frameworks/Framework B.framework/framework B (0x108784a28) and /private/var/containers/Bundle/Application/B4F23931-F41B-45C2-AEFA-4587C81D9474/sampleApp.app/Frameworks/Framework C.framework/Framework C (0x1053afb18). One of the two will be used. Which one is undefined. After this Googlecast feature are breaking like cars button icon is disappearing. Please help me in solving this problem
1
1
605
Oct ’23
Cocoapods, Library not loaded
I get this error message : The error is not from algolia but from cocoap or xcode because Algolia is only the first framework in the install list and when I remove it from podfile I get the same error with the second framework. I tried many thing, clean build folder, delete derived data, restart mac, uninstall and reinstall all pod files. I hope someone can help me solve this problem!
0
0
363
Jul ’23
How to handle functions with the same name in multiple libraries
I am creating an application for ios. I include two static libraries in my application. However, if the same function name exists in two static libraries, the function that was first included as a library will be called. (Static library written in Objective-c) Is there any way to solve this? Is it possible to solve it by using framework? Note that the function names of the library are specified by the standard, so the function names cannot be changed. Best regards.
1
0
369
Jul ’23
NEFilterDataProvider.apply cause all tcp connection disconnected once
my content netfilter systemextension is like this: class FilterDataProvider: NEFilterDataProvider { override func startFilter(completionHandler: @escaping (Error?) -> Void) { let ipv4LocalHost = NWHostEndpoint(hostname: "127.0.0.1", port: "0") let ipv4LocalNetworkRule = NENetworkRule(remoteNetwork: ipv4LocalHost, remotePrefix: 0, localNetwork: ipv4LocalHost, localPrefix: 0, protocol: .any, direction: .any) let ipv4LocalFilterRule = NEFilterRule(networkRule: ipv4LocalNetworkRule, action: .filterData) let ipv6LocalHost = NWHostEndpoint(hostname: "::1", port: "0") let ipv6LocalNetworkRule = NENetworkRule(remoteNetwork: ipv6LocalHost, remotePrefix: 0, localNetwork: ipv6LocalHost, localPrefix: 0, protocol: .any, direction: .any) let ipv6LocalFilterRule = NEFilterRule(networkRule: ipv6LocalNetworkRule, action: .filterData) let normalNetworkRule = NENetworkRule(remoteNetwork: nil, remotePrefix: 0, localNetwork: nil, localPrefix: 0, protocol: .any, direction: .any) let normalFilterRule = NEFilterRule(networkRule: normalNetworkRule, action: .filterData) let filterSettings = NEFilterSettings(rules: [ipv4LocalFilterRule, ipv6LocalFilterRule, normalFilterRule], defaultAction: .filterData) apply(filterSettings) { error in completionHandler(error) if error != nil { log.error("Failed to apply filter settings [\(error!)]") } else { log.info("Start content filter successfully.") } } } override func handleNewFlow(_ flow: NEFilterFlow) -> NEFilterNewFlowVerdict { return .allow() } } when startFilter is called, all tcp connections disconnected, but i can connect again.
1
0
378
Aug ’23