• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Problem using NSTimer in privileged helper tool
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problem using NSTimer in privileged helper tool


  • Subject: Re: Problem using NSTimer in privileged helper tool
  • From: Alex Zavatone <email@hidden>
  • Date: Thu, 19 Oct 2017 11:08:05 -0500

A granular timer shouldn’t be that hard to write.  Can you use
CFAbsoluteTimeGetCurrent() ?  It’s in MacOS since 10.0.

https://developer.apple.com/documentation/corefoundation/1543542-cfabsolutetimegetcurrent



> On Oct 19, 2017, at 11:04 AM, Mark Allan <email@hidden> wrote:
>
> Hi all,
>
> I'm currently writing a Mac app which performs some lengthy process on some
> data, and for a variety of reasons it needs to do this via privileged helper
> tool.
>
> The class which does the work sends progress updates periodically to its
> delegate, which then communicates these back to the main app.
>
> The main app communicates with the helper tool via NSXPCConnection.
>
> I'm using an NSTimer to send the update messages to the delegate with the
> following incantation:
>
>    [NSTimer timerWithTimeInterval:0.2 repeats:YES block:^(NSTimer * _Nonnull
> timer) { ... }];
>
>
> This works fine, but I've just realised NSTimer's
> timerWithTimeInterval:repeats:block: is only available with macOS 10.12 and I
> still need to support 10.8.
>
> So I tried refactoring the block into a separate method and using an older
> NSTimer method:
>       [NSTimer timerWithTimeInterval:0.2 target:self
> selector:@selector(updateTheDelegateForRunID:) userInfo:runID repeats:YES];
>
>
> This causes my privileged helper tool to crash with the following message
> printed to Console:
>
> Terminating app due to uncaught exception 'NSInvalidArgumentException',
> reason: '*** -[NSXPCEncoder _checkObject:]: This coder only encodes objects
> that adopt NSSecureCoding (object is of class '__NSCFTimer').'
>
>
> Initially, I thought this meant my own class needed to conform to
> NSSecureCoding, but after some failed attempts, it think it's trying to tell
> me that it can't do it because *NSTimer* doesn't conform to NSSecureCoding.
> Is that correct, and if so does anyone know of a way around this issue?
>
> I guess, if push comes to shove, I could put the timer in the main app and
> have it request updates from the helper tool, but that sounds awfully like
> polling, and feels like it would be the wrong way round!
>
> Grateful for any suggestions.
>
> Many thanks
> Mark
>
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Problem using NSTimer in privileged helper tool (From: Mark Allan <email@hidden>)

  • Prev by Date: Problem using NSTimer in privileged helper tool
  • Next by Date: Re: Problem using NSTimer in privileged helper tool
  • Previous by thread: Problem using NSTimer in privileged helper tool
  • Next by thread: Re: Problem using NSTimer in privileged helper tool
  • Index(es):
    • Date
    • Thread