I have this code:
RAC(self.viewModel , password) = self.signupCell.passwordTextField.rac_textSignal;
RAC(self.viewModel , userName) = self.signupCell.usernameTextField.rac_textSignal;
RAC([UIApplication sharedApplication], networkActivityIndicatorVisible) = self.viewModel.executeRegister.executing;
At my LogIn page.
At first is runs perfect, But it user Logout and gets to the register page once again, the app crushes at the line:
RAC([UIApplication sharedApplication], networkActivityIndicatorVisible) = self.viewModel.executeRegister.executing;
With Error:
'Signal name: is already bound to key path "networkActivityIndicatorVisible" on object , adding signal name: is undefined behavior'
I'm guessing it has something to do with subscribing to UIApplication events. But I'm not sure what else can i do beside sending subscriber completed as so:
[subscriber sendCompleted]
Any one had the same problem?
thanks.
EDIT
With the help of #erikprice and #powerj1984 I found a solution:
RAC([UIApplication sharedApplication], networkActivityIndicatorVisible) = [self.viewModel.executeRegister.executing takeUntilBlock:^BOOL(id x) {
return _viewShowing;
}];
The "_viewShowing" veritable is setted to YES on ViewWillAppear, And to NO on ViewWillDisapear.
This is not the best coding.. So if anyone has a better option i would be happy to use it.
Thanks.
That error message means that you're trying to call RAC(UIApplication.sharedApplication, networkActivityIndicatorVisible) more than once. Make sure you only make that call on that specific property of that specific object one time, ever. (Or at least until such time as you dispose of the subscription, as #powerj1984 suggests.)
Related
I have a watch app with complications. Updating the complication on a watch face did work for a long time, but stopped recently, maybe due to a watchOS update.
The reason is that the activeComplications property of the CLKComplicationServer.sharedInstance() is nil, although my complication placeholder is shown on the watch face (device & simulator).
The code could not be simpler:
final class ComplicationController: NSObject, CLKComplicationDataSource {
// …
func updateComplications() {
//…
let complicationServer = CLKComplicationServer.sharedInstance()
if let activeComplications = complicationServer.activeComplications {
for complication in activeComplications {
complicationServer.reloadTimeline(for: complication)
}
}
//…
}
//…
}
If I stop at a breakpoint at the if let instruction, complicationServer has the following values:
And the following lldb command outputs nil:
What could be the reason?
My bad: I solved the problem 4 years ago, but forgot the solution during refactoring of the app.
Actually I don’t know if this is a solution, a workaround or a hack:
I suspect that the CLKComplicationServer or its CLKComplicationDataSource, i.e. the ComplicationController, is not correctly initialized if ComplicationController.shared is executed anywhere in the code. If not, the ComplicationController is correctly initialized by the CLKComplicationServer.
Therefore, one cannot call any function in the ComplicationController, e.g. to update complications. Instead one can send a notification to the ComplicationController that executes the requested function. Of course, one has to ensure that the ComplicationController is already initialized and registered to receive such a notification before it is posted.
If so, CLKComplicationServer.sharedInstance().activeComplications is no longer nil, and the complication update works.
I need to watch a specified folder for specific type of file (pdf) and get notification only when file is "Created" or "Renamed".
I tried many Obj c wrappers like SCEvents, UKKQueue etc., I could not get the type of the event raised("Created" or "Renamed") inside the notification delegate.I am just getting a flag/some#.I also tried FSEventStream which was not raising callback.Refered URL for this:OSX FSEventStreamEventFlags not working correctly.
In SCEvents, I have below delegate which is not telling me the type of event-
- (void)pathWatcher:(SCEvents *)pathWatcher eventOccurred:(SCEvent *)event {
NSLog(#"%#", event);
}
Getting below log-
2014-02-27 16:41:59.342 PMLauncher6[5187:303] <SCEvent { eventId = 661674, eventPath = /Users/Test, eventFlag = 67584 } >
Any one has any idea on the same or better way to meet the requirement, kindly advise.
Thanks
Try NSWorkspace - noteFileSystemChanged:.
The documentation doesn't tell much about it, but as a Notification that "Informs the NSWorkspace object that the file system changed at the specified path." it should fit to your needs.
Can I fire an event when ever there is Incoming and Outgoing call ends on iphone? Axample of an event is calling a webservice .
Yes you can, but not necessarily immediately.
There is a framework, called the CoreTelephony framework, which has a CTCallCenter class. One of the properties on this class is the callEventHandler property. This is a block that gets fired when then state of a phone call changes. For example:
CTCallCenter *callCenter = ...; // get a CallCenter somehow; most likely as a global object or something similar?
[callCenter setCallEventHandler:^(CTCall *call) {
if ([[call callState] isEqual:CTCallStateConnected]) {
//this call has just connected
} else if ([[call callState] isEqual:CTCallStateDisconnected]) {
//this call has just ended (dropped/hung up/etc)
}
}];
That's really about all you can do with this. You don't get access to any phone numbers. The only other useful tidbit of information is an identifier property on CTCall so you uniquely identify a CTCall object.
CAUTION:
This event handler is not invoked unless your app is in the foreground! If you make and receive calls while the app is backgrounded, the event handler will not fire until your app becomes active again, at which point (according to the documentation linked to above) the event handler will get invoked once for each call that has changed state while the app was in the background.
No but you do get callbacks into the app when those events happen.
-(void)applicationWillResignActive:(UIApplication *)application{
//our app is going to loose focus since thier is an incoming call
[self pauseApp];
}
-(void)applicationDidBecomeActive:(UIApplication *)application{
//the user declined the call and is returning to our app
[self resumeApp];
}
No. As of the current SDK, this is not possible. Apple does not allow apps to have such hooks.
everybody.
I want to understand, how i shoud procceed situations when an asynchronous method has "didFinish:#selector(SEL)" parameter.
My code example is:
//
// Authentication check
- ( void )authenticationSuccess: ( GDataServiceTicket* ) ticket
authenticatedWithError: ( NSError* ) error {
if ( error == nil )
{
NSLog( #"authentication success" );
}
else
{
NSLog( #"authentication error" );
}
}
//
- ( void ) fetchFeedOfSpreadsheets {
//create and authenticate to a google spreadsheet service
if ( !(mService) )
{
GDataServiceGoogleSpreadsheet *service = [self spreadsheetService];
[mService autorelease];
mService = [service retain];
}
// check autentication success ( invoke "authenticationSuccess" method for debug success & error )
[mService authenticateWithDelegate: self
didAuthenticateSelector:#selector(authenticationSuccess:
authenticatedWithError:) ];
// HERE I WANT TO MAKE A PAUSE AND WHAIT THE RESULT, EITHER I AUTHENTICATED OR NOT
// AND MAKE AN "IF" STATEMENT TO CONTINTUE WORKING ON SERVER, OR RETURN ERROR
//fetch retrieves the feed of spreadsheets entries
NSURL *feedURL = [ NSURL URLWithString: kGDataGoogleSpreadsheetsPrivateFullFeed ];
GDataServiceTicket *ticket;
ticket = [mService fetchFeedWithURL: feedURL
delegate: self
didFinishSelector: #selector(spreadsheetsTicket:finishedWithFeed:
error: ) ];
// HERE I WANT TO WAIT SECOND TIME. I WANT "spreadsheetsTicket:
// finishedWithFeed:error:" TO PROCCEED ERROR AND PUT A FEED IN SOME NSARRAY OBJECT
// AND AFTER THAT I WANT TO WORK WITH THAT NSARRAY RIGHT HERE
}
I's clear, that i can push the code i want into the end of "authenticationSuccess" method section, but it's also clear, that it's a wrong a way to solve the proble. There a number of situations like this, where i call an asynchronous method with a selector parameter, and i want to find a solution providing me a flexible code writing.
Thanks in advance.
It's a standard practice in Objective-C to put the code to be executed after the authentication in the authenticationSucess: method. You might not like it, but that is life.
Many people had the same complaint as you, so
on iOS 4 and later, there's something called blocks which allow you to write the code to be executed after the authentication in the method which initiates the authentication, as in
[mService authenticateAndExecute:^{
code to be executed when successfully authenticated ;
} whenError:^{
code to be executed when authentication failed;
} ];
But in this case you need to modify the API, which is possible by using categories. See this blog post by Mike Ash. He has many other posts on blocks on the same blog, which are also very instructive.
If you're going to use a library that works asynchronously (and therefore doesn't block your UI), you should have a good reason for trying to force it to work synchronously.
You should be checking for an authentication error at the end of your authenticationSuccess:authenticatedWithError: method, and calling the next request from there if there's a success. Similarly, in your spreadsheetsTicket:finishedWithFeed:error: check for an error, and continuing processing if there isn't one. It might be a better design to do that continued work in a separate method, but that's up to you.
Is there a specific reason you want to use the GData API in a synchronous fashion?
I am creating an application in Silverlight 4. The first screen the user comes in contact with is the Login screen (Login.xaml). I have written the following code in Login.xaml.cs file.
private void btnSubmit_Click(object sender, RoutedEventArgs e)
{
//first validate if the user is authorised for this application
if (this.ValidateEntry())
{
if (UserAuthenticationBL.AuthenticateUser(txtUserName.Text.Trim(), txtPassword.Password.Trim()))
{
//since the user is authenticated we will show the dashboard screen
this.Content = new MainPage();
}
else
{
this.ShowErrorMessage("Invalid username or password");
txtUserName.Focus();
}
}
}
My problem is that the code gets executed before i get the data in the AuthenticateUser method. The code immediately comes down to the "Invalid username or password" and the list is loaded after all the execution on the xaml page has finished.
I know there is something going wrong with the Asynchronous thingi...and i also know i need to put an event to know when the loading has completed........
but i dont know how to go about it!!!
can someone please put some light on this issue...
thank you.
If I understood it right, your AuthenticateUser method is running async, right?
You have to define a callback to the AuthenticateUserComplete event and run the method in the button submit event. In the callback write this if/else clause, then it will be called once the asynchronous method was completed.
Just one question, why are you doing asynchronously if your behavior should be synchronous? (You have to get the answer before deciding what to do).
This http://msdn.microsoft.com/en-us/library/aa719598%28VS.71%29.aspx
may be helpful :)
Oscar