gnustep runloop - nsrunloop

Does anyone tell is GNUstep NSRunLoop extension functions:
(void) addEvent: (void*)data
type: (RunLoopEventType)type
watcher: (id)watcher
forMode: (NSString*)mode;
this method is work?, and how to setup the argument data? I set a pipe to read file description, but it seems not work fine. Really hard to figure out the question, can anyone help me?

This method works. Please show more of your code.
eg. for reading,
[[NSRunLoop currentRunLoop] addEvent: (void*)anFd
type: ET_RDESC
watcher: anObj // must implement receivedEvent:type:extra:forMode:
forMode: NSDefaultRunLoopMode]; // rtfm

Related

CMPedometer is not running

My CMPedometer is not running.
The code before it and after it gets run, but it itself does not work.
I get no warning or exception.
I'm testing it on a real 5s.
I've tried both querydata and startpedometerupdates.
I am importing core motion and the library is linked.
Any help?
if ([CMPedometer isStepCountingAvailable] == YES)
{
CMPedometer *cmped;
[cmped queryPedometerDataFromDate:start toDate:[NSDate date] withHandler:^(CMPedometerData *pedometerData, NSError *error){
stepslabel.text = [pedometerData.numberOfSteps stringValue];
}];
}
The problem with the original code above is the cmped variable gets deallocated at the end of the if statement, so the query is destroyed before it finishes.
By changing it to a strong property, it is retained in memory for the life of the class.
It seems really odd but I got it working by not declaring in the .h or before using it. What worked was declaring as #property CMPedometer *cmped; right after interface

How to create a new instance of an NSDocument with NSDocumentController?

I tried
[[NSDocumentController sharedDocumentController] duplicateDocumentWithContentsOfURL:nil
copying:NO
displayName:nil
error:NULL] ;
but it is not working. I have the error
typeForContentsOfURL:error: must be overridden for your application to support non-'file:' URLs.
Did you try like this below:-
[[NSDocumentController sharedDocumentController]newDocument:self];
I don't really know about the NSDocument+NSDocumentController machinery but here is my guess . Since I am answering my own question, please don't hesitate to comment or react.
[[NSDocumentController sharedDocumentController] addDocument:[[Document alloc] initWithType:nil
error:NULL]] ;

Connection Kit Basics

I need to implement file transfer in my application and it seems that in Cocoa ConnectionKit is unofficial standard. I was able to compile it but I have struggled finding any documentation or examples of it's use. The only example I found was outdated and even with modification I could not get it to work. Does anyone know the basic functions (creating connections, uploading...).
Thanks for any help
Its pretty simple once you figure out how its laid out.
Heres the code to create an ftp connection
CKConnectionRequest *request = [CKConnectionRequest requestWithURL:url];
CKFTPConnection *ftpConn = [[CKFTPConnection alloc] initWithRequest:request];
[ftpConn setDelegate:self];
[ftpConn connect];
self.connection = ftpConn;
[ftpConn release];
Then you would interact with the Connection Delegate methods found in CKConnectionProtocol.h
To authenticate to the server above you would use this delegate method where "cred" is an instance of NSURLCredential you have set up with the credentials you need.
- (void)connection:(id <CKConnection>)connection
didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
[[challenge sender] useCredential:cred forAuthenticationChallenge:challenge];
}
For an upload you would just call one of the upload methods specified in CKConnectionProtocol.h inside of a delegate method like below
- (void)connection:(id <CKConnection>)con
didOpenAtPath:(NSString *)dirPath error:(NSError *)error {
CKTransferRecord *tr = [con uploadLocalItem:localPath
toRemoteDirectory:remotePath
ignoreHiddenItems:YES];
}
Then you would receive callbacks as to the status of that upload via the Uploading Methods specified in CKConnectionProtocol.h
Hopefully that helps. Forgive any small errors in the code I typed it out not copy/paste

How to properly save a QTMovie after editing using QTKit?

I am making minor edits to a QTMovie in an application using NSDocument architecture (such as adding a track, as shown below). After the edit, I want to save to the original file. However, I keep getting a 'file is busy' error. I assume this is due to some oversight I made in the handling of the files, or a failure in how I am using NSDocument. Any tips would be helpful! Here is (some of) the relevant code:
// open file that has the track I want to add to my movie
QTMovie* tempMovie = [QTMovie movieWithURL:outputFileURL error:nil];
// Use old API to add the track
AddMovieSelection([movie quickTimeMovie], [tempMovie quickTimeMovie]);
// get the filename from the NSDocument
NSString *filename = [[self fileURL] path];
NSLog(#"writing to filename: %#", filename);
// FLATTEN the movie file so I don't get external references
NSMutableDictionary *attributes = [NSMutableDictionary dictionaryWithCapacity:1];
[attributes setObject:[NSNumber numberWithBool:YES] forKey:QTMovieFlatten];
// attempt to write
NSError *error;
// this is where I get the "file is busy"
if (![movie writeToFile:filename withAttributes:attributes error:&error]) {
NSLog(#"Error: %#", [error localizedDescription]);
NSRunAlertPanel(#"Error", [error localizedDescription], nil, nil, nil);
}
Do I have to first release the movie in my NSDocument? What is the "proper" way to do that? Keep in mind, I am not necessarily finished with this document, I am not closing it. I have just finished this operation, and I want the file on disk to reflect my changes. I would love to use [movie updateMovieFile], but that call doesn't seem to flatten the movie. I don't want any external references in my file.
I am not too familiar with the QuickTime C API, so I honestly can't tell you anything about what is going wrong there. Absolute guesswork: Maybe a call to EndMediaEdits is missing?
Though that shouldn't be required by AddMovieSelection, you said "[...] such as adding a track [...]". So maybe there is something else going on, like AddMediaSample or something similar?
That said, if you don't need to target anything below 10.5 and all you need to do is add some segment from another movie, you can achieve that without dropping down to the C API:
Have a look at
-[QTMovie insertSegmentOfTrack:fromRange:scaledToRange:]
and
-[QTMovie insertSegmentOfMovie:fromRange:scaledToRange:], if you want to have the inserted segment "overlayed" (temporally speaking).
-[QTMovie insertSegmentOfMovie:timeRange:atTime:] and -[QTMovie insertSegmentOfTrack:timeRange:atTime:], if you want { movieA.firstPart, movieB, movieA.secondPart }.
Do I have to first release the movie in my NSDocument?
You mean in order to write it to disk? No: That should even result in a crash.
The role of release is to handle memory-management. It doesn't have much to do with the busy-state of a file.
Turns out I just wasn't using the NSDocument architecture properly. When I changed it to use Save/SaveAs properly, this problem went away.

function that runs all the time in xcode?

I want to make a function that is always running in xcode similar to Unity's "function Update()". is this possible and if so, how.
You'll want to read up on run loops and NSTimers.
This code work for me,Hope it will help you!
write this function in your viewDidLoad() method
[self performSelector:#selector(onTick:) withObject:nil afterDelay:2.0];
And Here is the onTick: Method do whatever you want to run all the time
-(void)onTick:(NSTimer *)timer
{
//do something here
}

Resources