XMPPFramework and Openfire sever, authentication successful ,but not call back - objective-c

Connect opefire server ok , and then to authentication:
- (void)xmppStreamDidConnect:(XMPPStream *)sender{
NSLog(#"connected --->YES");
isOpen = YES;
NSError *error = nil;
[xmppStream authenticateWithPassword:#"password" error:&error];
}
Openfire logs show:
2012.08.01 19:13:35 org.apache.mina.filter.executor.ExecutorFilter - Exiting since queue is empty for /121.0.29.220:60789
2012.08.01 19:13:35 org.apache.mina.filter.executor.ExecutorFilter - Launching thread for /121.0.29.220:60789
2012.08.01 19:13:35 org.apache.mina.filter.executor.ExecutorFilter - Exiting since queue is empty for /121.0.29.220:60789
2012.08.01 19:13:35 org.apache.mina.filter.executor.ExecutorFilter - Launching thread for /121.0.29.220:60789
2012.08.01 19:13:35 org.apache.mina.filter.executor.ExecutorFilter - Exiting since queue is empty for /121.0.29.220:60789
2012.08.01 19:13:35 org.apache.mina.filter.executor.ExecutorFilter - Launching thread for /121.0.29.220:60789
2012.08.01 19:13:35 org.jivesoftware.util.log.util.CommonsLogFactory - 000065 (01/05/00) - Connection #5 tested: OK
2012.08.01 19:13:35 org.jivesoftware.util.log.util.CommonsLogFactory - 000066 (01/05/00) - Connection #5 tested: OK
2012.08.01 19:13:35 org.jivesoftware.openfire.auth.AuthorizationManager - AuthorizationManager: Trying Default Mapping.map(shitiven)
2012.08.01 19:13:35 org.jivesoftware.openfire.auth.DefaultAuthorizationMapping - DefaultAuthorizationMapping: No realm found
2012.08.01 19:13:35 org.jivesoftware.openfire.auth.AuthorizationManager - AuthorizationManager: Trying Default Policy.authorize(shitiven , shitiven)
2012.08.01 19:13:35 org.jivesoftware.openfire.auth.DefaultAuthorizationPolicy - DefaultAuthorizationPolicy: Checking authenID realm
2012.08.01 19:13:35 org.jivesoftware.util.log.util.CommonsLogFactory - 000066 (01/05/00) - Connection #2 tested: OK
2012.08.01 19:13:35 org.jivesoftware.util.log.util.CommonsLogFactory - 000067 (01/05/00) - Connection #2 tested: OK
2012.08.01 19:13:35 org.jivesoftware.util.log.util.CommonsLogFactory - 000067 (01/05/00) - Connection #1 tested: OK
2012.08.01 19:13:35 org.jivesoftware.util.log.util.CommonsLogFactory - 000068 (01/05/00) - Connection #1 tested: OK
2012.08.01 19:13:35 org.apache.mina.filter.executor.ExecutorFilter - Exiting since queue is empty for /121.0.29.220:60789
2012.08.01 19:13:35 org.apache.mina.filter.executor.ExecutorFilter - Launching thread for /121.0.29.220:60789
2012.08.01 19:13:35 org.apache.mina.filter.executor.ExecutorFilter - Exiting since queue is empty for /121.0.29.220:60789
2012.08.01 19:13:35 org.apache.mina.filter.executor.ExecutorFilter - Launching thread for /121.0.29.220:60789
2012.08.01 19:13:35 org.apache.mina.filter.executor.ExecutorFilter - Exiting since queue is empty for /121.0.29.220:60789
But the delegate method "xmppStreamDidAuthenticate" not call:
- (void)xmppStreamDidAuthenticate:(XMPPStream *)sender{
NSLog(#"login success!!");
[self goOnline];
}
When I type wrong userid or password , the delegate method "didNotAuthenticate" call:
- (void)xmppStream:(XMPPStream *)sender didNotAuthenticate:(NSXMLElement *)error{
NSLog(#"authenticate fail %#",error); //console to the debug pannel
}
Can anyone help me?

I suspect that you're being haunted by the issue described here: https://github.com/robbiehanson/XMPPFramework/issues/81
You will have to update xmppframework to fix this.

Related

iOS App UI freeze when coming from background

I'm facing a strange issue and I have no clue why this is happening.My app works fine when it is active, but the app UI is freezing when it comes from background (by pressing the home button and by locking the device).
NOTE:This behaviour is only observed on devices but not in simulator.
And the console is throwing the messages:
Jul 5 13:28:55 Tejas-iPhone backboardd[7234] <Warning>: BKSendHIDEvent: IOHIDEventSystemConnectionDispatchEvent error:0xE00002E8 -- Unknown event dropped
along with too many logs of :
Jul 5 14:41:40 Tejas-iPhone boostApp[7913] <Error>: CoreLocation: Discarding message for event 0 because of too many unprocessed messages
Jul 5 14:41:42 Tejas-iPhone boostApp[7913] <Error>: CoreLocation: Discarding message for event 12 because of too many unprocessed messages
Jul 5 14:44:56 Tejas-iPhone boostApp[7913] <Error>: CoreLocation: Discarding message for event 1 because of too many unprocessed messages
Jul 5 14:44:56 Tejas-iPhone boostApp[7913] <Error>: CoreLocation: Discarding message for event 27 because of too many unprocessed messages
I found out that CoreLocation will log the above message if the locationManager is not running on main thread.
Here is how I initialise the CLLocationManager:
-(id)init {
if ( self = [super init] ) {
[self runLocationManagerOnMainThread];
}
return self;
}
-(void)runLocationManagerOnMainThread{
if (![NSThread mainThread]) {
[self performSelectorOnMainThread:#selector(runLocationManagerOnMainThread) withObject:nil waitUntilDone:NO];
}
self.locationManager = [[LocationManager alloc] init];
self.locationManager.delegate = self;
self.locationManager.distanceFilter = 1;
self.locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
self.buildings = [[NSMutableArray alloc] init];
}
+ (id)sharedInstance {
static LocationMonitor *sharedMyManager = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedMyManager = [[self alloc] init];
});
return sharedMyManager;
}
Please let me know if I need to mention any specific details.I tried this but it doesn't have any valid answers.
This is wierd . I integrated NSLogger to my project a while ago and I started to see that xcode terminal stopped logging logs and I have to always rely on apple configurator and NSLogger to see my logs.
After I delete the NSLogger from pods and from my project, my app started to work more faster and the UI is not freezing anymore irrespective of how many times the app is opened from background.

iOS Push Notifications sent but not received

I am completely new to the Objective-C language. All I need to implement is the Push Notifications bit on my app for now. I have written the Client side on XCode 6 and the server side in Java using the javapns library. Now, while the server manages to send the notification (I get the confirmation message), I receive nothing on my device, be it the app is active or running in background.
Can somebody please direct me in the right direction? Thank you!
#import "AppDelegate.h"
#interface AppDelegate ()
#end
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert |UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
[[UIApplication sharedApplication] registerForRemoteNotifications];
return YES;
}
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)newDeviceToken{
//Store the Device Token
NSLog(#"%#", newDeviceToken);
}
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error{
NSLog(#"Failed to register with error: %#", error);
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
NSLog(#"Push received: %#", userInfo);
}
Server side:
public class PushServer {
public static void main(String[] args) {
try {
BasicConfigurator.configure();
Push.alert("Message!", "***.p12", "***", false,
"92ab*************91af4");
} catch (CommunicationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (KeystoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
This is the output I receive when I try to send the notification:
0 [main] DEBUG javapns.notification.Payload - Adding alert [Message!]
210 [main] DEBUG javapns.communication.ConnectionToAppleServer - Creating SSLSocketFactory
229 [main] DEBUG javapns.communication.ConnectionToAppleServer - Creating SSLSocket to gateway.sandbox.push.apple.com:2195
1077 [main] DEBUG javapns.notification.PushNotificationManager - Initialized Connection to Host: [gateway.sandbox.push.apple.com] Port: [2195]: 735b478[SSL_NULL_WITH_NULL_NULL: Socket[addr=gateway.sandbox.push.apple.com/17.172.232.46,port=2195,localport=53762]]
1079 [main] DEBUG javapns.notification.PushNotificationManager - Building Raw message from deviceToken and payload
1080 [main] DEBUG javapns.notification.PushNotificationManager - Built raw message ID 1 of total length 73
1080 [main] DEBUG javapns.notification.PushNotificationManager - Attempting to send notification: {"aps":{"alert":"Message!"}}
1080 [main] DEBUG javapns.notification.PushNotificationManager - to device: 92a**********1af4
2327 [main] DEBUG javapns.notification.PushNotificationManager - Flushing
2327 [main] DEBUG javapns.notification.PushNotificationManager - At this point, the entire 73-bytes message has been streamed out successfully through the SSL connection
2327 [main] DEBUG javapns.notification.PushNotificationManager - Notification sent on first attempt
2327 [main] DEBUG javapns.notification.PushNotificationManager - Reading responses
2749 [main] DEBUG javapns.notification.PushNotificationManager - Found 0 notifications that must be re-sent
2749 [main] DEBUG javapns.notification.PushNotificationManager - No notifications remaining to be resent
2749 [main] DEBUG javapns.notification.PushNotificationManager - Closing connection
Any help is appreciated.
By chance would you happen to be building with Xcode 7 and targeting iOS 9?
If so, you are likely running into the new security default setting which requires accessing URLs securely, as described here:
Disabling ATS for an in-app browser in iOS 9?
Also, you seem to be mixing old methods with new.
registerUserNotificationSettings is an iOS 8 method that replaced registerForRemoteNotificationTypes.
So, only using the former, it looks like you're only targeting iOS 8 and later.
But then you use didReceiveRemoteNotification:, which is the old version of the method, corresponding to registerForRemoteNotificationTypes. But since you're going with the newer versions, you should be using
didReceiveRemoteNotification:fetchCompletionHandler.
You need to convert NSData to string and get actual device token by implementing following changes in your method.
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
NSString *myToken = [[[[deviceToken description] stringByReplacingOccurrencesOfString: #"<" withString: #""]
stringByReplacingOccurrencesOfString: #">" withString: #""]
stringByReplacingOccurrencesOfString: #" " withString: #""];
// *** Now user `myToken` to send notification ***
NSLog(#"%#",myToken);
}
Along with it you need to make sure you are running your application with same provisional profile (Developer/Distribution) which is used to send push notification on your server side. both should be same. I hope its clear to you.

Registering for notification causes error on mac

I am doing something like this:
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
// Insert code here to initialize your application
NSApplication *application = [aNotification object];
NSRemoteNotificationType myTypes = NSRemoteNotificationTypeBadge;
[application registerForRemoteNotificationTypes:myTypes];
}
//Successful
-(void)application:(NSApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{
NSLog(#"device token: %#", deviceToken);
}
//Failure to register
-(void)application:(NSApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error{
NSLog(#"ERROR: %#\nError object: %#", [error localizedDescription], error);
}
And I am getting the following error:
2014-06-14 20:47:13.656 RajamManagerStation[1878:303] ERROR: The operation couldn’t be completed. (OSStatus error 1.)
Error object: Error Domain=NSOSStatusErrorDomain Code=1 "The operation couldn’t be completed. (OSStatus error 1.)" (kCFHostErrorHostNotFound / kCFStreamErrorSOCKSSubDomainVersionCode / kCFStreamErrorSOCKS5BadResponseAddr / kCFStreamErrorDomainPOSIX / evtNotEnb / siInitSDTblErr / kUSBPending / dsBusError / kStatusIsError / kOTSerialSwOverRunErr / cdevResErr / EPERM: / Error code is the version of SOCKS which the server wishes to use / / POSIX errno; interpret using <sys/errno.h> / event not enabled at PostEvent / slot int dispatch table could not be initialized. / / bus error / / / Couldn't get a needed resource; alert / Operation not permitted)
I dont understand what I can do to fix it.
I was watching the WWDC apple video in 2011 relating to push notifications, and there was a slide in there that showed:
It tells me that if the error delegate callback is called that I should check my privisioning profile for entitlements.
I have done everything I possiby could to get things working but I am receiving this error still. What can I do to fix it?
UPDATE 1 - Just to affirm that I have enabled push notification services in the enabled services list.
UPDATE 2 - Affirming that push notifications is there on the provisioning profile
Switch on the Push Notifications capability for your target. In XCode, go to Target -> Capabilities, and ensure "Push Notifications" is set to ON:
(Thanks to #mateusmaso's comment for this solution!)

beginBackgroundTaskWithExpirationHandler with a current thread

beginBackgroundTaskWithExpirationHandler creates a new thread when we execute something.
Can I execute something using an existing thread with this?
Because new thread generated by beginBackgroundTaskWithExpirationHandler causes some problems to my application when it is resumed. So I passed an instance of an existing thread to beginBackgroundTaskWithExpirationHandler and called the required methods using the existing thread. Is it ok to use existing threads inside beginBackgroundTaskWithExpirationHandler ?
Will it cause any problems?
- (void)applicationDidEnterBackground:(UIApplication *)application {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
IOSMobilePOSApplication *app = [IOSMobilePOSApplication getInstance];
if ([app keepAliveMessage]) {
if([[UIDevice currentDevice] respondsToSelector:#selector(isMultitaskingSupported)])
{
[Logger log:#"Multitasking Supported"];
background_task = [application beginBackgroundTaskWithExpirationHandler:^ {
[Logger log:#"Background maximum time exeeded."];
IOSMobilePOSApplication *iosMobileApplication = [IOSMobilePOSApplication getInstance];
[[iosMobileApplication getKeepAliveManager] stop];
//Clean up code. Tell the system that we are done.
[application endBackgroundTask: background_task];
background_task = UIBackgroundTaskInvalid;
}];
//To make the code block asynchronous
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
//### background task starts
[Logger log:#"Running in the background"];
IOSMobilePOSApplication *iosMobileApplication = [IOSMobilePOSApplication getInstance];
[[iosMobileApplication getKeepAliveManager] setEnabled:true];
[[iosMobileApplication getKeepAliveManager] performSelector:#selector(run) onThread:[[iosMobileApplication getKeepAliveManager] runingThread] withObject:NULL waitUntilDone:NO];
isStarted = true;
//#### background task ends
//Clean up code. Tell the system that we are done.
[application endBackgroundTask: background_task];
background_task = UIBackgroundTaskInvalid;
});
}
else
{
[Logger log:#"Multitasking Not Supported"];
}
}
}
here
[[iosMobileApplication getKeepAliveManager] run]; causes new thread to start and it causes thread synchronization problems in my code. So I added the code in place of above mentioned line.
[[iosMobileApplication getKeepAliveManager] performSelector:#selector(run) onThread:[[iosMobileApplication getKeepAliveManager] runingThread] withObject:NULL waitUntilDone:NO];.
Will this cause any problems when the app goes background?
It’s probably some mistake, because -beginBackgroundTaskWithExpirationHandler: doesn’t create any threads. It only marks the beginning of some long-running task you’re about to start or just started.
This method can be called from any thread. The expiration handler that it takes as a parameter is called on the main thread. This handler is used to clean up and mark the end of the long-running task you’re doing.

IOS4.2 app quits with EXC_BAD_ACCESS

An iPad app that runs fine under IOS3 fails under IOS4.2 It has a class that runs an http session from an operation queue and the failure is linked to this activity. Here is the console output:
Program received signal: “EXC_BAD_ACCESS”.
[Switching to thread 11523]
Running NSZombies enabled didn't reveal anything so I have been putting NSLog statements in the code and found that the crash occurs when a local variable is changed. Here is the code section:
self.currentOperation = [[[DeduceAccessOperation alloc] init] autorelease];
[self.currentOperation addObserver:self forKeyPath:#"isFinished"
options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld)
context:NULL];
NSLog (#"Start observer added");
[operationQueue addOperation:self.currentOperation];
NSLog (#"Start operation added");
NSLog(#"State is %d", self.status);
self.status = IEnablerServiceUpdating;
NSLog (#"State updated");
And here is the console log output:
2010-12-08 21:26:44.548 UCiEnabler[5180:307] Start observer added
2010-12-08 21:26:44.550 UCiEnabler[5180:307] Start operation added
2010-12-08 21:26:44.552 UCiEnabler[5180:307] State is 1
Program received signal: “EXC_BAD_ACCESS”.
[Switching to thread 11523]
It is like status has become read-only (It's property is declared as atomic and readwrite).
The other relevant piece of information is that a sub-view has just been changed and it triggers the call on the above routine. It's code is:
//Start the update
UCiEnablerAppDelegate *controller = (UCiEnablerAppDelegate *)[[UIApplication sharedApplication] delegate];
[controller deduceIEnablerServiceAccess];
controller.serviceBusy = TRUE; //1.04
Has anyone seen anything like this?
Has anyone ideas where to look next?
Regards
Robin
Here's the stack trace:
#0 0x34a80464 in objc_msgSend
#1 0x3119543e in NSKVOPendingNotificationCreate
#2 0x3119535a in NSKeyValuePushPendingNotificationPerThread
#3 0x3117009a in NSKeyValueWillChange
#4 0x311682c6 in -[NSObject(NSKeyValueObserverNotification) willChangeValueForKey:]
#5 0x311cc718 in _NSSetIntValueAndNotify
#6 0x000097ce in -[IEnablerService startDeducingAccessState] at IEnablerService.m:55
#7 0x00002bc0 in -[UCiEnablerAppDelegate deduceIEnablerServiceAccess] at UCiEnablerAppDelegate.m:100
#8 0x0000a33e in -[RootViewControlleriPad animationDidStop:finished:context:] at RootViewController-iPad.m:43
#9 0x341bb336 in -[UIViewAnimationState sendDelegateAnimationDidStop:finished:]
NSOperationQueue in iOS 4.2 now uses GrandCentralDispatch when starting NSOperations. There's a Technical Q&A here
Pretty much the queue now calls the NSOperation subclass's start method in a new thread regardless of the isConcurrent property. In my experience it means that if you are using NSURLConnection inside a start method your code will no longer run because the thread start is running on doesn't have an NSRunLoop.
Apple says that this change doesn't break compatibility because you were supposed to spawn a new thread in the start method anyway.
For backwards compatibility you should change your subclass from using start to using run.