Rectangle 27 4

This was not working because I had an active video capture session in my application.

AudioServicesPlaySystemSound will not play when there is an active video capture session.

iphone - AudioServicesPlaySystemSound sound not audible when called fr...

iphone ios objective-c audiotoolbox
Rectangle 27 4

This was not working because I had an active video capture session in my application.

AudioServicesPlaySystemSound will not play when there is an active video capture session.

iphone - AudioServicesPlaySystemSound sound not audible when called fr...

iphone ios objective-c audiotoolbox
Rectangle 27 677

Basically you need to "merge backwards" - apply a diff between the current and previous version to the current version (so you end up with a working copy looking like the old version) and then commit again. So for example to go from revision 150 (current) back to revision 140:

svn update
svn merge -r 150:140 .
svn commit -m "Rolled back to r140"

but the merge is not override my changes and the new revision.

Which changes? Any changes you don't want in your working copy can just be removed with svn revert. Committed changes will be 'undone' by this merge.

If you are using TortoiseSVN, right-click the file select Merge, then Merge a Range of Revisions. In the log box type in 140-150 and click the Reverse Checkbox. After that, commit as usual. This will perform the same operation as Jon's example.

With eclipse and subclipse, you can right-click on your project, Team/Show History, then select then revisions you want to "undo" and with another right-click select "Revert changes from Selected Revisions".

To revert from head revision you can also write svn merge -r HEAD:140.

svn - How do I return to an older version of our code in Subversion? -...

svn backport
Rectangle 27 675

Basically you need to "merge backwards" - apply a diff between the current and previous version to the current version (so you end up with a working copy looking like the old version) and then commit again. So for example to go from revision 150 (current) back to revision 140:

svn update
svn merge -r 150:140 .
svn commit -m "Rolled back to r140"

but the merge is not override my changes and the new revision.

Which changes? Any changes you don't want in your working copy can just be removed with svn revert. Committed changes will be 'undone' by this merge.

If you are using TortoiseSVN, right-click the file select Merge, then Merge a Range of Revisions. In the log box type in 140-150 and click the Reverse Checkbox. After that, commit as usual. This will perform the same operation as Jon's example.

With eclipse and subclipse, you can right-click on your project, Team/Show History, then select then revisions you want to "undo" and with another right-click select "Revert changes from Selected Revisions".

To revert from head revision you can also write svn merge -r HEAD:140.

svn - How do I return to an older version of our code in Subversion? -...

svn backport
Rectangle 27 668

Basically you need to "merge backwards" - apply a diff between the current and previous version to the current version (so you end up with a working copy looking like the old version) and then commit again. So for example to go from revision 150 (current) back to revision 140:

svn update
svn merge -r 150:140 .
svn commit -m "Rolled back to r140"

but the merge is not override my changes and the new revision.

Which changes? Any changes you don't want in your working copy can just be removed with svn revert. Committed changes will be 'undone' by this merge.

If you are using TortoiseSVN, right-click the file select Merge, then Merge a Range of Revisions. In the log box type in 140-150 and click the Reverse Checkbox. After that, commit as usual. This will perform the same operation as Jon's example.

With eclipse and subclipse, you can right-click on your project, Team/Show History, then select then revisions you want to "undo" and with another right-click select "Revert changes from Selected Revisions".

To revert from head revision you can also write svn merge -r HEAD:140.

svn - How do I return to an older version of our code in Subversion? -...

svn backport
Rectangle 27 202

Actually, there are no examples at all. Here is my working code. Recording is triggered by the user pressing a button on the navBar. The recording uses cd quality (44100 samples), stereo (2 channels) linear pcm. Beware: if you want to use a different format, especially an encoded one, make sure you fully understand how to set the AVAudioRecorder settings (read carefully the audio types documentation), otherwise you will never be able to initialize it correctly. One more thing. In the code, I am not showing how to handle metering data, but you can figure it out easily. Finally, note that the AVAudioRecorder method deleteRecording as of this writing crashes your application. This is why I am removing the recorded file through the File Manager. When recording is done, I save the recorded audio as NSData in the currently edited object using KVC.

#define DOCUMENTS_FOLDER [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]


- (void) startRecording{

UIBarButtonItem *stopButton = [[UIBarButtonItem alloc] initWithTitle:@"Stop" style:UIBarButtonItemStyleBordered  target:self action:@selector(stopRecording)];
self.navigationItem.rightBarButtonItem = stopButton;
[stopButton release];

AVAudioSession *audioSession = [AVAudioSession sharedInstance];
NSError *err = nil;
[audioSession setCategory :AVAudioSessionCategoryPlayAndRecord error:&err];
if(err){
    NSLog(@"audioSession: %@ %d %@", [err domain], [err code], [[err userInfo] description]);
    return;
}
[audioSession setActive:YES error:&err];
err = nil;
if(err){
    NSLog(@"audioSession: %@ %d %@", [err domain], [err code], [[err userInfo] description]);
    return;
}

recordSetting = [[NSMutableDictionary alloc] init];

[recordSetting setValue :[NSNumber numberWithInt:kAudioFormatLinearPCM] forKey:AVFormatIDKey];
[recordSetting setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey]; 
[recordSetting setValue:[NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey];

[recordSetting setValue :[NSNumber numberWithInt:16] forKey:AVLinearPCMBitDepthKey];
[recordSetting setValue :[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsBigEndianKey];
[recordSetting setValue :[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsFloatKey];



// Create a new dated file
NSDate *now = [NSDate dateWithTimeIntervalSinceNow:0];
NSString *caldate = [now description];
recorderFilePath = [[NSString stringWithFormat:@"%@/%@.caf", DOCUMENTS_FOLDER, caldate] retain];

NSURL *url = [NSURL fileURLWithPath:recorderFilePath];
err = nil;
recorder = [[ AVAudioRecorder alloc] initWithURL:url settings:recordSetting error:&err];
if(!recorder){
    NSLog(@"recorder: %@ %d %@", [err domain], [err code], [[err userInfo] description]);
    UIAlertView *alert =
    [[UIAlertView alloc] initWithTitle: @"Warning"
                               message: [err localizedDescription]
                              delegate: nil
                     cancelButtonTitle:@"OK"
                     otherButtonTitles:nil];
    [alert show];
    [alert release];
    return;
}

//prepare to record
[recorder setDelegate:self];
[recorder prepareToRecord];
recorder.meteringEnabled = YES;

BOOL audioHWAvailable = audioSession.inputIsAvailable;
if (! audioHWAvailable) {
    UIAlertView *cantRecordAlert =
    [[UIAlertView alloc] initWithTitle: @"Warning"
                               message: @"Audio input hardware not available"
                              delegate: nil
                     cancelButtonTitle:@"OK"
                     otherButtonTitles:nil];
    [cantRecordAlert show];
    [cantRecordAlert release]; 
    return;
}

// start recording
[recorder recordForDuration:(NSTimeInterval) 10];

}

- (void) stopRecording{

[recorder stop];

NSURL *url = [NSURL fileURLWithPath: recorderFilePath];
NSError *err = nil;
NSData *audioData = [NSData dataWithContentsOfFile:[url path] options: 0 error:&err];
if(!audioData)
    NSLog(@"audio data: %@ %d %@", [err domain], [err code], [[err userInfo] description]);
[editedObject setValue:[NSData dataWithContentsOfURL:url] forKey:editedFieldKey];   

//[recorder deleteRecording];


NSFileManager *fm = [NSFileManager defaultManager];

err = nil;
[fm removeItemAtPath:[url path] error:&err];
if(err)
    NSLog(@"File Manager: %@ %d %@", [err domain], [err code], [[err userInfo] description]);



UIBarButtonItem *startButton = [[UIBarButtonItem alloc] initWithTitle:@"Record" style:UIBarButtonItemStyleBordered  target:self action:@selector(startRecording)];
self.navigationItem.rightBarButtonItem = startButton;
[startButton release];

}

- (void)audioRecorderDidFinishRecording:(AVAudioRecorder *) aRecorder successfully:(BOOL)flag
{

NSLog (@"audioRecorderDidFinishRecording:successfully:");
// your actions here

}

I think I am close to getting your code to work, but I am struggling with the delegate stuff. I am pretty new to Objective C and still have not gotten my head around the proper way to do the delegate for something like this. I have my delegate trying to implement NSObject <AVAudioRecorder>, but I don't think I am doing it right. Would it be too much trouble to post the delegate code also? Thanks.

I just finally got it working by adding this to my delegate class @protocol AVAudioRecorder @optional - (void)audioRecorderBeginInterruption:(AVAudioRecorder *)recorder; - (void)audioRecorderDidFinishRecording:(AVAudioRecorder *)recorder successfully:(BOOL)flag; - (void)audioRecorderEncodeErrorDidOccur:(AVAudioRecorder *)recorder error:(NSError *)error; - (void)audioRecorderEndInterruption:(AVAudioRecorder *)recorder; It seems to work, but I don't know if this is best practice or not. Now I need to persist it to a local data store and play it back among other things.

some questions: editedObject & editedFieldKey in stopRecording undefined. Can you give me some lights?

@Olie, they are functionally the same. I adapted my original code in which I was not using the current date, so I had already in my code a statement like recordingDate = [NSDate dateWithTimeIntervalSinceNow:lastEvent]. I just changed it to the one you saw in the code snippet, but, being lazy, I did not rewrite the statement ;-)

ios - How do I record audio on iPhone with AVAudioRecorder? - Stack Ov...

ios objective-c iphone audio recording
Rectangle 27 202

Actually, there are no examples at all. Here is my working code. Recording is triggered by the user pressing a button on the navBar. The recording uses cd quality (44100 samples), stereo (2 channels) linear pcm. Beware: if you want to use a different format, especially an encoded one, make sure you fully understand how to set the AVAudioRecorder settings (read carefully the audio types documentation), otherwise you will never be able to initialize it correctly. One more thing. In the code, I am not showing how to handle metering data, but you can figure it out easily. Finally, note that the AVAudioRecorder method deleteRecording as of this writing crashes your application. This is why I am removing the recorded file through the File Manager. When recording is done, I save the recorded audio as NSData in the currently edited object using KVC.

#define DOCUMENTS_FOLDER [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]


- (void) startRecording{

UIBarButtonItem *stopButton = [[UIBarButtonItem alloc] initWithTitle:@"Stop" style:UIBarButtonItemStyleBordered  target:self action:@selector(stopRecording)];
self.navigationItem.rightBarButtonItem = stopButton;
[stopButton release];

AVAudioSession *audioSession = [AVAudioSession sharedInstance];
NSError *err = nil;
[audioSession setCategory :AVAudioSessionCategoryPlayAndRecord error:&err];
if(err){
    NSLog(@"audioSession: %@ %d %@", [err domain], [err code], [[err userInfo] description]);
    return;
}
[audioSession setActive:YES error:&err];
err = nil;
if(err){
    NSLog(@"audioSession: %@ %d %@", [err domain], [err code], [[err userInfo] description]);
    return;
}

recordSetting = [[NSMutableDictionary alloc] init];

[recordSetting setValue :[NSNumber numberWithInt:kAudioFormatLinearPCM] forKey:AVFormatIDKey];
[recordSetting setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey]; 
[recordSetting setValue:[NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey];

[recordSetting setValue :[NSNumber numberWithInt:16] forKey:AVLinearPCMBitDepthKey];
[recordSetting setValue :[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsBigEndianKey];
[recordSetting setValue :[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsFloatKey];



// Create a new dated file
NSDate *now = [NSDate dateWithTimeIntervalSinceNow:0];
NSString *caldate = [now description];
recorderFilePath = [[NSString stringWithFormat:@"%@/%@.caf", DOCUMENTS_FOLDER, caldate] retain];

NSURL *url = [NSURL fileURLWithPath:recorderFilePath];
err = nil;
recorder = [[ AVAudioRecorder alloc] initWithURL:url settings:recordSetting error:&err];
if(!recorder){
    NSLog(@"recorder: %@ %d %@", [err domain], [err code], [[err userInfo] description]);
    UIAlertView *alert =
    [[UIAlertView alloc] initWithTitle: @"Warning"
                               message: [err localizedDescription]
                              delegate: nil
                     cancelButtonTitle:@"OK"
                     otherButtonTitles:nil];
    [alert show];
    [alert release];
    return;
}

//prepare to record
[recorder setDelegate:self];
[recorder prepareToRecord];
recorder.meteringEnabled = YES;

BOOL audioHWAvailable = audioSession.inputIsAvailable;
if (! audioHWAvailable) {
    UIAlertView *cantRecordAlert =
    [[UIAlertView alloc] initWithTitle: @"Warning"
                               message: @"Audio input hardware not available"
                              delegate: nil
                     cancelButtonTitle:@"OK"
                     otherButtonTitles:nil];
    [cantRecordAlert show];
    [cantRecordAlert release]; 
    return;
}

// start recording
[recorder recordForDuration:(NSTimeInterval) 10];

}

- (void) stopRecording{

[recorder stop];

NSURL *url = [NSURL fileURLWithPath: recorderFilePath];
NSError *err = nil;
NSData *audioData = [NSData dataWithContentsOfFile:[url path] options: 0 error:&err];
if(!audioData)
    NSLog(@"audio data: %@ %d %@", [err domain], [err code], [[err userInfo] description]);
[editedObject setValue:[NSData dataWithContentsOfURL:url] forKey:editedFieldKey];   

//[recorder deleteRecording];


NSFileManager *fm = [NSFileManager defaultManager];

err = nil;
[fm removeItemAtPath:[url path] error:&err];
if(err)
    NSLog(@"File Manager: %@ %d %@", [err domain], [err code], [[err userInfo] description]);



UIBarButtonItem *startButton = [[UIBarButtonItem alloc] initWithTitle:@"Record" style:UIBarButtonItemStyleBordered  target:self action:@selector(startRecording)];
self.navigationItem.rightBarButtonItem = startButton;
[startButton release];

}

- (void)audioRecorderDidFinishRecording:(AVAudioRecorder *) aRecorder successfully:(BOOL)flag
{

NSLog (@"audioRecorderDidFinishRecording:successfully:");
// your actions here

}

I think I am close to getting your code to work, but I am struggling with the delegate stuff. I am pretty new to Objective C and still have not gotten my head around the proper way to do the delegate for something like this. I have my delegate trying to implement NSObject <AVAudioRecorder>, but I don't think I am doing it right. Would it be too much trouble to post the delegate code also? Thanks.

I just finally got it working by adding this to my delegate class @protocol AVAudioRecorder @optional - (void)audioRecorderBeginInterruption:(AVAudioRecorder *)recorder; - (void)audioRecorderDidFinishRecording:(AVAudioRecorder *)recorder successfully:(BOOL)flag; - (void)audioRecorderEncodeErrorDidOccur:(AVAudioRecorder *)recorder error:(NSError *)error; - (void)audioRecorderEndInterruption:(AVAudioRecorder *)recorder; It seems to work, but I don't know if this is best practice or not. Now I need to persist it to a local data store and play it back among other things.

some questions: editedObject & editedFieldKey in stopRecording undefined. Can you give me some lights?

@Olie, they are functionally the same. I adapted my original code in which I was not using the current date, so I had already in my code a statement like recordingDate = [NSDate dateWithTimeIntervalSinceNow:lastEvent]. I just changed it to the one you saw in the code snippet, but, being lazy, I did not rewrite the statement ;-)

ios - How do I record audio on iPhone with AVAudioRecorder? - Stack Ov...

ios objective-c iphone audio recording
Rectangle 27 200

Actually, there are no examples at all. Here is my working code. Recording is triggered by the user pressing a button on the navBar. The recording uses cd quality (44100 samples), stereo (2 channels) linear pcm. Beware: if you want to use a different format, especially an encoded one, make sure you fully understand how to set the AVAudioRecorder settings (read carefully the audio types documentation), otherwise you will never be able to initialize it correctly. One more thing. In the code, I am not showing how to handle metering data, but you can figure it out easily. Finally, note that the AVAudioRecorder method deleteRecording as of this writing crashes your application. This is why I am removing the recorded file through the File Manager. When recording is done, I save the recorded audio as NSData in the currently edited object using KVC.

#define DOCUMENTS_FOLDER [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]


- (void) startRecording{

UIBarButtonItem *stopButton = [[UIBarButtonItem alloc] initWithTitle:@"Stop" style:UIBarButtonItemStyleBordered  target:self action:@selector(stopRecording)];
self.navigationItem.rightBarButtonItem = stopButton;
[stopButton release];

AVAudioSession *audioSession = [AVAudioSession sharedInstance];
NSError *err = nil;
[audioSession setCategory :AVAudioSessionCategoryPlayAndRecord error:&err];
if(err){
    NSLog(@"audioSession: %@ %d %@", [err domain], [err code], [[err userInfo] description]);
    return;
}
[audioSession setActive:YES error:&err];
err = nil;
if(err){
    NSLog(@"audioSession: %@ %d %@", [err domain], [err code], [[err userInfo] description]);
    return;
}

recordSetting = [[NSMutableDictionary alloc] init];

[recordSetting setValue :[NSNumber numberWithInt:kAudioFormatLinearPCM] forKey:AVFormatIDKey];
[recordSetting setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey]; 
[recordSetting setValue:[NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey];

[recordSetting setValue :[NSNumber numberWithInt:16] forKey:AVLinearPCMBitDepthKey];
[recordSetting setValue :[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsBigEndianKey];
[recordSetting setValue :[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsFloatKey];



// Create a new dated file
NSDate *now = [NSDate dateWithTimeIntervalSinceNow:0];
NSString *caldate = [now description];
recorderFilePath = [[NSString stringWithFormat:@"%@/%@.caf", DOCUMENTS_FOLDER, caldate] retain];

NSURL *url = [NSURL fileURLWithPath:recorderFilePath];
err = nil;
recorder = [[ AVAudioRecorder alloc] initWithURL:url settings:recordSetting error:&err];
if(!recorder){
    NSLog(@"recorder: %@ %d %@", [err domain], [err code], [[err userInfo] description]);
    UIAlertView *alert =
    [[UIAlertView alloc] initWithTitle: @"Warning"
                               message: [err localizedDescription]
                              delegate: nil
                     cancelButtonTitle:@"OK"
                     otherButtonTitles:nil];
    [alert show];
    [alert release];
    return;
}

//prepare to record
[recorder setDelegate:self];
[recorder prepareToRecord];
recorder.meteringEnabled = YES;

BOOL audioHWAvailable = audioSession.inputIsAvailable;
if (! audioHWAvailable) {
    UIAlertView *cantRecordAlert =
    [[UIAlertView alloc] initWithTitle: @"Warning"
                               message: @"Audio input hardware not available"
                              delegate: nil
                     cancelButtonTitle:@"OK"
                     otherButtonTitles:nil];
    [cantRecordAlert show];
    [cantRecordAlert release]; 
    return;
}

// start recording
[recorder recordForDuration:(NSTimeInterval) 10];

}

- (void) stopRecording{

[recorder stop];

NSURL *url = [NSURL fileURLWithPath: recorderFilePath];
NSError *err = nil;
NSData *audioData = [NSData dataWithContentsOfFile:[url path] options: 0 error:&err];
if(!audioData)
    NSLog(@"audio data: %@ %d %@", [err domain], [err code], [[err userInfo] description]);
[editedObject setValue:[NSData dataWithContentsOfURL:url] forKey:editedFieldKey];   

//[recorder deleteRecording];


NSFileManager *fm = [NSFileManager defaultManager];

err = nil;
[fm removeItemAtPath:[url path] error:&err];
if(err)
    NSLog(@"File Manager: %@ %d %@", [err domain], [err code], [[err userInfo] description]);



UIBarButtonItem *startButton = [[UIBarButtonItem alloc] initWithTitle:@"Record" style:UIBarButtonItemStyleBordered  target:self action:@selector(startRecording)];
self.navigationItem.rightBarButtonItem = startButton;
[startButton release];

}

- (void)audioRecorderDidFinishRecording:(AVAudioRecorder *) aRecorder successfully:(BOOL)flag
{

NSLog (@"audioRecorderDidFinishRecording:successfully:");
// your actions here

}

I think I am close to getting your code to work, but I am struggling with the delegate stuff. I am pretty new to Objective C and still have not gotten my head around the proper way to do the delegate for something like this. I have my delegate trying to implement NSObject <AVAudioRecorder>, but I don't think I am doing it right. Would it be too much trouble to post the delegate code also? Thanks.

I just finally got it working by adding this to my delegate class @protocol AVAudioRecorder @optional - (void)audioRecorderBeginInterruption:(AVAudioRecorder *)recorder; - (void)audioRecorderDidFinishRecording:(AVAudioRecorder *)recorder successfully:(BOOL)flag; - (void)audioRecorderEncodeErrorDidOccur:(AVAudioRecorder *)recorder error:(NSError *)error; - (void)audioRecorderEndInterruption:(AVAudioRecorder *)recorder; It seems to work, but I don't know if this is best practice or not. Now I need to persist it to a local data store and play it back among other things.

some questions: editedObject & editedFieldKey in stopRecording undefined. Can you give me some lights?

@Olie, they are functionally the same. I adapted my original code in which I was not using the current date, so I had already in my code a statement like recordingDate = [NSDate dateWithTimeIntervalSinceNow:lastEvent]. I just changed it to the one you saw in the code snippet, but, being lazy, I did not rewrite the statement ;-)

ios - How do I record audio on iPhone with AVAudioRecorder? - Stack Ov...

ios objective-c iphone audio recording
Rectangle 27 2

It's been a while but I was working on a similar problem. I have an example here. Maybe this will help.

The program is using PySide, shouldn't be a problem though.

To run the program

python pyStocker.py

You would see a widget popup and in the top left you'll see a TextEdit box. Just enter GOOG or some other valid stock symbol and press enter. The graph will populate with the stock's data. The slider bar at the bottom changes the graph real-time.

python - Matplotlib interactive graph embedded in PyQt - Stack Overflo...

python graph matplotlib pyqt4 interactive
Rectangle 27 10

Well if you were working with the site developers to create a solution for your application, then you would use ObjectForScripting to communicate between JavaScript and the app. There a good article here, and another question which might be helpful here.

However as I understand your question, the site is an arbitrary third party site with no affiliation to your application, and you want to auto-fill some form values and submit the form within your code.

To do this you can handle the LoadCompleted event of the WebBrowser. This is called when the loaded document readyState is changed to completed. You can therefore use this event as a hook to then set/read the document form values. Note you will need to add a reference to Microsoft mshtml in the project.

The following is an MVVM style (PRISM) command, which allows an event to bind directly to the ViewModel using behaviors. This is equivalent to registering an event handler in code-behind.

public ICommand LoadCompleted
{
    get
    {
        return new EventToCommandWithSender<NavigationEventArgs>(
            (s,e) => { 

               WebBrowser browser = (WebBrowser) sender;
               // false if nested frame
               if (e.IsNavigationInitiator)
               {
                   mshtml.IHTMLDocument2 doc = (mshtml.IHTMLDocument2)browser.Document;
                   // always completed
                   var readyState = doc.readyState;
                   // populate form
                   var name = doc.body.document.getElementById("username");
                   name.value = "@TheCodeKing";
                   // submit form
                   var submit = doc.body.document.getElementById("submit");
                   submit.Click();
                }
        });
    }
}

Unfortunately the NavigationEventArgs don't provide a way to access the HTML document or request data. It does contain a WebRequest property but this has not been implemented, and will always be null. In my example I've assumed a custom EventToCommandWithSender class which providers the sender as well as the event ARGs when the event fires, but it's down to your own implementation to get access to the sender.

I can see how this can be used to get values, but it is also possible to use this method to set values, and submit the form via javascript?

Actually I do have a question about this, would I have to use attached behaviors to bind a command to the navigating event, or is there a direct way to do that?

Yes I think you can use the document loaded event to then call into JavaScript and post the form. I haven't tried it through. You would use attached behaviours for events. I think Prism offers an alternative, but it's been a while since I've used it.

Doesn't the document loaded event occur when html rendering it complete, before javascript has finished executing? I will research prism to see if it can do this. Your answer is helpful, but I don't think it is complete.

The WebBrowser control DocumentLoaded event occurs when the control has finished downloading content and rendered the page. It gives you a hook for parts 2 & 3 of your question. I'll clarify when back at a computer (when you say ReadyState what do you mean?). Prism is a framework for building WPF applications to separate concerns (nothing to do with client-side code). I wasn't sure if you were using it.

c# - How to use Javascript on a WPF WebBrowser Control via MVVM - Stac...

c# javascript wpf webbrowser-control
Rectangle 27 88

I found this question when I was moving from a development environment to a production one on an application that I am working on. This process involved the creation of a new profile, a new app ID, etc. I created the app ID and a profile, but the Team Agent had to configure the push notifications. I ran into the problem of "no valid 'aps-environment' entitlement string found for application" when I tried to resume testing with the new profile (after the app had been configured for push notifications). I then remembered reading a little caveat in the documentation:

"You have to modify the profile in some way (for example, toggle an option) for the portal to generate a new provisioning profile. If the profile isn't so "dirtied", you're given the profile without the push entitlements."

For me, "dirtying" the provisioning profile and reinstalling it was all that was needed to fix the issue. Per the documentation, this was required because the provisioning profile was created before the app was configured for push notifications. This may or may not help anyone, but this probably explains (and eliminates) the need to manually add anything to the provisioning profile.

Totally worked for me, thanks! Absolutely unacceptable that the Apple dev site work so shoddily.

Yes it worked for me. Whenever you update App-id,update your provisioning profiles. You will not get any intimation from Apple to do so. But you have to do it. No need to edit any XML's or entitlements

I ran into this issue when I deleted my development app from my IPad then tried to run it again. I followed the instructions for "dirtying" the provisioning profile, redownloaded via organizer, closed and opened xcode, rebuilt and deployed, then it worked. This is a lame workaround.

This problem is still present and caused me hours of problems with CloudKit. Checking the provisioning profile revealed the "aps-environment" key was missingI regenerated the provisioning profiles many times tried deleting them to no avail. Eventually I managed to dirty the provisioning profile by changing the iCloud containers the app could access.The provisioning profile which works still doesn't have the aps-environment key though.

xcode - Bundle Identifier and push certificate... aps-environment enti...

xcode push ios-provisioning settings.bundle
Rectangle 27 88

I found this question when I was moving from a development environment to a production one on an application that I am working on. This process involved the creation of a new profile, a new app ID, etc. I created the app ID and a profile, but the Team Agent had to configure the push notifications. I ran into the problem of "no valid 'aps-environment' entitlement string found for application" when I tried to resume testing with the new profile (after the app had been configured for push notifications). I then remembered reading a little caveat in the documentation:

"You have to modify the profile in some way (for example, toggle an option) for the portal to generate a new provisioning profile. If the profile isn't so "dirtied", you're given the profile without the push entitlements."

For me, "dirtying" the provisioning profile and reinstalling it was all that was needed to fix the issue. Per the documentation, this was required because the provisioning profile was created before the app was configured for push notifications. This may or may not help anyone, but this probably explains (and eliminates) the need to manually add anything to the provisioning profile.

Totally worked for me, thanks! Absolutely unacceptable that the Apple dev site work so shoddily.

Yes it worked for me. Whenever you update App-id,update your provisioning profiles. You will not get any intimation from Apple to do so. But you have to do it. No need to edit any XML's or entitlements

I ran into this issue when I deleted my development app from my IPad then tried to run it again. I followed the instructions for "dirtying" the provisioning profile, redownloaded via organizer, closed and opened xcode, rebuilt and deployed, then it worked. This is a lame workaround.

This problem is still present and caused me hours of problems with CloudKit. Checking the provisioning profile revealed the "aps-environment" key was missingI regenerated the provisioning profiles many times tried deleting them to no avail. Eventually I managed to dirty the provisioning profile by changing the iCloud containers the app could access.The provisioning profile which works still doesn't have the aps-environment key though.

xcode - Bundle Identifier and push certificate... aps-environment enti...

xcode push ios-provisioning settings.bundle
Rectangle 27 2

First Check your hash key with these lines of code given by me at this link Facebook Integration in Android Application and if it is not working yet then please check that your Facebook Android Application in mobile is updated. If the application is not updated update your Facebook application and try to post.

android - Facebook login not working if Facebook native application in...

android facebook facebook-android-sdk facebook-login
Rectangle 27 3

Why is it working fine when i click somewhere off my application form but hangs when i click inside my form?

You're not posting the message to other windows when you click on them. First you should ask yourself, "what happens if I posted a message in my hook callback to all windows which are posted a WM_LBUTTONUP?".

PostMessage(FindWindow('TShowMouseClick', nil), MouseHookMessage, MsgID, 0);

in your dll code, with this:

PostMessage(PMouseHookStruct(Data).hwnd, MouseHookMessage, MsgID, 0);

It doesn't matter if the other applications would know or not what MouseHookMessage is, they will ignore the message. Launch your application and click the mouse wildly to other windows. Generally nothing will happen. Unless you click in the client area of any Delphi application. You'll instantly freeze it.

The answer to this question lies in both how a VCL message loop runs and how a WH_MOUSE hook works. A quote from MouseProc callback function's documentation.

[..] The system calls this function whenever an application calls the GetMessage or PeekMessage function and there is a mouse message to be processed.

Suppose you launch your application and the mouse is hooked, then you hover the mouse on your form and wait till your application calls 'WaitMessage', that it is idle. Now click in the client area to generate mouse messages. What happens is that the OS places messages to your application's main thread's message queue. And what your application does is that to remove and dispatch these messages with PeekMessage. This is where applications differ. The VCL first calls 'PeekMessage' with 'PM_NOREMOVE' passed in 'wRemoveMsg' parameter, while most other applications either removes the message with a call to 'PeekMessage' or do the same by using 'GetMessage'.

Now suppose it is 'WM_LBUTTONUP's turn. Refer to the quote above. As soon as PeekMessage is called, the OS calls the MouseProc callback. The call happens from 'user32.dll', that is, when your hook callback is called the statement following the 'PeekMessage' is not executed yet. Also, remember the VCL loop, the message is still in the queue, it has not been removed. Now, your callback function posts a message to the same message queue and returns. Execution returns to the VCL message loop and VCL again calls 'PeekMessage', this time to remove and dispatch the message, but instead of removing the 'WM_LBUTTONUP', it removes the custom message that you posted. 'WM_LBUTTONUP' remains in the queue. After the custom message is dispatched, since 'WM_LBUTTONUP' is still in the queue, 'PeekMessage' is again called, and again the OS calls the callback so that the callback can post another custom message to be removed instead of the mouse message. This loop effectively freezes the application.

To resolve, either post your message to a different thread that has its own message loop which would in some way synchronize with the main thread, or, I would not especially advice it but, instead of posting the message, send it. As an alternative you can remove the 'WM_LBUTTONUP' message yourself from the queue if one exists:

procedure TShowMouseClick.WndProc(var Message: TMessage);
begin
    inherited WndProc(Message);
    if (Message.Msg = HookCommon.MouseHookMessage) and
        (Message.WParam = $202) then begin
      if PeekMessage(Msg, Handle, WM_LBUTTONUP, WM_LBUTTONUP, PM_REMOVE) then
        DispatchMessage(Msg);  // or eat if you don't need it.

     ..

end;

The disadvantage to this approach is that, the PeekMessage itself, as mentioned above, will cause another custom message to be posted, so you'll be receiving those in pairs.

Thank you, this all makes sense and i tried thinking what could be done. In the DLL i have added the check of whether the Findwindow() returned handle is the same as the PMouseHookStruct has, at first it seemed to work, i rapidly clicked on the drawn circles and application continued to run. But then i decided to click on the static text that shows active timer count. It froze. Meaning that static text has its own window handle which is not equal to main form. Back to the drawing board

You're welcome. You can use a label instead of a static, or test if the struct window is a child window and a static, and if it is compare its parent with the FindWindow window. Or try one of the suggestions in the answer..

Sending instead of posting a message seems to have solved the issue. Now clicking the static text it doesn't hang. I will definitely need to read more about posting and sending messages and what effects can it cause. It may be a good solution in my case but it is interesting to know what would happen in different situations. So far i know that posting a message doesnt wait for response, while sending it - waits.

@user - Correct, what this means is that you want to return really quick, otherwise whole system might feel unresponsive, even the OS might kick your hook out of the hook chain.

delphi - Window receives infinite amount of messages when mouse is hoo...

delphi hook messages
Rectangle 27 5

The recommended approach is to use UIWebView in your application and create post request using NSURLRequest and NSURLConnection. It is pretty easy to create a post request and fire the request. Since you have already figured this out and you dont want to use this approach, only alternative is by creating a temporary html file as mentioned here. You can try with the approach they are following and check if it is working in your case.

As per that link, you have to write a temporary html file. This html file will have an onLoad() javascript which immediately sends the POST, and a button for users that don't have javascript enabled. You can create NSURL object as [NSURL fileURLWithPath:path]; from this file.

Another solution is by creating a one time key from the webserver and pass it to safari via HTTPS request as mentioned here.

iphone - Open Url hosted using POST method in Safari using sharedAppli...

iphone objective-c ios xcode uiapplication
Rectangle 27 3

By default, Java opens it in the working directory of your application (this behavior actually depends on the OS used). To load a file, do:

Properties props = new java.util.Properties();
FileInputStream fis new FileInputStream("myfile.txt");
props.load(fis)

As such, any file extension can be used for property file. Additionally, the file can also be stored anywhere, as long as you can use a FileInputStream.

On a related note if you use a modern framework, the framework may provide additionnal ways of opening a property file. For example, Spring provide a ClassPathResource to load a property file using a package name from inside a JAR file.

As for iterating through the properties, once the properties are loaded they are stored in the java.util.Properties object, which offer the propertyNames() method.

properties - How to use Java property files? - Stack Overflow

java properties
Rectangle 27 137

If you adhere the *nix filesystem path rules (i.e. you use exclusively forward slashes as in /path/to/files), then it will work on Windows as well without the need to fiddle around with ugly File.separator string-concatenations. It would however only be scanned on the same working disk as from where this command is been invoked. So if Tomcat is for example installed on C: then the /path/to/files would actually point to C:\path\to\files.

If the files are all located outside the webapp, and you want to have Tomcat's DefaultServlet to handle them, then all you basically need to do in Tomcat is to add the following Context element to /conf/server.xml inside <Host> tag:

<Context docBase="/path/to/files" path="/files" />

This way they'll be accessible through http://example.com/files/.... GlassFish/Payara configuration example can be found here and WildFly configuration example can be found here.

If you want to have control over reading/writing files yourself, then you need to create a Servlet for this which basically just gets an InputStream of the file in flavor of for example FileInputStream and writes it to the OutputStream of the HttpServletResponse.

On the response, you should set the Content-Type header so that the client knows which application to associate with the provided file. And, you should set the Content-Length header so that the client can calculate the download progress, otherwise it will be unknown. And, you should set the Content-Disposition header to attachment if you want a Save As dialog, otherwise the client will attempt to display it inline. Finally just write the file content to the response output stream.

Here's a basic example of such a servlet:

@WebServlet("/files/*")
public class FileServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException
    {
        String filename = URLDecoder.decode(request.getPathInfo().substring(1), "UTF-8");
        File file = new File("/path/to/files", filename);
        response.setHeader("Content-Type", getServletContext().getMimeType(filename));
        response.setHeader("Content-Length", String.valueOf(file.length()));
        response.setHeader("Content-Disposition", "inline; filename=\"" + file.getName() + "\"");
        Files.copy(file.toPath(), response.getOutputStream());
    }

}

When mapped on an url-pattern of for example /files/*, then you can call it by http://example.com/files/image.png. This way you can have more control over the requests than the DefaultServlet does, such as providing a default image (i.e. if (!file.exists()) file = new File("/path/to/files", "404.gif") or so). Also using the request.getPathInfo() is preferred above request.getParameter() because it is more SEO friendly and otherwise IE won't pick the correct filename during Save As.

You can reuse the same logic for serving files from database. Simply replace new FileInputStream() by ResultSet#getInputStream().

@SalutonMondo: the way with least effort.

<Context docBase="/path/to/images" path="/images" />
C:\install\apache-tomcat-8.0.26\webapps\tmp] is not valid

tomcat - Simplest way to serve static data from outside the applicatio...

tomcat java-ee servlets static-content
Rectangle 27 4

Definitely easier to maintain if you put it in a stored procedure. If there's difficult logic involved that will potentially change in the future it is definitely a good idea to put it in the database when you have multiple clients connecting. For example I'm working on an application right now that has an end user web interface and an administrative desktop application, both of which share a database (obviously) and I'm trying to keep as much logic on the database as possible. This is a perfect example of the DRY principle.

c# - What are the pros and cons to keeping SQL in Stored Procs versus ...

c# sql sql-server stored-procedures
Rectangle 27 11

I managed to get a working spec/spec_helper.rb configuration that executes SimpleCov correctly simply using the $ rspec spec/ command thanks to a comment on the Github issue that sent me to this blog entry, and its example spec/spec_helper.rb. All reasons why this works are contained in the (very detailed!) blog entry. Replace SampleApp with the name of your application.

If you use Travis-CI, don't use this code as-is because you'll likely get a undefined method 'root' for Rails:Module (NoMethodError) error. If you know how to fix this, please share.

I got Travis CI to work by essentially putting everything in the Spork.each_run block, which seems to have slowed down the tests significantly. There must be a better way to do this, or it just doesn't seem worth it for the sake of not having to run $ rspec --no-drb spec/ once to get the SimpleCov report...

After using this config for a few months, I've come to realize that it is slower than I thought. Part of that is the realisation that it seems that Spork can slow down test suites, and is best for fast iterative focused testing vs always running entire test suites with it. The following SO questions and blog posts got me to the spec_helper.rb file below, which can run SimpleCov with or without Spork, runs faster than before, and works with Capybara 2.0.

require 'rubygems'
require 'spork'
require 'simplecov'
#uncomment the following line to use spork with the debugger
#require 'spork/ext/ruby-debug'

Spork.prefork do
  ENV["RAILS_ENV"] ||= 'test'
  unless ENV['DRB']
    SimpleCov.start 'rails'
    require File.expand_path("../../config/environment", __FILE__)
  end

  require 'rspec/rails'
  require 'rspec/autorun'
  require 'capybara/rails'
  require 'capybara/rspec'

  # files to preload based on results of Kernel override code below
  # ie they took more than 100 ms to load
  require "sprockets"
  require "sprockets/eco_template"
  require "sprockets/base"
  require "active_record/connection_adapters/postgresql_adapter"
  require "tzinfo"
  require "tilt"
  require "journey"
  require "journey/router"
  require "haml/template"

  RSpec.configure do |config|
    config.mock_with :rspec

    # If you're not using ActiveRecord, or you'd prefer not to run each of your
    # examples within a transaction, remove the following line or assign false
    # instead of true.
    config.use_transactional_fixtures = false

    # If true, the base class of anonymous controllers will be inferred
    # automatically. This will be the default behavior in future versions of
    # rspec-rails.
    config.infer_base_class_for_anonymous_controllers = false

    config.include FactoryGirl::Syntax::Methods

    config.before :suite do
      # PerfTools::CpuProfiler.start("/tmp/rspec_profile")
      DatabaseCleaner.strategy = :transaction
      DatabaseCleaner.clean_with(:truncation)
    end

    # Request specs cannot use a transaction because Capybara runs in a
    # separate thread with a different database connection.
    config.before type: :request do
      DatabaseCleaner.strategy = :truncation
    end

    # Reset so other non-request specs don't have to deal with slow truncation.
    config.after type: :request  do
      DatabaseCleaner.strategy = :transaction
    end

    RESERVED_IVARS = %w(@loaded_fixtures)
    last_gc_run = Time.now

    config.before(:each) do
      GC.disable
    end

    config.before do
      DatabaseCleaner.start
    end

    config.after do
      DatabaseCleaner.clean
    end

    # Release instance variables and trigger garbage collection
    # manually every second to make tests faster
    # http://blog.carbonfive.com/2011/02/02/crank-your-specs/
    config.after(:each) do
      (instance_variables - RESERVED_IVARS).each do |ivar|
        instance_variable_set(ivar, nil)
      end
      if Time.now - last_gc_run > 1.0
        GC.enable
        GC.start
        last_gc_run = Time.now
      end
    end

    config.after :suite do
      # PerfTools::CpuProfiler.stop

      # REPL to query ObjectSpace
      # http://blog.carbonfive.com/2011/02/02/crank-your-specs/
      # while true
      #   '> '.display
      #   begin
      #     puts eval($stdin.gets)
      #   rescue Exception => e
      #     puts e.message
      #   end
      # end
    end
  end

  # Find files to put into preload
  # http://www.opinionatedprogrammer.com/2011/02/profiling-spork-for-faster-start-up-time/
  # module Kernel
  #   def require_with_trace(*args)
  #     start = Time.now.to_f
  #     @indent ||= 0
  #     @indent += 2
  #     require_without_trace(*args)
  #     @indent -= 2
  #     Kernel::puts "#{' '*@indent}#{((Time.now.to_f - start)*1000).to_i} #{args[0]}"
  #   end
  #   alias_method_chain :require, :trace
  # end
end

Spork.each_run do
  # This code will be run each time you run your specs.
  if ENV['DRB']
    SimpleCov.start 'rails'
    SampleApp::Application.initialize!
    class SampleApp::Application
      def initialize!; end
    end
  end

  # Requires supporting ruby files with custom matchers and macros, etc,
  # in spec/support/ and its subdirectories.
  Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
  FactoryGirl.reload
  I18n.backend.reload!
end

SimpleCov reports not generating in Rails 3 app after running RSpec te...

ruby-on-rails-3 rspec code-coverage ruby-on-rails-3.2 spork
Rectangle 27 2

By default, Java opens it in the working directory of your application (this behavior actually depends on the OS used). To load a file, do:

Properties props = new java.util.Properties();
FileInputStream fis new FileInputStream("myfile.txt");
props.load(fis)

As such, any file extension can be used for property file. Additionally, the file can also be stored anywhere, as long as you can use a FileInputStream.

On a related note if you use a modern framework, the framework may provide additionnal ways of opening a property file. For example, Spring provide a ClassPathResource to load a property file using a package name from inside a JAR file.

As for iterating through the properties, once the properties are loaded they are stored in the java.util.Properties object, which offer the propertyNames() method.

properties - How to use Java property files? - Stack Overflow

java properties