• 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: Mark Allan <email@hidden>
  • Date: Fri, 20 Oct 2017 11:23:59 +0100

> On 19 Oct 2017, at 6:05 pm, Quincey Morris
> <email@hidden> wrote:
>
> On Oct 19, 2017, at 09:04 , Mark Allan <email@hidden
> <mailto:email@hidden>> wrote:
>>
>> Terminating app due to uncaught exception 'NSInvalidArgumentException',
>> reason: '*** -[NSXPCEncoder _checkObject:]: This coder only encodes objects
>> that adopt NSSecureCoding (object is of class '__NSCFTimer').'
>
> It’s very suspicious that the timer itself would be encoded, since that would
> suggest that the timer itself is being passed back across the interface to
> the main app. What does the backtrace look like? Ideally there would be
> something there that tells you what it’s trying to do at that time.
>
> I don’t know, but I suspect that the block-based NSTimer methods might differ
> from the selector-based ones in that they use GCD rather than the run loop.
> If you look at the documentation, the old methods say "schedules it on the
> current run loop”. The new methods do not.
>
> That suggests the possibility of using dispatch_source_create and
> dispatch_source_set_timer directly to create a GCD-based time. It’s not quite
> as convenient to code, but not hard to get right.


Bingo...I think!

After creating the NSTimer, I was scheduling it on the main run loop with the
following:
        [[NSRunLoop mainRunLoop] addTimer:self.delegateUpdateTimer
forMode:NSDefaultRunLoopMode];

That worked with the block-based NSTimer API but not the selector-based API.  I
tried changing it to 'currentRunLoop' which got rid of the crash, but the timer
never fired.

Removing NSTimer altogether and replacing it with your suggestion of a
GCD-based timer works a treat.  Timer fires, no crashing, and the main app sees
the expected output.


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

  • Follow-Ups:
    • Re: Problem using NSTimer in privileged helper tool
      • From: Quincey Morris <email@hidden>
References: 
 >Problem using NSTimer in privileged helper tool (From: Mark Allan <email@hidden>)
 >Re: Problem using NSTimer in privileged helper tool (From: Quincey Morris <email@hidden>)

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