Quickblox iOS: chatRoomDidEnter called multiple times - ios

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];

Related

WatchKit extension crash: "Program ended with exit code: 0"

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.

webRTC on iOS: Can't send SDP answer, RTCPeerConnection.setRemoteDescription() failed

I'm using libjingle_peerconnection installed with cocoapods. When I receive SDP offer through signaling server from my caller, I'm trying to set this as a remote description, which triggers RTCSessionDescriptionDelegate peerConnection:didSetSessionDescriptionWithError:
with error:
Error Domain=RTCSDPError Code=-1 "(null)" UserInfo={error=Failed to set remote answer sdp: Called in wrong state: STATE_INIT}.
My code is:
- (void)transportChanell:(TransportChannel *)channel didReceivedSignalWithSessionDescription:(NSString *)sessionDescription withType:(NSString *)type {
RTCSessionDescription *remoteDesc = [[RTCSessionDescription alloc] initWithType:#"answer" sdp:sessionDescription];
[_peerConnection setRemoteDescriptionWithDelegate:self sessionDescription:remoteDesc];
}
I've investigated the problem quite a lot and found in webRTC source code the place, as I suppose, this error comes from BadRemoteSdp(type, BadStateErrMsg(state()), err_desc); and all possible states of WebRtcSession are:
STATE_INIT = 0,
STATE_SENTOFFER, // Sent offer, waiting for answer.
STATE_RECEIVEDOFFER, // Received an offer. Need to send answer.
STATE_SENTPRANSWER, // Sent provisional answer. Need to send answer.
STATE_RECEIVEDPRANSWER, // Received provisional answer, waiting for answer.
STATE_INPROGRESS, // Offer/answer exchange completed.
STATE_CLOSED, // Close() was called.
Any suggestions, please, what could I missed in caller or callee side?
The offer seems to be marked as an "answer" according to the error message. It fails because it then expects you to be in the STATE_SENTOFFER state.
If you have created an offer and sent it to the other party, you may have forgotten to call setLocalDescription first. If you did not send an offer from the failing client, the other party should be changed to send an offer instead of an answer.
In the event this helps anyone coming here from Google:
I ran into this problem myself, and it turned out I'd hastily copy-pasted some code from the offerer I'd written. So I was init'ing RTCSessionDescription with type RTCSdpTypeAnswer instead of RTCSdpTypeOffer.
Make sure when allocating your RTCSessionDescription that you're using the right type!

Suppress RestKit Error Message

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.

Send programmatically SMS on jailbreak device

I am using a iOS 6 iphone 4S and I want to be able to send the unnoticed sms messages.
So using the standard view controller won't work in this case.
I tried using
- (BOOL)sendSMSWithText:(id)arg1 serviceCenter:(id)arg2 toAddress:(id)arg3;
but it doesn't send anything and returns NO. I used nil for arg2.
Can someone suggest a way to do it on iOS 6?(for jailbroken devices)
Found out why - (BOOL)sendSMSWithText:(id)arg1 serviceCenter:(id)arg2 toAddress:(id)arg3; is not working since iOS 6.
This API is protected by the entitlement com.apple.CommCenter.Messages-send. Just sign your app with this entitlement set to true. It's much better than my another answer here (XPC method) because of the two main reasons:
sendSMSWithText tells you whethere message was sent successfully
Messages sent using sendSMSWithText are not being saved in the SMS database and can't be seen anywhere. On the other hand, messages sent using XPC method are being saved in SMS database and can be seen in Messages application.
So, win win. I strongly suggest dropping XPC method also because it's using pretty low level API that can change easily in new iOS version. sendSMSWithText can be found even in iOS 7 and I don't think it will be dropped any time soon.
UPDATE
In order to use this API on iOS 7 and above you need to add another entitlement with bool value set to true - com.apple.coretelephony.Identity.get.
Straight from ChatKit.framework
dispatch_queue_t queue = dispatch_queue_create("com.apple.chatkit.clientcomposeserver.xpc_connection_queue", DISPATCH_QUEUE_SERIAL);
xpc_connection_t connection = xpc_connection_create_mach_service("com.apple.chatkit.clientcomposeserver.xpc", queue, 0);
xpc_connection_set_event_handler(connection, ^(xpc_object_t){});
xpc_connection_resume(connection);
dispatch_release(queue);
xpc_object_t dictionary = xpc_dictionary_create(0, 0, 0);
xpc_dictionary_set_int64(dictionary, "message-type", 0);
NSData* recipients = [NSPropertyListSerialization dataWithPropertyList:[NSArray arrayWithObject:#"12212"] format:NSPropertyListBinaryFormat_v1_0 options:0 error:NULL];
xpc_dictionary_set_data(dictionary, "recipients", recipients.bytes, recipients.length);
xpc_dictionary_set_string(dictionary, "markup", "SMS text");
xpc_connection_send_message(connection, dictionary);
xpc_release(dictionary);
recipients holds serialized property list with array of phone numbers to which you want to send your SMS - 12212 is just an example of phone number. Instead of SMS text you should put actual SMS text. Unfortunately, I couldn't find a way to check whether SMS was sent successfully.
To send message using this code your application entitlements should have com.apple.messages.composeclient key with boolean value set to true. Otherwise you get error in console saying application lacks entitlement.

Google Analytics on iOS returning NO on dispatch, no debug output

In trying to implement the Google Analytics SDK for iOS, I've run into two brick walls.
The first one is that after executing this code in application:DidFinishLaunchingWithOptions:
[[GANTracker sharedTracker] startTrackerWithAccountID:#"UA-XXXXXXX-YY"
dispatchPeriod:10
delegate:self];
[[GANTracker sharedTracker] setDebug:YES];
.. and then trying to track anything or call dispatch, no debug messages are logged whatsoever. I've added NSLog lines before and after tracking calls and the code is definitely being reached.
Secondly, when I do try and do a manual dispatch, it returns NO. All the other issues I've seen online are where dispatch returns YES but it's somehow not going through properly. What does one do if dispatch actually returns NO?
I've tried adding an NSError * reference to the track methods and those actually succeed (no error, function returns YES). But the events are definitely not being periodically dispatched, since we're seeing nothing on the GA account more than 24 hours later.
EDIT: I've also got NSLog calls in both of the delegate methods (hitDispatched: and trackerDispatchDidComplete:eventsDispatched:eventsFailedDispatch:), and neither of those are being called either.
i think you should check this to delegate method of GANTracker
- (void)trackerDispatchDidComplete:(GANTracker *)tracker
eventsDispatched:(NSUInteger)hitsDispatched
eventsFailedDispatch:(NSUInteger)hitsFailedDispatch{
//print or check number of events failed or success
}
//Delegate is set to 'nil' instead of class instance which implements the delegate methods.
[[GANTracker sharedTracker] startTrackerWithAccountID:#"UA-XXXXXXX-YY"
dispatchPeriod:10
delegate:nil];
In your case, assuming that UIApplicationDelegate may be implementing GANTrackerDelegate, the message call should set delegate as ' self '.
Cheers!! Amar.
Possibly the dispatch is relying on the calling thread's run loop - Is it possible you are running this from a secondary thread, one which might not exist by the time the dispatch is suppose to call you back?
You've not enabled dryRun have you? Double check with:
[[GANTracker sharedTracker] setDryRun:NO];
Also try dispatchSynchronous, it'll block as it's sending but might help with if things aren't on the same threads:
[[GANTracker sharedTracker] dispatchSynchronous];
Just've checked it from scratch, dispatch perfectly worked meaning
a) your device is somehow different (i still have unsolved crashes on the particular iPad's 3 from Apple tester's unresolved, so it wouldn't be a huge surprise)
b) your code is somehow different - and that's much easier for you to fix.
For the a) there's no advice but to test it against all the devices you might get, for the b) i could only say what worked for me:
downloaded 1.4 SDK here
got Google sample projects with git clone https://code.google.com/p/google-mobile-dev.analytics-end-to-end/
configured final/AnalyticsSample to launch, changed the source slightly
(trackEvent::::: were called from sample, app was restarted manually as there's zero time period requiring dispatch call)
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[GANTracker sharedTracker] startTrackerWithAccountID:kGANAccountId
dispatchPeriod:0
delegate:self];
NSLog(#"Dispatch%#", [[GANTracker sharedTracker] dispatch] ? #"ed Successfully": #" Failed");
[self.window addSubview:tabBarController.view];
[self.window makeKeyAndVisible];
return YES;
}
That's it, log says Dispatched Successfully, worth trying i guess.
cough
I'd misspelled the #define to start the tracker object in my app delegate. Other files were spelled correctly, hence the logging statements showing up, but when I tried to log just before the tracker was started it didn't show.
Oops. Well, at least there's a decent troubleshooting post for Google Analytics on SO now!

Resources