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

macOS app crashes on first launch from TestFlight
2024_06_09_testflight_launch_crash_log.txt Running my macOS app the first time after installing via TestFlight crashes on launch. Every subsequent run works fine (including completely quitting the app and re-running it). Also, building and running directly in XCode both in Debug and Release mode works fine. I'm on a Mac M2 and the app excludes x86_64 arch. Here is the trimmed crash log (sanitised full log is attached) Crashed Thread: 0 Dispatch queue: com.apple.main-thread Exception Type: EXC_CRASH (SIGABRT) Exception Codes: 0x0000000000000000, 0x0000000000000000 Termination Reason: Namespace SIGNAL, Code 6 Abort trap: 6 Terminating Process: CamHero-macOS-v2-Release [12876] Application Specific Information: abort() called Thread 0 Crashed:: Dispatch queue: com.apple.main-thread 0 libsystem_kernel.dylib 0x18c81d11c __pthread_kill + 8 1 libsystem_pthread.dylib 0x18c854cc0 pthread_kill + 288 2 libsystem_c.dylib 0x18c764a40 abort + 180 3 libglib-2.0.0.dylib 0x1061e5bd0 g_assertion_message + 464 4 libglib-2.0.0.dylib 0x1061e5c44 g_assertion_message_expr + 116 5 libgstlibav.dylib 0x10549ede0 gst_ffmpeg_cfg_init + 776 6 libgstlibav.dylib 0x10548a4f4 plugin_init + 140 7 libgstreamer-1.0.0.dylib 0x10646a458 gst_plugin_register_func + 636 8 libgstreamer-1.0.0.dylib 0x106469fe4 gst_plugin_register_static + 212 9 libgstlibav.dylib 0x10548a45c gst_plugin_libav_register + 92 10 CamHero-macOS-v2-Release 0x104a01624 gst_ios_init + 900 (gst_ios_init.m:1072) 11 CamHero-macOS-v2-Release 0x104a80590 specialized CamHeroMacOSApp.init() + 68 (CamHeroMacOSApp.swift:19) 12 CamHero-macOS-v2-Release 0x104a804a4 CamHeroMacOSApp.init() + 4 [inlined] 13 CamHero-macOS-v2-Release 0x104a804a4 protocol witness for App.init() in conformance CamHeroMacOSApp + 20 (<compiler-generated>:16) 14 SwiftUI 0x1b7f134e0 0x1b7163000 + 14353632 15 CamHero-macOS-v2-Release 0x104a804d8 static CamHeroMacOSApp.$main() + 24 [inlined] 16 CamHero-macOS-v2-Release 0x104a804d8 main + 36 17 dyld 0x18c4d90e0 start + 2360 Thread 1: 0 libsystem_pthread.dylib 0x18c84fe28 start_wqthread + 0 Thread 2: 0 libsystem_pthread.dylib 0x18c84fe28 start_wqthread + 0 Thread 0 crashed with ARM Thread State (64-bit): x0: 0x0000000000000000 x1: 0x0000000000000000 x2: 0x0000000000000000 x3: 0x0000000000000000 x4: 0x0000600000755680 x5: 0x0000000000000020 x6: 0x0000600000755680 x7: 0xffffffff00008600 x8: 0x8ddd1ea266cd729b x9: 0x8ddd1ea3846d2c5b x10: 0x0000000000001620 x11: 0x00000000dbe367fb x12: 0x00000000000007fb x13: 0x00000000000007fd x14: 0x00000000dc03683c x15: 0x000000000000003c x16: 0x0000000000000148 x17: 0x00000001eb9f3da0 x18: 0x0000000000000000 x19: 0x0000000000000006 x20: 0x00000001e2a05ec0 x21: 0x0000000000000103 x22: 0x00000001e2a05fa0 x23: 0x000000016b407508 x24: 0x0000000000000000 x25: 0x00000001064f8450 x26: 0x000060000080d511 x27: 0x0000000000000000 x28: 0x0000000000000000 fp: 0x000000016b407460 lr: 0x000000018c854cc0 sp: 0x000000016b407440 pc: 0x000000018c81d11c cpsr: 0x40001000 far: 0x0000000000000000 esr: 0x56000080 Address size fault It seems that the initialisation of one of the gstreamer plug-ins doesn't go well. But, I wonder what might lead to that happening only the first time after launch? Will appreciate any clues! EDIT / UPDATE: If i remove the app completely and install the same version again from TestFlight, app doesn't crash. So it seems the crashing is limited to the very first launch of a new /updated version.
3
0
402
Jun ’24
Xcode16 Beta Compilation Error: Reserved Keyword 'module' Issue
While compiling with the Xcode Beta1 version, the 'module' keyword used in the previous method as a parameter is now recognized as a reserved keyword, causing compilation errors and preventing our project from continuing to run. Please fix this issue as soon as possible. Additionally, I would like to vent: It's quite uncomfortable that the MacOS Beta version cannot be downgraded directly. I am now facing the dilemma of being unable to open Xcode 15 and having Xcode 16 fail to compile.
4
0
422
Jun ’24
Delete button in default NSSavePanel for new document
I just noticed that when closing a new document with edits in MacOS Sonoma that it skips the Save/Don't Save/Cancel panel and goes directly to default NSSavePanel with Delete/Cancel/Save buttons. The problem is that when I click "Delete" nothing happens. It should have simple solution, but I could not find anything. How does one respond to the "Delete" button? My undocumented (as far as I can tell) hack was to implement document:didSave:contextinfo selector for runModalSavePanelForSaveOperation. It appears that in this method for a new document: Delete button has didSave=YES (even though it did not save) and the document fileURL nil Cancel button has didSave=NO and document fileURL nil Save button has didSave=YES and document filieURL to saved file I can handle Delete button this way, but since it is not a documented method, it make me uncomfortable. For example what happens is user clicks "Save", but the save has an error? As an aside, since Apple is now working with ChatGPT, I thought it might provide some help. I asked it how I can respond to "Delete" button in MacOS Sonoma and it said to implement deleteDocument: in your NSDocument subclass. I pointed out to ChatGPT that deleteDocument: does not exist. It said "you are correct" and you should instead check the returned result from runModalSavePanelForSaveOperation and look for "stop" action. I pointed out to ChatGPT that runModalSavePanelForSaveOperation is void and does not return a result, it said again, "you are correct." It gave a third option which basically said to override runModalSavePanelForSaveOperation and build your own save panel from scratch. I didn't know if I should trust this answer. I reverted to my hack and wrote this post. Also ChatGPT never apologized for wasting my time with the wrong answers.
3
0
363
Jun ’24
ios 17.5.1 keyboard glitch on some batches on iphone 14+models(not all)
We are using Material Textfield iOS component (as directed by our client), https://github.com/material-components/material-components-ios/blob/develop/components/TextControls/README.md , after ios 17.5.1 update, for all the material textfield on some iphone 14+ models there is a keyboard appearance issue, the keyboard starts to appear but dismisses immediately on tap of any textfeild,i.e material textfield component, apple's uitextfield works properly, we have an iphone 14+ with ios 17.5.1, for us it works without any issues, our app was uploaded using xcode 14.2, not sure how to fix this issue as we are not able to reproduce it, couple of users have reported this issue, it however works on all other iphone models!!! Any help would be greatly appreciated , i understand this is a third party SDK, but how to simulate this bug, if it is happening only on some devices and on the same device models we have, are working.
1
0
504
Jun ’24
NSString.getBytes does not crash even when an invalid range is passed.
When we pass some special words, NSString.getBytes does not crash even when we pass an invalid range. It seems a bug. The below code is an example. func testNSStringGetBytes() { let originalString: String = "􁜁あ" let bufferSize = 256 var buffer = [UInt8](repeating: 0, count: bufferSize) var usedLength = 0 // An invalid range is passed let range = NSRange(location: 0, length: originalString.count + 1) var remainingRange = NSRange() (originalString as NSString) .getBytes( &buffer, maxLength: bufferSize, usedLength: &usedLength, encoding: String.Encoding.utf8.rawValue, options: [], range: range, remaining: &remainingRange ) print("Used Length: \(usedLength)") print("Buffer: \(buffer[0..<usedLength])") if remainingRange.length > 0 { print("Did not convert the whole string. Remaining range: \(remainingRange)") } else { print("Entire string was converted successfully.") } }
1
0
289
Jun ’24
How do you allow an XPC service to create a new file based on an NSURL that the user selected from an NSSavePanel?
How do you send an NSURL representing a new file, as returned from an NSSavePanel, to an XPC service such that the service is granted permission to create the file? I can successfully pass an NSURL to the XPC process if the NSURL represents an existing file. This is documented in Apple's Documentation: Share file access between processes with URL bookmarks This involves creating bookmark date while passing 0 in as the options. However, if you try to create bookmark data for an NSURL that represents a file that is not yet created, you do not get any bookmark data back and an error is returned instead: Error Domain=NSCocoaErrorDomain Code=260 "The file couldn’t be opened because it doesn’t exist." Simply passing the file path to the XPC process, by way of: xpc_dictionary_set_string(message, "file_path", url.fileSystemRepresentation); Does not grant the XPC create/write permissions. Is there an API or trick I'm missing? Note that the user should be allowed to save and create new files anywhere of their choosing, thus restricting URLs to only those within a group or container shared between the app and service isn't really viable. Using the latest of everything on macOS with the xpc_session API...
1
0
324
Jun ’24
Archiving my macOS target app fails with BOOL error
I'm building a macOS target for my App (which also has some Obj-C code). Building and running the app is fine but when I archive the app in XCode, the process / build fails with the following error Type 'BOOL' (aka ;Int32') cannot be used as a boolean;test for '!=0' instead It happens in a couple of places, one of the places being private func getRootDirectory(createIfNotExists: Bool = true) throws -> URL { return try FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true) } where it complains that create: true is not acceptable and throws the above error. If I comment out this line, the archive works successfully. When i Cmd + click the definition of Filemanager.default.url , i get this @available(macOS 10.6, *) open func url(for directory: FileManager.SearchPathDirectory, in domain: FileManager.SearchPathDomainMask, appropriateFor url: URL?, create shouldCreate: BOOL) throws -> URL This looks fishy since it it says create shouldCreate: BOOL whereas the documentation says it should be just Bool func url( for directory: FileManager.SearchPathDirectory, in domain: FileManager.SearchPathDomainMask, appropriateFor url: URL?, create shouldCreate: Bool ) throws -> URL My minimum deployment target is macOS 13.0 I'm quite stumped at this error - which happens only while archiving. Does anybody know why?
4
0
406
Jun ’24
How activate window correctly using activationPolicy
I have the following code: + (BOOL)activateWindow:(NSWindow*)window { if (NSApp.activationPolicy != NSApplicationActivationPolicyRegular) [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular]; if (window) { [NSApp activate]; //if (window.isMiniaturized) [window deminiaturize:nil]; [window makeKeyAndOrderFront:nil]; } return YES; } + (BOOL)hideWindowFromDock:(NSWindow*)window { if (NSApp.activationPolicy != NSApplicationActivationPolicyProhibited) [NSApp setActivationPolicy:NSApplicationActivationPolicyProhibited]; window.isVisible = NO; return YES; } I hide app main window by setting NSApplicationActivationPolicyProhibited if it is minimized or being closed. The code worked most of the time. But since upgrading to Sonoma, sometimes it won't correctly activate main window. The window icon reappears in the dock, but the window won't show up. I have to click on the window icon again to let it 'order front'. Sometimes, I observe a very weird behavior of the window being activated. It 'order front' and then disappears and re-appears.
1
0
353
Jun ’24
XPC, Swift, ObjC, and arrays
I create a protocol that had, among other things: @objc func setList(_: [MyType], withReply: @escaping (Error?) -> Void) The daemon part is in Swift, while the calling part is in Objective-C. Because why not? (Actually, because the calling part has to deal with C++ code, so that's ObjC++; however, I wanted the stronger typing and runtime checking for the daemon part, so I wrote it in Swift.) The ObjC part uses NSArray<MyType*>. I set up an NSXPCConnection link, and create a (synchronous) proxy with the right protocol name. But when I try to do the XPC setList call, I get an error. I assume that's because it doesn't like the signature. (Surely this is logged somewhere? I couldn't find it, if so. 😩) But... if I have a signature of @objc func addItem(_: MyType, withReply: @escaping (Error?) -> Void), then it works. So I assume it's the array. (Oh, I've also tried it without the @objc; the protocol itself is defined as @objc.) I've tried changing to protocol signature to using NSArray, but same thing.
7
0
1.1k
Jun ’24
Problem with setNeedsDisplay:
Hi, with the default values the rotation take place but changing the value not. I bind a button to a slider action: -(IBAction)rotateXAction:(id)sender { NSLog(@"%@ \n",sender); BOOL yn = YES; _rotationX = [_sliderX intValue]; if(yn) printf("rotationX %d \n",_rotationX); // value o.k [self setNeedsDisplay:YES]; } The drawRect: will not be called. What is wrong with my code, please tell me. Uwe
1
0
434
Jun ’24
Mistake in OpenGLView:drawRect
I rewrite an old project since OpenGL is deprecated and the downgrade to High Sierra goes with the lost of the old project. Here is the drawRect: - (void)drawRect:(NSRect)dirtyRect { [super drawRect:dirtyRect]; if(backgroundColor == 1) glClearColor(0.95f, 1.0, 1.0f, 1.0); else glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glTranslatef(0.0 ,0.0, -10.0); // After mistake I wrote PushMatrix() glTranslatef(-0.01 ,-0.01, -10.0); // Screen Shot 0 // glTranslatef(-0.25 ,-0.25, -10.0); Screen Shot 1 glLineWidth(1.0); glRotated(rotationX, 1, 0, 0); glRotated(rotationY, 0, 1, 0); glCallList(axes); // After mistake I wrote PopMatrix() // Axes Vertices of xx,y,z are 1.0 // With vertices +/-0.99 nothing is drawn [self glError]; [self.openGLContext flushBuffer]; } I hope you Accept my Text and hope you can help me ! Mit freundlichen Grüßen Uwe Screen Shot 0 Screen Shot 1
1
0
369
Jun ’24
Cannot get NSTimer working in another thread
I need to create timers in another thread (not on main): @implementation AppDelegate { NSThread* _worker; } - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { _worker = [[NSThread alloc] initWithTarget:self selector:@selector(main) object:nil]; [_worker start]; } - (void)main { [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timer_tick:) userInfo:nil repeats:YES]; [NSThread sleepForTimeInterval:INFINITY]; NSLog(@"**********************"); } - (void)timer_tick:(NSTimer*)timer { NSLog(@"%@", NSThread.currentThread); } The timer never gets fired. What's wrong with my code?
2
0
350
May ’24
Memory leak with [NSMutableData appendData:]
Instruments reveals that the following simple code leaks memory on each delegate invoke: - (void)start { [_urlSession dataTaskWithURL:_url]; } - (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask didReceiveData:(NSData *)data { [_data appendData:data]; } I don't have any clue on this leak, it should not happen. What should I do to avoid this?
2
0
487
May ’24
Passkey AutoFill won't show the "passkey" prompt above the native keyboard
We implemented passkeys Autofill feature in iOS 16.6. Later verified in iOS 17.0 as well. But when we upgraded to iOS 17.5, the available passkeys autofill prompt is disappeared now. No code changes were done from our side. Also upgraded to iOS 17.5.1 and checked, still doesn’t show the prompt on the keyboard. For autofill we are calling 'performAutoFillAssistedRequests()' API on our ASAuthorizationController after fetching assertion options response from our Relying-Party. Our textFields content type is set to ‘username’. Additional Info: Before making the performAutoFillAssistedRequests() API call, when we click on the ‘Passwords’ icon on keyboard, it only shows the passwords saved on iPhone. But after making the call, we can see available passkeys as well in the list. We are making the fetch assertion options response call on textField delegate after typing more than two characters. I already raised a bug in Feedback Assistant on this - FB13809196. I attached a video and sysdiag file there.
0
1
408
May ’24
debug dlopen returning NULL
Hi, For the very same plugin dlopen() sometimes fails. The library is present but sometimes it returns NULL and sometimes a valid plugin handle. Here is the code: char *filename; void *plugin_so; filename = "/Applications/com.example.MyApp/Contents/Plugins/myplugin.dylib"; plugin_so = dlopen(filename, RTLD_NOW); I have debugged using lldb checked filename and it is present. The myplugin.dylib file supports 2 architectures, arm64 and x86_64. regards, Joël
1
0
366
May ’24
nw_connection_t and STARTTLS for SMTP connections
I'm using Network to establish a connection to various SMTP servers. For SMTP servers that use SSL on port 465, using the following code to establish the connection and communicate with the server works fine (read/write code omitted): nw_endpoint_t endpoint = nw_endpoint_create_host("smtp.example.com", "465"); nw_parameters_t parameters = nw_parameters_create_secure_tcp(NW_PARAMETERS_DEFAULT_CONFIGURATION, NW_PARAMETERS_DEFAULT_CONFIGURATION); nw_connection_t connection = nw_connection_create(endpoint, parameters); nw_connection_set_queue(connection, dispatch_get_main_queue()); nw_connection_set_state_changed_handler(connection, ^(nw_connection_state_t state, nw_error_t error) { //... } nw_connection_start(connection); For servers on port 587 that require an insecure connection at start then renegotiate a TLS handshake with the STARTTLS command, I change the parameters like so: nw_parameters_t parameters = nw_parameters_create_secure_tcp(NW_PARAMETERS_DISABLE_PROTOCOL, NW_PARAMETERS_DEFAULT_CONFIGURATION); This does allow me to establish the connection to the SMTP server but I'm stumped on how to initiate TLS on the established connection after invoking the STARTTLS command and receiving an OK response from the SMTP server. How do I add TLS options to an existing connected nw_connection_t connection?
5
0
499
May ’24
How to use .a in swift with an empty header
I'm making a Swift Program. I got a .a file that builded from some c++ scripts,and I can see some fuctions in it by commed "nm *.a", and a .h file like this My question is how to call the fuctions in .a like "testDebug",I can call from c# like [DllImport("__Internal")] private static extern void testDebug(); Google's answer always with a right .h file,Maybe I should make .h file correct first. Any reply would be greatly appreciated.
2
0
276
May ’24
Can't establish mTLS on iOS with WKWebView and ProxyConfiguration
I have a sample iOS app in Xcode that I run in the iOS 17.5 Simulator. It creates a WKWebView and configures a proxy via the ProxyConfiguration API, it works as expected unless the proxy tries to establish mTLS. It seems there is no way to handle the client certificate request when using a proxy. If I navigate to a page that requests mTLS without a proxy configured, it works as expected. Here is a minimal repro: #import "ViewController.h" #import &lt;WebKit/WebKit.h&gt; @import Foundation; @import WebKit; @interface ViewController () &lt;WKNavigationDelegate&gt; @property (nonatomic,strong) WKWebView* webView; @property (nonatomic, strong) WKWebViewConfiguration * webConfig; @end @implementation ViewController - (void)loadView { [super loadView]; nw_protocol_options_t tls_options = nw_tls_create_options(); sec_protocol_options_t sec_options = nw_tls_copy_sec_protocol_options(tls_options); sec_protocol_options_set_challenge_block( sec_options, ^(sec_protocol_metadata_t metadata, sec_protocol_challenge_complete_t challenge_complete) { NSLog(@"Inside of challenge block"); challenge_complete(nil); }, dispatch_get_main_queue()); nw_endpoint_t proxy_endpoint = nw_endpoint_create_host(GetHost(), GetPort()); nw_relay_hop_t relay = nw_relay_hop_create(nil, proxy_endpoint, tls_options); nw_proxy_config_t proxy_config = nw_proxy_config_create_relay(relay, nil); nw_proxy_config_add_match_domain(proxy_config, "api.ipify.org"); self.webConfig = [[WKWebViewConfiguration alloc] init]; self.webConfig.websiteDataStore = [WKWebsiteDataStore nonPersistentDataStore]; self.webConfig.websiteDataStore.proxyConfigurations = @[ proxy_config ]; self.webView = [[WKWebView alloc] initWithFrame:self.view.frame configuration:self.webConfig]; self.webView.navigationDelegate = self; [self.view addSubview:self.webView]; } - (void)viewDidLoad { [super viewDidLoad]; NSLog(@"%s",__func__); NSURL* url = [[NSURL alloc] initWithString:@"https://api.ipify.org"]; NSURLRequest* request = [[NSURLRequest alloc] initWithURL:url]; [self.webView loadRequest:request]; } - (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation { NSLog(@"%s",__func__); } - (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(WKNavigation *)navigation withError:(NSError *)error { NSLog(@"%s. Error %@",__func__,error); } - (void)webView:(WKWebView *)webView didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential *))completionHandler { NSLog(@"%s",__func__); NSLog(@"protection space: %@", challenge.protectionSpace.authenticationMethod); completionHandler(NSURLSessionAuthChallengePerformDefaultHandling, nil); } @end The logs for this code show: -[ViewController viewDidLoad] -[ViewController webView:didStartProvisionalNavigation:] -[ViewController webView:didFailProvisionalNavigation:withError:]. Error Error Domain=NSURLErrorDomain Code=-1206 "The server “api.ipify.org” requires a client certificate." If we don't set up the ProxyConfiguration and navigate to a site that requires mTLS, the logs look like this: -[ViewController viewDidLoad] -[ViewController webView:didReceiveAuthenticationChallenge:completionHandler:] protection space: NSURLAuthenticationMethodServerTrust -[ViewController webView:didReceiveAuthenticationChallenge:completionHandler:] protection space: NSURLAuthenticationMethodClientCertificate -[ViewController webView:didStartProvisionalNavigation:] //... Eventually the request fails but the key difference is that didReceiveAuthenticationChallenge was invoked. When using the ProxyConfiguration neither that function nor the block we set via sec_protocol_options_set_challenge_block were run. I also tried to provide the client identity via sec_protocol_options_set_local_identity to no avail, and I've tried configuring these options too but they had no effect sec_protocol_options_add_tls_application_protocol(sec_options, "h2"); sec_protocol_options_set_max_tls_protocol_version(sec_options, tls_protocol_version_TLSv13); sec_protocol_options_set_peer_authentication_required(sec_options, true); Am I missing something? Or is this a bug in the ProxyConfiguration API?
0
1
408
May ’24