Objective-C

RSS for tag

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

Posts under Objective-C tag

292 Posts
Sort by:
Post marked as solved
1 Replies
74 Views
Hi everyone ;-) I work on an objc framework and we will modernize it by starting to implement new features in Swift. To do so, I'm currently writing a POC, but I encountered a weird crash. If I just add some basic swift files and call them from my objc code, I can use my xcframework easily (from a swift app for the record). But, if the swift code contains Async/Await calls (even wrapped in a completion method), it does not work. This code leads to a crash right away : @objcMembers public class SwiftChecker: NSObject {   @available(iOS 13.0.0, *)   func check() async {     let data = try? await URLSession().data(for: URLRequest(url: URL(string: "http://www.google.fr")!))     if let data {       print("Yay! ❤️ \(data.0.count)")     } else {       print("Nay 😡")     }   }       public func check(completion: @escaping (() -> Void)) {     if #available(iOS 13.0.0, *) {       Task {         await check()         completion()       }     } else {       completion()     }   } } And I call it like that (inside the framework fyi) : if (@available(iOS 13.0, *)) {       SwiftChecker* checker = [[SwiftChecker alloc] init];       [checker checkWithCompletion:^{                 }];     } I even tried a more simpler code with @objcMembers public class SwiftChecker: NSObject {   @available(iOS 13.0.0, *)   func check() {     Task {       let data = try? await URLSession().data(for: URLRequest(url: URL(string: "http://www.google.fr")!))       if let data {         print("Yay! ❤️ \(data.0.count)")       } else {         print("Nay 😡")       }     }   } } but the result is the same. I f I don't use Task, then it works :-/ I can't find any reason or literature that indicates not to use modern concurrency with objC, especially when it's wrapped into a completion block like signature. I just can't give you the crash log as it has nothing to do with the actual crash. It's just a exit with signal 6 Any help would be appreciated. Thanks!
Posted Last updated
.
Post marked as solved
2 Replies
113 Views
hello, I am using dylibs and using c library. I am opening the dylibs and using some of the function properly. However, some of the other functions are giving me errors relating to freeing pointers. here is one of the function below. first I open the dl and save it as variable in a class     let dylib = dlopen("x.dylib", RTLD_NOW) then i create type alias for the function     typealias LoadConfiguration = @convention(c)  (ath_conf_t)> -> Void then here is the function to call the function of c     func LoadConfigLib(athConfT : inout ath_conf_t) -> Void?{         guard dylib != nil  else {             errorDylib()             return nil         }         guard let sym = dlsym(dylib, "LoadConfiguration")  else {             errorDylib()             return nil         }         let f = unsafeBitCast(sym, to: LoadConfiguration.self)         let result: Void = f(athConfT)         print(result)         return result     } here is the error. malloc: *** error for object 0x102665cc0: pointer being freed was not allocated malloc: *** set a breakpoint in malloc_error_break to debug things I am not certain how to fix this problem or how to approach this. any sorts of guidance would be appreciated here is the ath_conf_t public class ath_conf_t : NSObject {     public var version: CInt     public var channels: NSArray     init(version: CInt = 0, channels: NSArray = Array(repeating: ath_channel_t.init(arg1: false, arg2: 0, adaptiveHigh: 0, arg3: 0), count: constant) as NSArray) {         self.version = version         self.channels = channels     } }
Posted
by RyanKimK.
Last updated
.
Post not yet marked as solved
5 Replies
184 Views
I am having a crash with a Swift -> Objective-C interoperability under Xcode 14 / Swift 5.7 but only when Optimize for Speed is part of the build. There was no issue with this under Xcode 13.4.1 / Swift 5.6 under the same conditions. Typically, this compiler option is disabled for Debug builds so this was only detected once we provided release builds to beta users using Test Flight.  The interoperability is with using a proprietary, third-party framework. I am not privy to the Objective-C code that makes up the public API for this framework. As the framework had worked with Xcode 13.4.1 (with and without the speed optimization) and also works in Debug mode with Xcode 14.x (I have tried 14.1 as well) but crashes with the speed optimization turned on, I suspect the optimization may be at fault. But it is hard to say. I am hoping someone with better knowledge than I of this can guide me as to why this is happening…and only now. Here is an example of the code. Note: there are multiple instances of this same pattern in the API. There are vendor supplied structures (as well as NSArray as in this example) that cause similar failure. The vendor has supplied only Objective-C sample code and documentation.     func listItems() {         var availableItems: NSMutableArray? = NSMutableArray()         let result = itemSDK.getAvailableItemList(&availableItems)     // ...     } The header file provides: - (ITEM_RESULT) getAvailableItemList:(NSMutableArray**)getAvailableItemList; The derived Swift interface for this is: func getAvailableItemList(_ availableItemsList: AutoreleasingUnsafeMutablePointer<NSMutableArray?>!) -> ITEM_RESULT The crash occurs when calling the API and/or attempting to use the value associated with the AutoreleasingUnsafeMutablePointer. I have turned on all memory management diagnostics for the run phase of the scheme. When I do so, I see the following in the console when I get a fatal Thread 1: EXC_BREAKPOINT (code=1, subcode=0x1d66e8a88) presented in the caller to the listItems() method. *** -[__NSArrayM retain]: message sent to deallocated instance 0x28bd15200 My assumption is that this indicates the memory was released (aggressively?) and so this causes the crash. Again, only with the -O (Optimize for Speed) option is enabled. I have been able to code a potential solution to this issue. Maybe this should have been the solution for prior Swift versions…but I had no reason (as it had worked without issue up until Xcode 14).     func listItems() {         let itemsArray = NSMutableArray()          var availableItems: NSMutableArray? = itemsArray         let result = itemSDK.getAvailableItemList(&availableItems)     // ...     } This solution assigns the array to an immutable variable and then assigns that reference to an optional that is passed for the AutoreleasingUnsafeMutablePointer. My assumption is that adds an additional retain to keep the optimization from removing the memory for the array until the itemsArray is no longer referenced. I am reaching out to see if this is a known issue by others and/or expected (but new) behavior as I do not have much experience with AutoreleasingUnsafeMutablePointer. Also, if this is not a bug but is the new normal, is the potential solution the proper way to use the AutoreleasingUnsafeMutablePointer with Objective-C framework APIs? Or should I be doing something different? Thanks for any insight or pointers (even if unsafe).
Posted
by billdog.
Last updated
.
Post marked as solved
5 Replies
135 Views
I've been seeing a lot of crash reports on iOS 15 for code that has been in place a long time. The crash report indicates this is happening during the call to saveAppData while trying to persist the state of the users tab order. There is a More Controller in the mix but this was working for literally years. I've been staring at this for days and can't find anything obvious. I am wondering if something changed with iOS 15 which is when this issue started . This is the relevant code: -(void)saveAppData { // Save Current Tab Order to Users Prefs NSMutableArray *savedOrder = [NSMutableArray arrayWithCapacity:TAB_BAR_NUMBER_OF_ITEMS]; NSArray *tabOrderToSave = _tabBarController.viewControllers; for(UIViewController *aViewController in tabOrderToSave) { [savedOrder addObject:@(aViewController.tabBarItem.tag)]; } [userSettings setObject:savedOrder forKey:SavedTabOrderKey];       // Save the TAG of selected TabBarItem   [userSettings setObject:@(_tabBarController.tabBar.selectedItem.tag) forKey:SavedTabLastViewedKey]; [userSettings synchronize]; } -(void)applicationDidEnterBackground:(UIApplication *)application { NSLog(@"**** Entering Background Saving Data");    [self saveAppData];     [self.coreDataUtil saveMOC]; } and here is the crash report. Any assistance on observations are most welcome. Thanks.
Posted
by cliffr.
Last updated
.
Post not yet marked as solved
6 Replies
151 Views
Seeing A LOT of crashes for this code which has been around for quite a while (on iOS 15). After a viewController that user has been using is dismissed we check some values to determine if we should prompt for a rating and write some values into NSUserDefaults and which is when the crash happens. This code gets called when the user clicks a Done Button to dismiss the viewController: -(void)dismissChart { [self.navigationController dismissViewControllerAnimated:YES completion:^{     if([IphemerisUtil okToRequestRatingUsingCount:OK_TO_REQUEST_REVIEW_COUNT])       [IphemerisUtil requestAppRating];   }]; } This is what is called and where the crash occurs: +(BOOL)okToRequestRatingUsingCount:(int)count {    int curVersion = [[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"] intValue];        NSNumber *lastVerRated = [userSettings objectForKey:RateLastVersionRated];    int lastVersionRated = (lastVerRated != nil) ? [lastVerRated intValue] : 0;        NSNumber *ratePromptCnt = [userSettings objectForKey:RatePromptCounter];    int rateCounter = (ratePromptCnt != nil) ? [ratePromptCnt intValue] : 1;        NSDate *dateLastCounterIncrement = [userSettings objectForKey:RatePromptCounterLastDateIncrement];    if(!dateLastCounterIncrement) {      dateLastCounterIncrement = [NSDate date];      [userSettings setObject:dateLastCounterIncrement forKey:RatePromptCounterLastDateIncrement];    }        if(curVersion &gt; lastVersionRated) {      if(rateCounter &gt; count)        return YES;      else {        // Increment the counter only once a day        if([[NSDate date] timeIntervalSinceDate:dateLastCounterIncrement] &gt; (3600 * 24)) {          rateCounter++;          [userSettings setObject:[NSNumber numberWithInt:rateCounter] forKey:RatePromptCounter];        }      }   }   return NO; } One of the two userSettings:setObject is crashing. As indicated by this symbolicated crash log for the above code.
Posted
by cliffr.
Last updated
.
Post not yet marked as solved
1 Replies
217 Views
Hello everyone! I've faced this issue: using AutoreleasingUnsafeMutablePointer with XCode >= 14 and Release configuration causes EXC_BAD_ACCESS. However, with Debug or XCode 13.4.1 app works just fine... Original post here - https://forums.swift.org/t/swift-5-7-using-autoreleasingunsafemutablepointer-leads-to-exc-bad-access/60688
Posted
by cgsgilich.
Last updated
.
Post not yet marked as solved
1 Replies
151 Views
I assign its navigationDelegate in my 'CustomWebView' init function, the init function is called in the viewDidLoad function and the 'CustomWebView' implements the WKNavigationDelegate functions, objection_requires(NSStringFromSelector(@selector(configRepository))) - (instancetype)initWithConfiguration:(WKWebViewConfiguration *)configuration configRepository:(SKYConfigRepository *)configRepository { self = [super init]; _configRepository = configRepository; if (self) { [[JSObjection defaultInjector] injectDependencies:self]; self.converterLink = [JSObjection defaultInjector][@protocol(UniversalLinkConverterProtocol)]; WKWebViewConfiguration *wkWebViewConfig = [self getWebViewConfigWithUpdatedUserAgent:configuration]; _wkWebView = [[WKWebView alloc] initWithFrame:CGRectZero configuration:wkWebViewConfig]; _wkWebView.navigationDelegate = self; ... ... then when I debug the '_wkWebView.navigationDelegate' is nil the 'self' is not nil, and it implements the WKNavigationDelegate, {   WKWebView *_wkWebView;   SKYConfigRepository *_configRepository; }
Posted
by Kjc_dd.
Last updated
.
Post not yet marked as solved
1 Replies
388 Views
Anybody come across this problem? Unable to activate constraint with anchors &lt;NSLayoutDimension:0x28276bb00 "_UINavigationBarTitleControl:0x155327a70.height"&gt; and &lt;NSLayoutDimension:0x28281d840 "UILayoutGuide:0x28043e300'TitleViewGuide(0x14ff9ee00)'.height"&gt; because they have no common ancestor. Does the constraint or its anchors reference items in different view hierarchies? That's illegal. Who can tell me why? Or the solution
Posted Last updated
.
Post not yet marked as solved
8 Replies
238 Views
Hello, We want to create iOS App from scratch in Objective C. But we are confused that at the time of binary upload , is binary accepted by the application loader as project is created in Objective C? and answer is yes, then any specific steps/standards that we need to follow. Thanks.
Posted
by Fingser.
Last updated
.
Post marked as solved
7 Replies
7.1k Views
I'm looking for a way to set up a new alarm in the actual IOS Alarm Clock application from a new (self-created) app.Basically, the app I'm creating would programmatically add a new alarm to the Default alarm Clock app, which would then simply behave as it normally does -- making the built-in alarm clock ring when the time arrives.
Posted Last updated
.
Post not yet marked as solved
1 Replies
198 Views
Description Fatal Exception: NSInvalidArgumentException 0 CoreFoundation 0x9e88 (Missing UUID 2e338a4118d539d79a8432fc4fc84488) 1 libobjc.A.dylib 0x178d8 (Missing UUID a451160df9663645b8ee8e68fcbfdadf) 2 CoreFoundation 0xf9c58 (Missing UUID 2e338a4118d539d79a8432fc4fc84488) 3 UIFoundation 0x220e0 (Missing UUID b06f93ec409d398d83ca2c329e047ca4) 4 UIFoundation 0x9f104 (Missing UUID b06f93ec409d398d83ca2c329e047ca4) 5 UIFoundation 0x86e70 (Missing UUID b06f93ec409d398d83ca2c329e047ca4) 6 CoreFoundation 0xa3a0 (Missing UUID 2e338a4118d539d79a8432fc4fc84488) 7 CoreFoundation 0x910e0 (Missing UUID 2e338a4118d539d79a8432fc4fc84488) 8 UIFoundation 0x86cfc (Missing UUID b06f93ec409d398d83ca2c329e047ca4) 9 UIFoundation 0x86eb4 (Missing UUID b06f93ec409d398d83ca2c329e047ca4) 10 UIFoundation 0x7e6ec (Missing UUID b06f93ec409d398d83ca2c329e047ca4) 11 UIFoundation 0x815d8 (Missing UUID b06f93ec409d398d83ca2c329e047ca4) 12 UIKitCore 0x98e3b4 (Missing UUID 46a6f3c12e66389e92f14b24322c4905) 13 UIKitCore 0xf32090 (Missing UUID 46a6f3c12e66389e92f14b24322c4905) 14 UIKitCore 0xf485d4 (Missing UUID 46a6f3c12e66389e92f14b24322c4905) 15 UIKitCore 0xedd264 (Missing UUID 46a6f3c12e66389e92f14b24322c4905) 16 UIKitCore 0xedcfd0 (Missing UUID 46a6f3c12e66389e92f14b24322c4905) 17 UIKitCore 0xedd82c (Missing UUID 46a6f3c12e66389e92f14b24322c4905) 18 UIKitCore 0x24e0c8 (Missing UUID 46a6f3c12e66389e92f14b24322c4905) 19 UIKitCore 0x9436d8 (Missing UUID 46a6f3c12e66389e92f14b24322c4905) 20 UIKitCore 0xbdc2c (Missing UUID 46a6f3c12e66389e92f14b24322c4905) 21 UIKitCore 0x42baf8 (Missing UUID 46a6f3c12e66389e92f14b24322c4905) 22 UIKitCore 0x1a5418 (Missing UUID 46a6f3c12e66389e92f14b24322c4905) 23 UIKitCore 0x85dcc (Missing UUID 46a6f3c12e66389e92f14b24322c4905) 24 UIKitCore 0x131c90 (Missing UUID 46a6f3c12e66389e92f14b24322c4905) 25 UIKitCore 0x9b6bf0 (Missing UUID 46a6f3c12e66389e92f14b24322c4905) 26 UIKitCore 0xf66d4 (Missing UUID 46a6f3c12e66389e92f14b24322c4905) 27 UIKitCore 0xfb02c (Missing UUID 46a6f3c12e66389e92f14b24322c4905) 28 UIKitCore 0xfa2fc (Missing UUID 46a6f3c12e66389e92f14b24322c4905) 30 UIKitCore 0xf99b8 (Missing UUID 46a6f3c12e66389e92f14b24322c4905) 31 UIKitCore 0x14179c (Missing UUID 46a6f3c12e66389e92f14b24322c4905) 32 UIKitCore 0x44a230 (Missing UUID 46a6f3c12e66389e92f14b24322c4905) 33 CoreFoundation 0xd5f54 (Missing UUID 2e338a4118d539d79a8432fc4fc84488) 34 CoreFoundation 0xe232c (Missing UUID 2e338a4118d539d79a8432fc4fc84488) 35 CoreFoundation 0x66210 (Missing UUID 2e338a4118d539d79a8432fc4fc84488) 36 CoreFoundation 0x7bba8 (Missing UUID 2e338a4118d539d79a8432fc4fc84488) 37 CoreFoundation 0x80ed4 (Missing UUID 2e338a4118d539d79a8432fc4fc84488) 38 GraphicsServices 0x1368 (Missing UUID a633a095122639428f413877660185ee) 39 UIKitCore 0x3a161c (Missing UUID 46a6f3c12e66389e92f14b24322c4905) 40 UIKitCore 0x3a1280 (Missing UUID 46a6f3c12e66389e92f14b24322c4905) 42 ??? 0x1f425a960 (Missing) This crash is happening only in iOS 16.1,The crash is in the method NSTextContentStorage locationFromLocation:withOffset: and the reason is "received invalid location (null)". Guys please help to fix this issue.
Posted Last updated
.
Post marked as solved
1 Replies
147 Views
We use “CGDisplayStreamCreateWithDispatchQueue” function to create a display stream, sometimes the application show crash on macOS Ventura. It can be use normally on macOS Monterey/Big Sur/Catalina/… I can see this bug by other Application(Through the Console->Crash Report), which is also use this function. The relevant code is as follows:     CGDisplayStreamRef _displayStream;     CGDirectDisplayID displayID = CGMainDisplayID();     unsigned long modeWidth;     unsigned long modeHeight;     modeWidth = CGDisplayPixelsWide(displayID);     modeHeight = CGDisplayPixelsHigh(displayID);     CGDisplayModeRef displayModeRef = CGDisplayCopyDisplayMode(displayID);     if (displayModeRef){         modeWidth = CGDisplayModeGetPixelWidth(displayModeRef);         modeHeight = CGDisplayModeGetPixelHeight(displayModeRef);     }     CGDisplayModeRelease(displayModeRef);     NSLog(@"enable stream, displayID[0x%x], mode[%lu x %lu]\n", displayID, modeWidth, modeHeight);     const int var_prop = 2;     const void* keys[var_prop] = { kCGDisplayStreamDestinationRect, kCGDisplayStreamShowCursor};     const void* values[var_prop] = { CGRectCreateDictionaryRepresentation(CGRectMake(0, 0, modeWidth, modeHeight)) , kCFBooleanTrue};     CFDictionaryRef properties = CFDictionaryCreate(NULL, keys, values, var_prop, NULL, NULL);     _displayStream = CGDisplayStreamCreateWithDispatchQueue(displayID, modeWidth, modeHeight, 'BGRA', properties, dispatchQueue, ^(CGDisplayStreamFrameStatus status, uint64_t displayTime, IOSurfaceRef frameSurface, CGDisplayStreamUpdateRef updateRef) {             if(status == kCGDisplayStreamFrameStatusStopped)             {                 NSLog(@"kCGDisplayStreamFrameStatusStopped is received!");                 bIsStreamStatusStopped = true;                 return;             }             if(status == kCGDisplayStreamFrameStatusFrameComplete && frameSurface)             {                 CFRetain(frameSurface);                 IOSurfaceIncrementUseCount(frameSurface);                 CFRetain(updateRef);                 [[NSOperationQueue mainQueue] addOperationWithBlock:^{                     if(!bIsStreamStatusStopped) {                         self.view.layer.contents = (__bridge id _Nullable)(frameSurface);                     }                 }];               CFRelease(updateRef);                 IOSurfaceDecrementUseCount(frameSurface);                 CFRelease(frameSurface);             }     });     if (_displayStream)     {         CGError err = CGDisplayStreamStart(_displayStream);         bIsStreamStatusStopped = false;         if (err != CGDisplayNoErr)         {             NSLog(@"Error %u starting display stream", (unsigned)err);             CFRelease(_displayStream);             _displayStream = 0;         }     }     else         NSLog(@"create stream failed.\n"); The crash log is as follows: 0 CoreFoundation 0x189889e48 CFGetTypeID + 148 1 CoreFoundation 0x1898ac970 __CFPropertyListIsValidAux + 60 2 CoreFoundation 0x1898aedd4 __CFPropertyListIsDictPlistAux + 188 3 CoreFoundation 0x1898eab40 __CFDictionaryApplyFunction_block_invoke + 28 4 CoreFoundation 0x1898b2c38 CFBasicHashApply + 148 5 CoreFoundation 0x1898a4814 CFDictionaryApplyFunction + 320 6 CoreFoundation 0x1898acb9c __CFPropertyListIsValidAux + 616 7 CoreFoundation 0x1898beea8 CFPropertyListWrite + 92 8 CoreFoundation 0x1898de418 CFPropertyListCreateData + 144 9 SkyLight 0x18e4aba04 CGSPropertyListCreateSerializedData + 72 10 SkyLight 0x18e4b72ac CGSPropertyListCreateSerializedBytes + 68 11 SkyLight 0x18e699e14 CGSPropertyListPerformWithSerializedBytes + 64 12 SkyLight 0x18e5c25c4 SLDisplayStreamCreate + 296 13 SkyLight 0x18e5c3008 SLDisplayStreamCreateWithDispatchQueue + 52 14 macOS InstantView 0x1043617f8 0x104328000 + 235512 15 macOS InstantView 0x1043619fc 0x104328000 + 236028 16 macOS InstantView 0x104361444 0x104328000 + 234564 17 SkyLight 0x18e4b9f8c displayConfigFinalizedProc + 276 18 SkyLight 0x18e4b1558 CGSPostLocalNotification + 172 19 SkyLight 0x18e4b1148 (anonymous namespace)::notify_datagram_handler(unsigned int, CGSDatagramType, void*, unsigned long, void*) + 116 20 SkyLight 0x18e7d3bec CGSDatagramReadStream::dispatchMainQueueDatagrams() + 228 21 SkyLight 0x18e7d3ae8 invocation function for block in CGSDatagramReadStream::mainQueueWakeup() + 28 22 libdispatch.dylib 0x189680a48 _dispatch_call_block_and_release + 32 23 libdispatch.dylib 0x189682570 _dispatch_client_callout + 20 24 libdispatch.dylib 0x189690d28 _dispatch_main_queue_drain + 928 25 libdispatch.dylib 0x189690978 _dispatch_main_queue_callback_4CF + 44 26 CoreFoundation 0x18992a77c __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 16 27 CoreFoundation 0x1898e82d0 __CFRunLoopRun + 2036 28 CoreFoundation 0x1898e7388 CFRunLoopRunSpecific + 612 29 HIToolbox 0x192f06a68 RunCurrentEventLoopInMode + 292 30 HIToolbox 0x192f068ac ReceiveNextEventCommon + 672 31 HIToolbox 0x192f065f4 _BlockUntilNextEventMatchingListInModeWithFilter + 72 32 AppKit 0x18cb2621c _DPSNextEvent + 632 33 AppKit 0x18cb253ac -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 728 34 AppKit 0x18cb1972c -[NSApplication run] + 464 35 AppKit 0x18caf0a24 NSApplicationMain + 880 36 macOS InstantView 0x1043546cc 0x104328000 + 181964 37 dyld
Posted
by Christal.
Last updated
.
Post not yet marked as solved
1 Replies
160 Views
am using the [NSKeyedUnarchiver unarchiveObjectWithData:result] methode for unarchiving NSData in my objective c bases app. `NSMutableArray *array = (NSMutableArray *)[NSKeyedUnarchiver unarchiveObjectWithData:result]; This is working pretty fine upto iOS15. But since iOS16 I am getting a crash that [MyClass initWithCoder:]: unrecognized selector sent to instance 0x281069760. I can see that unarchiveObjectWithData methods is deprecated. So as suggested in xcode, now I have tried `NSError *err; @try { NSMutableArray *array = (NSMutableArray *)[NSKeyedUnarchiver unarchivedObjectOfClass:[NSMutableArray class] fromData:result error:&amp;err]; } @catch (NSException *exception) { NSLog(@"Exception %@", exception.reason); } Now I am getting nil value for my array and the err is err = 0x0000000281ff1020 domain: nil - code: 4864 There were no issues before I updated my iPad to iPadOS 16. Any help is appreciated.
Posted
by Basith128.
Last updated
.
Post not yet marked as solved
1 Replies
186 Views
I have the next problem: my app gets a false notification about time change. // add observer and notification  [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleSystemTimeChangeNotification:) name:NSSystemClockDidChangeNotification object:nil]; // handle system notification about time change - (void)handleSystemTimeChangeNotification:(NSNotification*)notification {     CLLogInfo(@"The time change detected"); } It works without any problem on previous OS: Big Sur, Catalina. Only working with Monterey, Ventura I have these troubles. Please, give me some recommendations about what I should do. How can I detect time change on macOS (Ventura, Monterey) ?
Posted Last updated
.
Post marked as solved
1 Replies
183 Views
I am using the openApplicationAtURL:(NSURL *)applicationURL configuration:(NSWorkspaceOpenConfiguration *)configuration completionHandler:(void (^ _Nullable)(NSRunningApplication *_Nullable app, NSError *_Nullable error))completionHandler function to open the application itself on macOS Ventura. I need to restart the software itself before it exits. So I call the openApplicationAtURL function to reopen it. But it failed. In the same code, I can successfully open any other software(As soon as I change the name of the software), but it can not open the software itself. Is there any way to resolve it? Sample code: NSBundle* bundle = NSBundle.mainBundle; NSWorkspace* workspace = NSWorkspace.sharedWorkspace; NSWorkspaceOpenConfiguration* configuration = [NSWorkspaceOpenConfiguration new]; NSDictionary* env = @{}; [configuration setEnvironment: env]; [configuration setPromptsUserIfNeeded: YES]; NSString* path = bundle.bundlePath; [workspace openApplicationAtURL: [NSURL fileURLWithPath: path] configuration: configuration completionHandler:^(NSRunningApplication* app, NSError* error) { if (error) { NSLog(@"Failed to run the app: %@", error.localizedDescription); } }];
Posted
by Christal.
Last updated
.
Post not yet marked as solved
1 Replies
202 Views
The purpose of the following code is to achieve a gradient background color In newer versions, it looks fine, but in macOS 10.12.4, the title of the button doesn't appear - (void)setGradient:(NSArray&lt;__kindof NSColor *&gt; *)colorArr StartPoint:(CGPoint)startPoint EndPoint:(CGPoint)endPoint { self.wantsLayer = YES; CAGradientLayer *gradinentlayer = [CAGradientLayer layer]; NSMutableArray *array = [NSMutableArray array]; for (NSColor *color in colorArr) { [array addObject:(id)color.CGColor]; } gradinentlayer.colors = array; gradinentlayer.startPoint = startPoint; gradinentlayer.endPoint = endPoint; gradinentlayer.frame = self.bounds; [self.layer insertSublayer:gradinentlayer atIndex:0]; } How do I make the title text appear, other than adding a subview? Any help would be appreciated!
Posted
by LLL_.
Last updated
.