XMPPFramework - keine Verbindung

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • XMPPFramework - keine Verbindung

    Hallo,

    Wir haben uns entschieden in unsere App einen Realtimemessenger einzubauen. Dafür wollen wir XMPP nutzen und dafür bietet sich ja bei iOS nur das Framework an: github.com/robbiehanson/XMPPFramework.
    Ich (zurzeit leider der einzige iOS entwickler) kenne mich leider gar nicht damit aus und habe es nie gemacht. Alle Tutorials etc. die für objective C sind sind nicht aktuell und die Beispielprojekte funktionieren größtenteils nicht. Mit einem Tutorial von 2011 habe und einem nicht funktionierenden GitHub projekt zu dem tutorial von ende 2015 habe ich versucht irgendwie eine Verbindung in meiner App zu unserem Server herzustellen.
    Der Compiler gibt dabei eine Warnung aus:
    Bildschirmfoto 2016-07-18 um 15.47.55.png
    aber sonst startet die app auch ohne probleme. Ich stelle jetzt mal mein AppDelegate hier rein, vielleicht kann mir ja jemand von euch helfen. Danke

    Quellcode: AppDelegate.h

    1. #import <UIKit/UIKit.h>
    2. #import <CoreData/CoreData.h>
    3. #import "XMPP.h"
    4. @interface AppDelegate : UIResponder <UIApplicationDelegate> {
    5. XMPPStream *xmppStream;
    6. NSString *password;
    7. BOOL isOpen;
    8. }
    9. @property (strong, nonatomic) UIWindow *window;
    10. @property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext;
    11. @property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel;
    12. @property (readonly, strong, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator;
    13. - (void)saveContext;
    14. - (NSURL *)applicationDocumentsDirectory;
    15. #pragma mark - setup XMPP
    16. //properties:
    17. @property (readonly, nonatomic) XMPPStream *xmppStream;
    18. //functions:
    19. - (BOOL)connect;
    20. - (void)disconnect;
    21. @end
    Alles anzeigen

    Quellcode: AppDelegate.m

    1. #import "AppDelegate.h"
    2. @interface AppDelegate ()
    3. - (void)setupStream;
    4. - (void)goOnline;
    5. - (void)goOffline;
    6. @end
    7. @implementation AppDelegate
    8. @synthesize xmppStream;
    9. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    10. // Override point for customization after application launch.
    11. return YES;
    12. }
    13. - (void)applicationWillResignActive:(UIApplication *)application {
    14. // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    15. // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
    16. [self disconnect];
    17. }
    18. - (void)applicationDidEnterBackground:(UIApplication *)application {
    19. // 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.
    20. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
    21. }
    22. - (void)applicationWillEnterForeground:(UIApplication *)application {
    23. // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
    24. }
    25. - (void)applicationDidBecomeActive:(UIApplication *)application {
    26. // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
    27. NSLog(@"%d",[self connect]);
    28. }
    29. - (void)applicationWillTerminate:(UIApplication *)application {
    30. // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
    31. // Saves changes in the application's managed object context before the application terminates.
    32. [self saveContext];
    33. }
    34. #pragma mark - Core Data stack
    35. @synthesize managedObjectContext = _managedObjectContext;
    36. @synthesize managedObjectModel = _managedObjectModel;
    37. @synthesize persistentStoreCoordinator = _persistentStoreCoordinator;
    38. - (NSURL *)applicationDocumentsDirectory {
    39. // The directory the application uses to store the Core Data store file. This code uses a directory named "de.Steigerwald.Schoolproject" in the application's documents directory.
    40. return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
    41. }
    42. - (NSManagedObjectModel *)managedObjectModel {
    43. // The managed object model for the application. It is a fatal error for the application not to be able to find and load its model.
    44. if (_managedObjectModel != nil) {
    45. return _managedObjectModel;
    46. }
    47. NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"Schoolproject" withExtension:@"momd"];
    48. _managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];
    49. return _managedObjectModel;
    50. }
    51. - (NSPersistentStoreCoordinator *)persistentStoreCoordinator {
    52. // The persistent store coordinator for the application. This implementation creates and returns a coordinator, having added the store for the application to it.
    53. if (_persistentStoreCoordinator != nil) {
    54. return _persistentStoreCoordinator;
    55. }
    56. // Create the coordinator and store
    57. _persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
    58. NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"Schoolproject.sqlite"];
    59. NSError *error = nil;
    60. NSString *failureReason = @"There was an error creating or loading the application's saved data.";
    61. if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]) {
    62. // Report any error we got.
    63. NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    64. dict[NSLocalizedDescriptionKey] = @"Failed to initialize the application's saved data";
    65. dict[NSLocalizedFailureReasonErrorKey] = failureReason;
    66. dict[NSUnderlyingErrorKey] = error;
    67. error = [NSError errorWithDomain:@"YOUR_ERROR_DOMAIN" code:9999 userInfo:dict];
    68. // Replace this with code to handle the error appropriately.
    69. // abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
    70. NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
    71. abort();
    72. }
    73. return _persistentStoreCoordinator;
    74. }
    75. - (NSManagedObjectContext *)managedObjectContext {
    76. // Returns the managed object context for the application (which is already bound to the persistent store coordinator for the application.)
    77. if (_managedObjectContext != nil) {
    78. return _managedObjectContext;
    79. }
    80. NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator];
    81. if (!coordinator) {
    82. return nil;
    83. }
    84. _managedObjectContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType];
    85. [_managedObjectContext setPersistentStoreCoordinator:coordinator];
    86. return _managedObjectContext;
    87. }
    88. #pragma mark - XMPP functions setup
    89. - (void)setupStream {
    90. //function sets up XMPPStream
    91. xmppStream = [[XMPPStream alloc] init];
    92. [xmppStream addDelegate:self delegateQueue:dispatch_get_main_queue()];
    93. }
    94. - (void)goOnline {
    95. XMPPPresence *presence = [XMPPPresence presence];
    96. [[self xmppStream] sendElement:presence];
    97. }
    98. - (void)goOffline {
    99. XMPPPresence *presence = [XMPPPresence presenceWithType:@"unavailable"];
    100. [[self xmppStream] sendElement:presence];
    101. }
    102. - (BOOL)connect {
    103. //connection to XMPPServer
    104. NSLog(@"connect to Server..");
    105. [self setupStream];
    106. //ACHTUNG HARDCODE ZU TESTZWECKEN! \\\\\\\\\\\\\\\
    107. NSString *jabberID = @"user1@unser-Server-;)";
    108. NSString *myPassword = @"password";
    109. //ACHTUNG HARDCODE ZU TESTZWECKEN! ///////////////
    110. if (![xmppStream isDisconnected]) {
    111. return YES;
    112. }
    113. if (jabberID == nil || myPassword == nil) {
    114. return NO;
    115. }
    116. [xmppStream setMyJID:[XMPPJID jidWithString:jabberID]];
    117. password = myPassword;
    118. NSError *error = nil;
    119. if (![xmppStream connectWithTimeout:XMPPStreamTimeoutNone error:&error]) {
    120. UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error"
    121. message:[NSString stringWithFormat:@"Can't connect to server %@", [error localizedDescription]]
    122. delegate:nil
    123. cancelButtonTitle:@"Ok"
    124. otherButtonTitles:nil];
    125. [alertView show];
    126. return NO;
    127. }
    128. return YES;
    129. }
    130. - (void)disconnect {
    131. [self goOffline];
    132. [xmppStream disconnect];
    133. NSLog(@"disconnect");
    134. }
    135. #pragma mark - Core Data Saving support
    136. - (void)saveContext {
    137. NSManagedObjectContext *managedObjectContext = self.managedObjectContext;
    138. if (managedObjectContext != nil) {
    139. NSError *error = nil;
    140. if ([managedObjectContext hasChanges] && ![managedObjectContext save:&error]) {
    141. // Replace this implementation with code to handle the error appropriately.
    142. // abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
    143. NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
    144. abort();
    145. }
    146. }
    147. }
    148. @end
    Alles anzeigen


    Die Konsole gibt aus, dass - (BOOL) connect 1 als return hat, also sollte der connect erfolgreich sein.

    Gruß