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

  • Home
  • SEARCH
  • 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 6809901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:08:28+00:00 2026-05-26T20:08:28+00:00

I created an FSEvent to handle the file changes. My problem is that the

  • 0

I created an FSEvent to handle the file changes. My problem is that the first time I save the file (it happens with Microsoft files, for example “.docx”, “.xls”… files) the event is fired twice. I need to display a user message, and it is displayed twice. Here is my source code:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
NSString *application_directory = [paths objectAtIndex:0];  
NSString *folder_path = [NSString stringWithFormat:@"%@/%@", application_directory, path];

CFStringRef file_path_ref = (CFStringRef) folder_path;

CFArrayRef pathsToWatch = CFArrayCreate(NULL, (const void **)&file_path_ref, 1, NULL);
void *appPointer = (void *)self;
FSEventStreamContext context = {0, appPointer, NULL, NULL, NULL}; // could put stream-specific data here.
CFAbsoluteTime latency = 3.0; /* Latency in seconds */

//Create the stream, passing in a callback 
stream = FSEventStreamCreate(NULL,
                             &mycallback,
                             &context,
                             pathsToWatch,
                             kFSEventStreamEventIdSinceNow, 
                             latency,
                             kFSEventStreamCreateFlagUseCFTypes 
                             );

FSEventStreamScheduleWithRunLoop(stream, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
FSEventStreamStart(stream);
CFRunLoopRun();

And this is the callback method:

void mycallback(ConstFSEventStreamRef streamRef,
            void *clientCallBackInfo,
            size_t numEvents,
            void *eventPaths,
            const FSEventStreamEventFlags eventFlags[],
            const FSEventStreamEventId eventIds[]){

int i;

for (i=0; i<numEvents; i++) 
{   
    DirectoryWatcher *directory_watcher = (DirectoryWatcher *)clientCallBackInfo;

    NSFileManager *file_manager = [NSFileManager defaultManager];

    Common *common = [[Common alloc] init];
    NSString *file_path = [common filePathByNameAndId:directory_watcher.file_name file_id:directory_watcher.file_id];

    NSDictionary *fileAttributes = [file_manager attributesOfItemAtPath:file_path error:NULL];
    [common release];

    NSDate *modified_date = [fileAttributes objectForKey:@"NSFileModificationDate"];
    NSDate *saved_date = [[NSUserDefaults standardUserDefaults] objectForKey:@"kFeedLastModified"];

    [[NSUserDefaults standardUserDefaults] setObject:modified_date forKey:@"kFeedLastModified"];
    [[NSUserDefaults standardUserDefaults] synchronize];

    if (![modified_date isEqualToDate: saved_date])
     {
         Common *common = [[Common alloc] init];
         if([common networkConectivityAvailable])
         {
             //HERE IS MY USER MESSAGE
         }
         else
         {
             NSLog(@"Retry this flow when internet is restored.");
         }

         [common release];
     } 
}    }
  • 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-05-26T20:08:28+00:00Added an answer on May 26, 2026 at 8:08 pm

    Sounds like Microsoft is doing some goofy stuff when writing out files… and actually, you can never count on every app behaving consistently and/or properly.

    My suggestion would be to only display an alert if one isn’t already displaying (i.e. that would get rid of the issue of multiple FSEvents firing from Microsoft apps). Or queue up the alerts and display them in order, making sure to display a subsequent alert only when appropriate (i.e. when a certain amount of time has passed or if the subsequent action is on a different file, etc.).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Created an extensive batch script program to handle some automated file management and printing
Created a button in my aspx file and add its click method in the
Created basic C++ DLL and exported names using Module Definition file (MyDLL.def). After compilation
Created a google map with GMap2 and put pinpoints on there that open up
Created by Microsoft as the foundation of its .NET technology, the Common Language Infrastructure
Created a web role project on Azure. Looking at the service definition file I
Created a WCF service that is being called by a Silverlight app. Both reside
Created new scaffold Users that has fields name & description All working as suppose
Created a AlertDialog that is used to prompting the user to enter a keyword.
I created a simple, stripped ListView style that highlights an element when the IsMouseOver

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.