Objective-C

RSS for tag

Objective-C is a programming language for writing iOS, iPad OS, and macOS apps.

Posts under Objective-C tag

200 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

No member in framework target: Swift class as forward class in ObjC, accessed in Swift through ObjC class
So I am creating an ObjC framework which has mix of ObjC and Swift code: UtilitiesFramework. Here is my StringUtilities class in Swift: @objc public class StringUtilities: NSObject { } I am accessing StringUtilities class in Utilities which is an ObjC class. Here is Utilities.h which is returning StringUtilities and has a forward class declaration for same: @class StringUtilities; // Forward Declaration @interface Utilities: NSObject - (StringUtilities *)stringUtilities; @end Here is Utilities.m which imports generated swift header file: #import <UtilitiesFramework/UtilitiesFramework-Swift.h> // This should provide concrete implementation of StringUtilities @implementation Utilities - (StringUtilities *)stringUtilities { return [StringUtilities new]; } @end I am exposing Utilites.h file to Swift through module.modulemap: module PrivateObjC { header "Utilities.h" } I have set the import path accurately in build settings as: $(SRCROOT)/$(PRODUCT_NAME) Now when I try to access Utilities class in some other swift class it just compiles fine: import PrivateObjC class SomeOperations { func doSomething() { _ = Utilities() // This compiles fine } However when I try to access the StringUtilities through its method, it gives compilation error: import PrivateObjC class SomeOperations { func doSomething() { _ = Utilities().stringUtilities() // This gives compilation error } Here are the errors: value of type Utilities has no member stringUtilities: _ = Utilities().stringUtilities() note: method stringUtilities not imported - (StringUtilities *)stringUtilities ^ note: return type not imported - (StringUtilities *)stringUtilities ^ note: interface StringUtilities is incomplete - (StringUtilities *)stringUtilities ^ note: interface StringUtilites forward declared here @class StringUtilities I thought this scenario is fixed as part of proposal: # 0384-importing-forward-declared-objc-interfaces-and-protocols.md However it is not working for me. May be it is due to it being approved as part of Swift 5.9, whereas in my machine 5.8.1 is used or am I missing anything else over here? Update: I installed Xcode 15 and double checked the swift version which is 5.9, however I am still getting the error. Any idea why it is not working for a framework target?
0
0
296
Dec ’23
Memory management issue while Call Obj-C in Swift
I'm currently developing a native plugin for a Capcitor app. I have very little experience with native iOS development, Swift and Obj-C. I use a framework (FunSDK) which is written in C++. I call this in an Objective-C++ wrapper. As described here: https://medium.com/@cecilia.humlelu/set-up-c-library-dependencies-in-swift-projects-5dc2ccd2ddaf The wrapper is then available in Swift via the bridging header. This works so far, I can call the functions from the framework and they are executed correctly. However, the functions of the framework are executed asynchronously. When a result is obtained, the “OnFunSDKResult” method is always executed. During this step I get an EXC_BAD_ACCESS error while debugging. Then I ticked “Zombie objects” under the diagnostics settings. This causes execution to stop with an EXC_BREAKPOINT. As I understand it, after executing the iniXMSDK method, the FunSDKWrapper class is cleared from memory before executing the "OnFunSDKResult" method? I have also already integrated a completionHandler, which is only called in the "OnFunSDKResult" method so that data is transferred to the Swift class. However, that doesn't help either. I have no idea how to proceed. I hope somebody can help me. If you need any more information, I would be happy to provide it. The FunSDKWrapper.mm // // FunSDKWrapper.m // App // // Created by Sysprobs on 12/8/23. // #import "FunSDKWrapper.h" #import "FunSDK/FunSDK.h" #import <XMNetInterface/Reachability.h> @implementation FunSDKWrapper -(NSString *)iniXMSDK:(int)test completion:(void (^)(int result))completionHandler{ self.initCompletionHandler = completionHandler; self.msgHandle = FUN_RegWnd((__bridge void *)self); FUN_Init(); Fun_LogInit(self.msgHandle, "", 0, "", LOG_UI_MSG); FUN_XMCloundPlatformInit("***", "***", "***", 1); FUN_InitNetSDK(); FUN_SetFunStrAttr(EFUN_ATTR_SAVE_LOGIN_USER_INFO,SZSTR([self GetDocumentPathWith:@"UserInfo.db"])); FUN_SetFunStrAttr(EFUN_ATTR_USER_PWD_DB, SZSTR([self GetDocumentPathWith:@"password.txt"])); FUN_SetFunStrAttr(EFUN_ATTR_UPDATE_FILE_PATH,SZSTR([self GetDocumentPathWith:@""])); FUN_SetFunStrAttr(EFUN_ATTR_TEMP_FILES_PATH,SZSTR([self GetDocumentPathWith:@""])); FUN_SetFunIntAttr(EFUN_ATTR_AUTO_DL_UPGRADE, 0); FUN_SetFunStrAttr(EFUN_ATTR_CONFIG_PATH,SZSTR([self GetDocumentPathWith:@"APPConfigs"])); FUN_SetFunIntAttr(EFUN_ATTR_SUP_RPS_VIDEO_DEFAULT, 1); FUN_SetFunIntAttr(EFUN_ATTR_SET_NET_TYPE, [self getNetworkType]); FUN_SysInit("arsp.xmeye.net;arsp1.xmeye.net;arsp2.xmeye.net", 15010); FUN_InitNetSDK(); FUN_SysGetDevList(self.msgHandle, SZSTR(@"xxxx") , SZSTR(@"xxxx"),0); return @"test"; } - (void)searchLanDevices { FUN_DevSearchDevice(self.msgHandle, 4000, 0); } // NSDocument/fileName - (NSString *)GetDocumentPathWith:(NSString *) fileName { NSString* path = [self documentsPath]; if (fileName != nil) { path = [path stringByAppendingString:@"/"]; path = [path stringByAppendingString:fileName]; } return path; } //NSDocument - (NSString *)documentsPath { NSArray *pathArray = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *path = [pathArray lastObject]; return path; } -(int)getNetworkType { Reachability*reach=[Reachability reachabilityWithHostName:@"www.apple.com"]; //判断当前的网络状态 switch([reach currentReachabilityStatus]){ case ReachableViaWiFi: return 1; case ReachableViaWWAN: return 2; default: return 0; break; } } - (void)OnFunSDKResult:(NSNumber *) pParam { NSInteger nAddr = [pParam integerValue]; MsgContent *msg = (MsgContent *)nAddr; switch (msg->id) { case EMSG_SYS_GET_DEV_INFO_BY_USER:{ self.initCompletionHandler(1); if (msg->param1 < 0){ //fehler NSLog(@"Fehler beim XMCloud login"); }else{ char devJson[750*500]; FUN_GetFunStrAttr(EFUN_ATTR_GET_USER_ACCOUNT_DATA_INFO, devJson, 750*500); NSLog(@"Geraeteliste: = %s",devJson); } } break; } } @end The Swift Class import Foundation import Capacitor /** * Please read the Capacitor iOS Plugin Development Guide * here: https://capacitorjs.com/docs/plugins/ios */ @objc(xmsdkPlugin) public class xmsdkPlugin: CAPPlugin { private let implementation = xmsdk() @objc func echo(_ call: CAPPluginCall) { let value = call.getString("value") ?? "" call.resolve([ "value": implementation.echo(value) ]) } @objc func initXMSDK(_ call: CAPPluginCall) { //let devId = call.getString("devId") ?? "" let wrapper = FunSDKWrapper(); let resp = wrapper.iniXMSDK(1, completion: {(result) -> Void in NSLog("Completion von iniXMSDK") }); call.resolve([ "status": resp ]) } } Errorlog with EXC_BREAKPOINT:
1
0
327
Dec ’23
Simple scriptable macOS Xcode Swift App example please
Does anyone have a simple example for a scriptable App in Swift in Xcode for macOS? I mean one that exposes objects and functions to applescript? I've checked all examples that I could find. But for me they get me confused about whether they are accessing the actual and already existing instance of a class or whether they are creating an instance with AppleScript, or just using the class definition to call some function. Also the way they are defined in the .sdef file does not help. It would be great if someone had a really simple example, stripped down to bare minimum that 1) defines a class with a single function, 2) creates an instance of the class inside appDelegate and then 3) the function of the specific instance is called using appleScript. 4) It would be great if the function could do something in the GUI, such as change a text of a Label.
0
0
520
Dec ’23
Environment variable not working in another user account
I have the following in my .zshrc: export MY_LIBRARY_DIR=~/bin In Xcode I can set header/lib search path using something like $(MY_LIBRARY_DIR)/abc. This works fine in my daily used user account. But today I found that this technique does not work in a test user account (for testing purpose only). I even reboot my machine but still can't get it working. Am I missing something very obvious??? BTW, I am using Xcode 14.2 and 14.3.1.
1
0
443
Dec ’23
*** Assertion failure in -[_UISystemBackgroundView _internalSubviewsOfType:], _UISystemBackgroundView.m:133
Our application was working fine in iOS 16, but after upgrading to iOS 17.1.1, we see a 100% reproducible crash when generating a cell in the [UITableViewDataSource tableView: cellForRowAtIndexPath:] callback for a particular table. I've only found a single table so far where it crashes. This is the line of code where it crashes: ItemContentTableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier forIndexPath:indexPath]; The crash occurs on the first call. Since it only crashes in this one table, I imagine it's somehow related to the particulars of the cell content layout, but as far as I can see, there's nothing spectacular going on there. Any ideas?? Thanks.
4
0
541
Dec ’23
openpty && security server
hi, I am using the openpty function in my code to run an interactive command, for example, "hdiutil convert -format UDRO /tmp/myFileName.sparsebundle -o ./test". The file myFileName.sparsebundle is an encrypted disk with a password. When running this command, it triggers the security server and a password input dialog box pops up. I don't want this dialog box to appear, and I want to provide the password through the fd_master returned by openpty. How can I achieve this?
1
0
447
Dec ’23
TLS1.3 connection Restriction
I created one application using Websocket when TLS version was 1.2 connection establishment working fine but when server team update TLS1.2 to TLS1.3 due to security enhancement in my project i am getting SSL Handshake fails with code 9836. and NSOSStatusErrorDomain with code 9836. here is my info.plist NSAppTransportSecurity NSAllowsArbitraryLoads NSExceptionDomains myserver.com NSIncludesSubdomains NSExceptionMinimumTLSVersion TLSv1.3 So my query here is that even if we specify TLSv1.3 for myserver.com as: NSExceptionMinimumTLSVersion TLSv1.3 we want to restrict only to TLS1.3, even if my request fails, how to achieve this?
1
0
383
Dec ’23
EXC_BREAKPOINT (SIGTRAP) on Mac arm64?
I received a crash dump from an ARM64 Mac. I see my code here but from what I can tell it looks like this "crash" occurred during cleanup/quit. One thing that caught my eye here is the symbol __A_WATCHDOG_TIMEOUT_HAS_OCCURRED__ that shows up just before exit. Does this mean the watchdog timeout initiated exit? Can I determine why? Crashed Thread: 13 Exception Type: EXC_BREAKPOINT (SIGTRAP) Exception Codes: 0x0000000000000001, 0x000000019c61427c Termination Reason: Namespace SIGNAL, Code 5 Trace/BPT trap: 5 Terminating Process: exc handler [60432] ... Thread 13 Crashed: 0 FrontBoardServices 0x000000019c61427c -[FBSMainRunLoopSerialQueue assertBarrierOnQueue] + 144 (FBSSerialQueue.m:264) 1 FrontBoardServices 0x000000019c5ca91c -[FBSScene detachLayer:] + 44 (FBSScene.m:222) 2 UIKitCore 0x00000001b59c0538 -[_UIFBSSceneSubstrate detachContext:] + 92 (_UIFBSSceneSubstrate.m:74) 3 UIKitCore 0x00000001b5569168 __UIContextBinderDetachContext + 240 (_UIContextBinder.m:367) 4 UIKitCore 0x00000001b5569014 -[_UIContextBinder detachBindable:] + 192 (_UIContextBinder.m:149) 5 UIKitCore 0x00000001b5568ed0 -[UIWindowScene _windowUpdatedVisibility:] + 84 (UIWindowScene.m:1162) 6 UIKitCore 0x00000001b5568d38 -[UIWindow _updateLayerOrderingAndSetLayerHidden:actionBlock:] + 192 (UIWindow.m:2330) 7 UIKitCore 0x00000001b55b9ae8 -[UIWindow _setHidden:forced:] + 104 (UIWindow.m:2556) 8 SDL2 0x00000001026ccb6c 0x102660000 + 445292 9 SDL2 0x0000000102713828 SDL_DestroyWindow + 164 10 My App 0x0000000102073890 cleanup + 60 (init.c:129) 11 libsystem_c.dylib 0x0000000186ddcfa8 __cxa_finalize_ranges + 492 (atexit.c:292) 12 libsystem_c.dylib 0x0000000186ddcd20 exit + 44 (exit.c:78) 13 UIKitMacHelper 0x000000019fbb60ec __A_WATCHDOG_TIMEOUT_HAS_OCCURRED__ + 192 (UINSLifecycleWatchdog.m:35) 14 UIKitMacHelper 0x000000019fbb487c __60-[UINSLifecycleWatchdog initWithStateIdentifier:andTimeout:]_block_invoke + 1160 (UINSLifecycleWatchdog.m:77) 15 UIKitMacHelper 0x000000019fbb5828 run_watchdog_thread + 276 (UINSLifecycleWatchdog.m:305) 16 libsystem_pthread.dylib 0x0000000186f1d034 _pthread_start + 136 (pthread.c:904) 17 libsystem_pthread.dylib 0x0000000186f17e3c thread_start + 8 (:-1)
1
0
606
Dec ’23
How read image file metadata?
I want to read metadata of image files such as copyright, author etc. I did a web search and the closest thing is CGImageSourceCopyPropertiesAtIndex: - (void)tableViewSelectionDidChange:(NSNotification *)notif { NSDictionary* metadata = [[NSDictionary alloc] init]; //get selected item NSString* rowData = [fileList objectAtIndex:[tblFileList selectedRow]]; //set path to file selected NSString* filePath = [NSString stringWithFormat:@"%@/%@", objPath, rowData]; //declare a file manager NSFileManager* fileManager = [[NSFileManager alloc] init]; //check to see if the file exists if ([fileManager fileExistsAtPath:filePath] == YES) { //escape all the garbage in the string NSString *percentEscapedString = (NSString *)CFURLCreateStringByAddingPercentEscapes(NULL, (CFStringRef)filePath, NULL, NULL, kCFStringEncodingUTF8); //convert path to NSURL NSURL* filePathURL = [[NSURL alloc] initFileURLWithPath:percentEscapedString]; NSError* error; NSLog(@"%@", [filePathURL checkResourceIsReachableAndReturnError:error]); //declare a cg source reference CGImageSourceRef sourceRef; //set the cg source references to the image by passign its url path sourceRef = CGImageSourceCreateWithURL((CFURLRef)filePathURL, NULL); //set a dictionary with the image metadata from the source reference metadata = (NSDictionary *)CGImageSourceCopyPropertiesAtIndex(sourceRef,0,NULL); NSLog(@"%@", metadata); [filePathURL release]; } else { [self showAlert:@"I cannot find this file."]; } [fileManager release]; } Is there any better or easy approach than this?
1
0
621
Dec ’23
Digital signature to PDF file on Swift/Objective-C
Hi there, Currently, I'm assigned to do the task that allow user can sign their digital signature on iPhone. I've researched for a week and so far, I'm lost on my way. I want to ask your all experience in working the similar task. My demand is: Allow users upload PDF document Then, allow users sign their digital signature Please give me a logic, step and how it works programmatically to research, in order to do this task. Thank you all <3
1
0
341
Dec ’23
Accessibility permission corrupted AXWebArea not found
I have an application that uses Accessibility APIs to determine if a browser tab with website content is present by checking for the AXWebArea role element. However, some users have reported that the app is not working after a recent update. When I check for permission using the following code, the result is YES, but the app still cannot detect the AXWebArea element in the browser though other elements like AXButton were there: NSDictionary *options = @{(__bridge id)kAXTrustedCheckOptionPrompt : @YES}; NSLog(@“%d”, AXIsProcessTrustedWithOptions((__bridge CFDictionaryRef)options)); The issue is resolved when the app is removed and re-added to the Accessibility permissions list in the System settings. I would appreciate a detailed explanation of what could be causing this issue.
1
1
768
Dec ’23
Could not find a navigation controller for segue. Random Crash for years now...
I've been seeing this crash happening for a few years now. It's rare and unreproducible. The App's storyboard is large and it can occur on any segue and randomly it seems Could not find a navigation controller for segue 'some-segue-on-storyboard'. Push segues can only be used when the source controller is managed by an instance of UINavigationController. I've tried various things to prevent it. Double checked it was on the main thread to keep the UI happy and assumed all this time that it was just an iOS glitch/bug that Apple would get around to fixing. That or it is a side effect of low memory. Anyone got any suggestions for how to fix or what to investigate?
5
0
845
Nov ’23
macOS 14 - NSAttributedString created from HTML displays as "undefined character" glyphs when certain fonts are used
I allow users to choose a font to use throughout the app, then display text using that font in 3 different ways: As the default body font of an HTML document displayed in a WKWebView. Used to create an NSAttributedString then displayed in an NSTextField. Used as the body font of a very small HTML document (2-3 lines), converted to NSAttributedString, then displayed in an NSTextField. My code has been working fine for years, but starting with the release of Sonoma (macOS 14), any text that is converted from HTML to NSAttributedString displays as all "question marks in boxes" for each character. This happens when certain fonts are used. In particular I've seen it with Calibri, Candara, and SF Pro. Calibri and Candara are Microsoft fonts and I think are distributed with MS Office. SF Pro is an Apple font. There could be others; I haven't done an exhaustive check. What I can tell you is that this has been working fine literally until a couple weeks ago when customers began installing macOS 14. If they go into my app and select a different font (such as Arial or Times New Roman) everything works fine. It is only certain fonts that don't work, and those fonts work when used as the body font of an HTML document in WKWebView and when used as the font for a new NSAttributedString. They just don't work if you make a little HTML document with the font selected as the body font, then convert to NSAttributedString. Here's the code that worked up until macOS 14: NSString *htmlString = @"&amp;lt;!DOCTYPE html&amp;gt;" "&amp;lt;html&amp;gt;" "&amp;lt;head&amp;gt;" "&amp;lt;style&amp;gt;" "body { font-family: 'Candara', serif; font-size: 14px; }" "&amp;lt;/style&amp;gt;" "&amp;lt;/head&amp;gt;" "&amp;lt;body&amp;gt;" "This won't display right." "&amp;lt;/body&amp;gt;" "&amp;lt;/html&amp;gt;"; NSData *htmlData = [htmlString dataUsingEncoding:NSUTF8StringEncoding]; NSDictionary *options = @{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: @(NSUTF8StringEncoding)}; NSError *error; NSAttributedString *attributedString = [[NSAttributedString alloc] initWithData:htmlData options:options documentAttributes:nil error:&amp;amp;error]; Note the fallback of "serif" — that doesn't matter. you get all undefined characters and the fallback font is not used. It's as if the renderer really believes the font is usable, but it isn't.
1
0
618
Nov ’23
Download content of public.file-url when Finder does the paste action
Hello, Is it possible fill NSpastebard with public.file-url which will initially point the an empty file. And when Finder will paste the file, my Application will download it and Finder will wait for the completion of the download. My goal is not to use drag &amp; drop. I saw that Microsoft RDP client is doing file download using this way. But I don't know how it works. Empty file is created in sandbox.
2
0
295
Nov ’23
Weird problem of NSTableView with auto layout
I have had this issue for a long time. If I configure any auto layout constraints in TableViewCell, I get extremely weird layout behavior in IB designer; however, layout is completely good during runtime. For example, with a completely new project and a single NSTableView on the main view, I get: If I resize main view, the tableview won't get resized Every time I reopen the project, the tableview would shrink by height. It seems the shrinked height is doubled every time. For example, in the following screenshot, the gap is 56. Next reopen will double the gap to 112. Is this a known bug? I would want to file bug report at https://feedbackassistant.apple.com.
1
1
469
Nov ’23