Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8650635
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:52:19+00:00 2026-06-12T13:52:19+00:00

Motivation: I’m working on an app that makes several (client) phones read audio data

  • 0

Motivation: I’m working on an app that makes several (client) phones read audio data from a (server) phone. The idea is that they must all play the song at the exact same time together.

Premise: I must figure out a way to make all phones start at a certain time stamp that is absolute (ie it’s not relative to the use set clock of either phone etc..).. based on some research I figured the best way to do this is to use CFAbsoluteTimeGetCurrent(); The idea here is that I get the latency it takes the server to communicate with each phone (b/c GKSession is done serially not in parallel apparently), add that latency to the current time, and then have every phone play the song starting at that start time. This start time must be absolute, it cannot be relative.

Question: How can I represent a time in the future in a number, that can be later on used to construct a CFDateRef. (The reason it has to be expressed as a number is that I must be able to send it in a packet..)

Example: This is a bit of code that explains what I’m trying to achieve:

-(void)viewDidLoad
{
    _timer = [Timer new];
    [_timer setCurrentTimeAsReferencepoint];

    [self performSelector:@selector(performAction) withObject:NULL afterDelay:5];
}


-(void)performAction
{
    double diff = [_timer getTimeElapsedinAbsTime];
    double timeInFuture = diff + [Timer getCurTime];
    NSLog(@"this is time in future in abs terms %f",timeInFuture);

    CFDateRef futureDate = CFDateCreate(NULL, timeInFuture);
    CFDateRef dateNow = CFDateCreate(NULL, [Timer getCurTime]);

    Boolean keepTesting = true;

    while (keepTesting) {
        if (CFDateCompare(dateNow, futureDate,NULL) == 0)   // ie both times are equal
        {
            NSLog(@"now is the time!");
            keepTesting = false;
        } else {
            NSLog(@"now isn't the time.. skip");
        }
    }
}

in Timer.m:

-(void)setCurrentTimeAsReferencepoint
{
    _referencePoint = [[self class] getCurTime];
    NSLog(@"this is reference point %f",_referencePoint);  
}

+(double)getCurTime
{
    return (double)CFAbsoluteTimeGetCurrent();
}

// not used in the above code.. but used when i compare the time of the server phone with the client phone
+(double)getTimeDifference:(double)time1
                     time2:(double)time2
{    
    CFDateRef newDate = CFDateCreate(NULL, time2);
    CFDateRef oldDate = CFDateCreate(NULL, time1);

    CFTimeInterval difference = CFDateGetTimeIntervalSinceDate(newDate, oldDate);    

    NSLog(@"this is time difference %f",fabs(difference));
    CFRelease(oldDate); CFRelease(newDate); 

    // fabs = absolute value
    return fabs(difference);    
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T13:52:21+00:00Added an answer on June 12, 2026 at 1:52 pm

    It turns out it’s simpler than I thought (note: getCurTime is defined in the question):

    -(void)performAction
    {
        double curTime = [Timer getCurTime];
        double timeInFuture = 2 + curTime;
        NSLog(@"this is time in future in abs terms %f and this is curTime %f",timeInFuture, curTime);
    
        CFDateRef futureDate = CFDateCreate(NULL, timeInFuture);
        CFDateRef dateNow = CFDateCreate(NULL, curTime);
    
        Boolean keepTesting = true;
    
        while (keepTesting) {
            dateNow = CFDateCreate(NULL, [Timer getCurTime]);
            if (CFDateCompare(dateNow, futureDate,NULL) >= 0)   // ie both times are equal or we've 
                                                                // gone past the future date time
            { 
                NSLog(@"now is the time!");
                keepTesting = false;
                return;
            } else {
                NSLog(@"now isn't the time.. skip");
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Motivation My app makes requests to some web service based on contents of table
I have a service that accepts callbacks from a provider. Motivation : I do
(Motivation: Consider a problem where you have to select a sports team from a
Motivation: I have fxcop integrated in the build process, which makes fxcopcmd.exe run each
motivation: I would like to create a utility class so that instead of having
My motivation for chaining my class constructors here is so that I have a
EDIT: To explain my motivation for this, I'm writing a command-line utility that takes
My main motivation for trying to do this is to get Javascript that is
Motivation and Problem There are several libraries for generating html markup strings using ruby
motivation for this is that (rarely)I have a need to know that the input

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.