Using RestKit 0.20.x I am firing off a series of API calls on a particular view. If the user sends the app to the background I am cancelling ALL API calls using the following statement in the app delegate
- (void)applicationDidEnterBackground:(UIApplication *)application{
[self.weatherManager.restKitManager.operationQueue cancelAllOperations];
}
When the app returns from the background a UIAlert is visible with the following message:
The operation could not be completed. (org.restkit.RestKit.ErrorDomain error 2).
I don't want the user to have to see or dismiss this message upon return but am having trouble figuring out where/how to suppress this message.
Initially I was avoiding the use of cancelAllObjectRequestOperationsWithMethod: matchingPathPattern: because I had found a post on Google Groups from Blake Watters suggesting the use of the cancelAllOperations method on the operation queue which did not require a pathPattern
However If I use
[self.weatherManager.restKitManager cancelAllObjectRequestOperationsWithMethod:RKRequestMethodAny matchingPathPattern:#"/"];
by specifying a path pattern of just a "/" this seems to do the trick.
Related
erlang 24.3.3 is used.
From the 24.3.3 document, the wx version is 2.1.3.
I have find 2.1.3's wx.hrl and it doesn't contain the wxEVT_WEBVIEW_LOADED and wxEVT_WEBVIEW_ERROR.
But in the doc, it says
Many of the methods in wxWebView are asynchronous, i.e. they return
immediately and perform their work in the background. This includes
functions such as loadURL/2 and reload/2. To receive notification of
the progress and completion of these functions you need to handle the
events that are provided. Specifically wxEVT_WEBVIEW_LOADED notifies
when the page or a sub-frame has finished loading and
wxEVT_WEBVIEW_ERROR notifies that an error has occurred.
My code is as follows:
Ad = wxWebView:new(Frame,?wxID_ANY,[{size,{1000,1000}}]),
lager:debug("_ad_1082:\t~p",[Ad]),
ok = wxWebView:loadURL(Ad,"http://www.baidu.com"),
wxFrame:connect(Ad, ?wxEVT_WEBVIEW_LOADED,[{callback,fun chair_launch_frame:update_webview/2},
{userData,{?CONST_FRAME_MAIN_AD_PRODUCER,Frame}}]),
wxFrame:connect(Ad, ?wxEVT_WEBVIEW_ERROR,[{callback,fun chair_launch_frame:update_webview/2},
{userData,{?CONST_FRAME_MAIN_AD_PRODUCER,Frame}}]),
The compiler give error messsage undefined macro 'wxEVT_WEBVIEW_LOADED'
For people wanting to reply quickly without reading the post: I am not hitting any memory limits. Read the whole post for details.
My WatchKit extension cannot properly function without the user first being "onboarded" through the phone app. Onboarding is where the user must accept the permissions that we require, so it's very crucial.
On my WatchKit extension, I wanted to display a simple warning for users who had not finished onboarding within our phone app yet.
As such, I thought I'd get the status of onboarding from the phone in two ways:
When the user opens the app/the app is activated (I use the willActivate method to detect this)
When the app finishes onboarding it sends a message to the watch of its completion (if the extension is reachable, of course)
Both of these combined would ensure that the status of onboarding is always kept in sync with the watch.
I wrote the first possibility in, utilizing reply handlers to exchange the information. It worked just fine, without any troubles. The warning telling the user to complete disappears, the extension does not crash, and all is well.
I then wrote in the second possibility, of the extension being reachable when the user finishes onboarding (with the phone then directly sending the companion the new status of onboarding). My extension crashes when it receives this message, and I am stuck with this odd error.
Program ended with exit code: 0
My extension does not even get a chance to handle the new onboarding status, the extension just quits and the above error is given to me.
I am not hitting any sort of memory limit. I have read the technical Q&A which describes what a memory usage limit error looks like, and I don't receive any sort of output like that whatsoever. As well, before the extension should receive the message, this is what my memory consumption looks like.
I have monitored the memory consumption of the extension right after finishing onboarding, and I see not a single spike indicating that I've gone over any kind of threshold.
I have tried going line by line over the code which manages the onboarding error, and I cannot find a single reason that it would crash with this error. Especially since the reply handler method of fetching the onboarding status works so reliably.
Here is the code of how I'm sending the message to the watch.
- (void)sendOnboardingStatusToWatch {
if(self.connected){
[self.session sendMessage:#{
LMAppleWatchCommunicationKey: LMAppleWatchCommunicationKeyOnboardingComplete,
LMAppleWatchCommunicationKeyOnboardingComplete: #(LMMusicPlayer.onboardingComplete)
}
replyHandler:nil
errorHandler:^(NSError * _Nonnull error) {
NSLog(#"Error sending onboarding status: %#", error);
}];
}
}
(All LMAppleWatchCommunicationKeys are simply #define'd keys with exactly their key as the string value. ie. #define LMAppleWatchCommunicationKey #"LMAppleWatchCommunicationKey")
Even though it's never called by the extension, here is the exact receiving code of the extension which handles the incoming data, if it helps.
- (void)session:(WCSession *)session didReceiveMessage:(NSDictionary<NSString *, id> *)message {
NSString *key = [message objectForKey:LMAppleWatchCommunicationKey];
if([key isEqualToString:LMAppleWatchCommunicationKeyOnboardingComplete]){
BOOL newOnboardingStatus = [message objectForKey:LMAppleWatchCommunicationKeyOnboardingComplete];
[[NSUserDefaults standardUserDefaults] setBool:newOnboardingStatus
forKey:LMAppleWatchCommunicationKeyOnboardingComplete];
dispatch_async(dispatch_get_main_queue(), ^{
for(id<LMWCompanionBridgeDelegate> delegate in self.delegates){
if([delegate respondsToSelector:#selector(onboardingCompleteStatusChanged:)]){
[delegate onboardingCompleteStatusChanged:newOnboardingStatus];
}
}
});
}
}
Before including this onboarding-related code, my WatchKit extension was tested by over 100 people, without any troubles. I am using the exact same custom error dialogue that I was using before, just with a different string. I cannot for the life of me figure out what is causing this crash, and the ambiguity of it has given me very little to work with.
Any help would be greatly appreciated. Thank you very much for taking your time to read my post.
Edit: I just tried creating a symbolic breakpoint for exit(), which is never hit. If I call exit() myself, it calls the breakpoint, so I know the breakpoint itself is working.
I am finding that if I execute a custom delegate method right after saving to NSUserDefaults, the data is not saved and the following error is displayed:
The operation couldn’t be completed. (OSStatus error -10875.)
The above error shows under iOS 8 but does NOT show under iOS 7. However, the results (the data not saving) is common to both versions. iOS 7 just doesn't show an error has occurred. Also, this is running on a simulator.
This issue only occurs when I call a custom delegate after writing the data. If I remove the custom delegate, the data is written with no issues.
The code is as follows:
[self.prefs setObject:self.secondsLabel.text forKey:#"timer"];
[self.prefs setInteger:self.questionTypeControl.selectedSegmentIndex forKey:#"type"];
[self.prefs setBool:self.speedSwitch.on forKey:#"speed"];
[self.prefs setBool:self.mixupSwitch.on forKey:#"switch"];
[self.prefs synchronize];
[self._delegate setupStatus:configChanged withVC:self];
[self dismissViewControllerAnimated:YES completion:nil];
As "synchronize" returns a BOOL I did do a check and did find that it was returning TRUE so the data should be saved, but again it is not. If I comment out the delegate line, the data is saved appropriately.
The delegate is firing a method in the prior VC. I put a breakpoint on the first line of that method but the error had already occurred. This makes me believe that the issue is simply the act of calling the method. Of interest, if instead of using a delegate I use an NSNotification, the problem doesn't present itself.
Why would calling a delegate cause the error and the inability to save the data?
Update: I did run it on an actual device (iPad running iOS 8.1). I still get the exact same error as mentioned above, however, the data DOES actually save. So the sim and device produce the same error but on the sim it won't save and on the device it will. Again this is only if the delegate is present.
This is my third Quickblox question in a row and I hope someone answers me.
As usual, Quickblox's documentation confuses me again.
I am using following code to create / join a room:
[[QBChat instance] createOrJoinRoomWithName:roomName membersOnly:NO persistent:YES];
Upon login, when I call this method, following delegate is called:
- (void)chatRoomDidEnter:(QBChatRoom *)room
However this is called once again - probably when other user calls the above statement.
Why, again, why such things keep happening?
Isn't it intended for current user only?
The delegate method's documentation says:
Fired when you did enter to room
Then why this unexpected behavior?
Also I keep getting the age old messages with following log:
<Warning>: QBChat/didReceiveMessage: <message xmlns="jabber:client" id="1407872706.569180" from="11447_en#muc.chat.quickblox.com/1233710" to="1233710-11447#chat.quickblox.com/56FEC1BB-71E8-4CDD-8ED7-33AB8C63AFAF" type="groupchat"><body>Body Text</body><delay xmlns="urn:xmpp:delay" from="1233710-11447#chat.quickblox.com/89F03E1A-8FB0-47A4-9565-39D78C90E3C7" stamp="2014-08-12T19:45:10Z"/><x xmlns="jabber:x:delay" from="1233710-11447#chat.quickblox.com/89F03E1A-8FB0-47A4-9565-39D78C90E3C7" stamp="20140812T19:45:10"/></message>
Surprisingly, this is not as part of following delegate:
- (void)chatDidReceiveMessage:(QBChatMessage *)message
This is highly confusing...when will they get things into shape?
Why don't you use the Chat 2.0 stuff?
http://quickblox.com/developers/SimpleSample-chat_users-ios
This is the modern way how to build Chat applications
It provides a better way to create a group chat than
[[QBChat instance] createOrJoinRoomWithName:roomName membersOnly:NO persistent:YES];
In my app, I need to make https calls to a restful web api and process the results upon return. The number of simultaneous service calls is never fixed, hence the related code has been written accordingly. The data fetched from the service is temporarily stored on an SQLite DB within the app. Following is the structure how it works.
When the user navigates to any screen or UI component thereof for which data needs to be fetched, the view controller calls a method on its designated model object. This method then checks whether the data is already present in the DB or it needs to be fetched. In case data is present, it returns the same to the view controller. Otherwise, it initiates an asynchronous service request and waits till the response comes, after which it returns the data to the VC. Therefore, the VC initialises a loading indicator before calling the specified model, and dismisses the same after control is returned from this function.
Here it is important that the function on the model waits till the response is received from the web api. This is done by registering for an NSNotification which will be issued by the service module once returned data is written to the DB. A boolean variable it set to false upon making the service request and set to true once the response is received. An NSRunLoop runs on the false condition of this boolean variable. Hence once the variable is set to true, the rest of the processing can continue.
Following are the relevant pieces of code in which all this is implemented:
[serviceModule initServiceCall:#"25" withDictionary:[NSDictionary dictionaryWithObjects:#[asOfDate] forKeys:#[#"toDate"]]];
dataReady=NO;
NSString *notificationName = #"dataReady";
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(useNotificationFromServiceModule:) name:notificationName object:nil];
NSRunLoop *theRL = [NSRunLoop currentRunLoop];
while (!dataReady && [theRL runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]);
The rest of the function continues after this.
This is the function that handles the notification:
-(void)useNotificationFromServiceModule:(NSNotification *)notification {
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0ul);
dispatch_async(queue, ^{
dataReady=YES;
});}
The usual process is that once the notification is sent, the NSRunLoop quits and the rest of the method completes, returning to the view controller which then dismissed the loading indicator. The problem is that sometimes this does not happen. While the notification is issued (I can see the console log), the NSRunLoop does not end. The loading indicator continues to appear on the screen and stays that way until the screen is tapped once. When the screen is tapped, the NSRunLoop ends and the rest of the process continues randomly.
This does not happen always. It happens quite randomly, maybe about 4-5 times out of 10. Kindly provide some inputs/pointers to indicate why this may be happening.
If you are using the run loop directly, you are either very clever or very stupid. In the first case, you'll find the answer yourself. In the second case, it would be much much better if you followed the same pattern as everyone else does, which is running your networking code on a background thread and using dispatch_async when the results arrive.