chat-sdk / chat-sdk-ios

Chat SDK iOS - Open Source Mobile Messenger
http://sdk.chat
Other
915 stars 274 forks source link

Need help in chat sdk setup #116

Closed sunilhs1986 closed 7 years ago

sunilhs1986 commented 7 years ago

Hi,

I am trying to integrate the chat sdk into our project, but i want to setup in different view controller rather than appdelegate has we have other features in app as well.

Regards Sunil

simonsmiley64 commented 7 years ago

Hi @sunilhs1986,

This should be easy to achieve, you'll need follow a few steps:

  1. You should still keep most of the initialisation code in the App Delegate, this will ensure the Chat SDK is configured and ready, you could also put this in your app login page.
  2. Instead of loading the Chat view controller in your app delegate just load the view you want when you want it. I would do this by sub-classing the views you want to use and then loading them up into your project.

Things to watch out for:

Let me know if this helps get you on the right path,

Simon

sunilhs1986 commented 7 years ago

Hi Simon,

Thanks for your response.

I integrated the way you explained above, but its crashing.

Steps: Step 1. I open the app which i have built and then login to chat sdk and i was able to message to the registered user. Step 2. Navigate to a different section. Step 3. I open the chat ui and try to message the user and click send button it crashes.

Terminating app due to uncaught exception 'NSObjectInaccessibleException', reason: 'CoreData could not fulfill a fault for '0xd000000000040002 <x-coredata://95E37307-1CBD-425C-828B-D8317E4A3CFB/CDThread/p1>''

Could you please help me on this. Thanks in advance.

Regards Sunil

simonsmiley64 commented 7 years ago

Hi @sunilhs1986,

Can you add the code showing how you are loading the Chat UI?

I would do it in the following way:

  1. Subclass the BPrivateThreadsViewController.h
  2. Present this new view controller as you normally would
  3. Make sure that the user has threads and that these threads appear in your subclassed view controller

Making this change should require very little code. If your Chat SDK was working correctly before then loading up a view controller from somewhere else should not cause any issues.

It is worth remembering that the app stores the user's conversations on it so the conversations might be showing up without the app being correctly connected to Firebase. This could mean you are trying to send a message without being logged in.

I would open up Firebase and ensure that the user is correctly logged in, you can do this by changing some information on the user profile and seeing the search index updating.

Otherwise though without actively looking at your project it is very difficult to know exactly what is going on. If you wanted to buy some priority support then I could have a look at this for you and send you and put together an example project with this functionality, let me know if this is something you would be interested in.

Simon

sunilhs1986 commented 7 years ago

Hi Simon,

i am using the below code for launching fire base ui.

     [BNetworkManager sharedManager].a = [[BFirebaseNetworkAdapter alloc] init];

        // Set the default interface manager
        [BInterfaceManager sharedManager].a = [[BDefaultInterfaceAdapter alloc] init];

        [BStorageManager sharedManager].a = [[BCoreDataManager alloc] init];

        // This is the main view that contains the tab bar
        UIViewController * mainViewController = [[BAppTabBarController alloc] initWithNibName:Nil bundle:Nil];

        // Set the login screen
        [BNetworkManager sharedManager].a.auth.challengeViewController = [[BLoginViewController alloc] initWithNibName:Nil bundle:Nil];

        NSLog(@"%d",[BNetworkManager sharedManager].a.auth.userAuthenticated);

        [appdelegate.window setRootViewController:mainViewController];

For priority support is there any cost involved ?

Regards Sunil

simonsmiley64 commented 7 years ago

Hi @sunilhs1986,

You can get information on priority support on our website here

I would first recommend checking the Chat SDK is working on your accounts:

  1. Download the Chat SDK and test it on the regular accounts - it should all work as expected
  2. Use the Chat SDK wiki and tutorials to change it to your accounts. Test the functionality once again
  3. Then make attempts to open the Chat SDK window from a new window.

For the third step it should be easy, when you first login it might be that your user isn't logged in. This should raise the BLoginView as a challenge view. Once you login you can load any view by initialising it and presenting it.

For example - in this example I have subclassed the BContactsViewController - I then just load and show it as normal. It will then show the contacts view controller as expected and can be modified within the subclass:

UIViewController * vc = [[BCustomContactsViewController alloc] init];

[self.navigationController pushViewController:vc animated:YES];

Let me know if this helps,

Simon

sunilhs1986 commented 7 years ago

Hi Simon,

I would like to know if i buy a priority support for 1 hour ($79.99) will be you sending us a sample project with our use case.

Also is this priority support is one time support for 1 hour or something else. Let me know if you can support us with a sample code and will pay this cost immediately.

Regards Sunil

simonsmiley64 commented 7 years ago

Hi @sunilhs1986,

How we support is really up to you. If you want you can send us a copy of your project and we can spend an hour adding the Chat SDK (if you do decide to go for this option please ensure your project compiles and runs correctly, it would be annoying to waste time troubleshooting this option). Otherwise you can let me know exactly what you are after and I can put together a test project and documentation for it.

In answer to your second point, when you buy an hour support it is a one time support, depending on the issue you are facing will depend on how much help we can provide within the support period.

In the case of this ticket I would expect do to the following steps providing support:

I'll then provide these test documents to you via a dropbox link (let me know if a different way would be more convenient).

If you do buy the priority support please comment here so I can allocate some time to get this done as soon as possible and also email me a detailed description of the exact problems and fixes you are looking for. This will help me make best use of my time while supporting this issue,

Simon

sunilhs1986 commented 7 years ago

Hi Simon,

I have purchased 1 hour support for Chat SDK and attached is the receipt for same.

I have created a sample project with Chat SDK frame work u can run the project and you will see 2 buttons on click of Chat SDK button i would like to load the chat feature.

You can refer to MenuViewController.m class for button action(chatPressed) for chat event. If u have any difficulties in running the project u can create a sample project with similar ui and send us.

Let us know if you need anything else.

Thanks in advance.

menu-page purchase-receipt InjuryHelp.zip

Regards Sunil

simonsmiley64 commented 7 years ago

Hi @sunilhs1986,

I have created the project and gone through the following steps:

  1. Created a test project with the buttons as above (It was quicker for me to make my own than download yours)
  2. Clone the Chat SDK and add it to the project
  3. Configure the Chat SDK based on the instructions in the wiki

This gets us to the point where the project runs and the Chat SDK opens immediately. At this stage I also load the Chat SDK and ensure that logging on correctly connects me with the database.

The importance of following these steps until now is so that we ensure the Chat SDK is configured correctly and is ready to be used.

USING THE CHAT SDK

We are now ready to start using the Chat SDK. The first thing we need to worry about is the login flow. A user has to login to be able to use the Chat SDK. You can put the login flow where ever you like - you just need to make sure that the user HAS to login if they want to get to the chat. We also have the Chat SDK set up flow, this is best kept in the app delegate to ensure it is run correctly.

In the example project I have added a line in the BViewController.m:

// De-comment for login on first screen

If you de-comment the viewDidAppear and showLoginScreen functions on this screen then the app will prompt you to login as soon as you load the app. These functions have been copied directly from the BAppTabBarViewController. All it does it raise the login screen if there is not a logged in user. This can be called - or checked from anywhere.

Loading the Chat SDK somewhere else

I assumed this wasn't the method you were after so I have commented this out for now. You can now see two buttons: Chat SDK (load the Chat SDK) and thread view (load a thread view - you must be logged in for this to work correctly).

Loading the ChatSDK The code to load the Chat SDK is very simple:

- (IBAction)chatSDKButtonPressed:(id)sender {

    if (!_mainViewController) {
        _mainViewController = [[BAppTabBarController alloc] initWithNibName:nil bundle:nil];
    }

    [self presentViewController:_mainViewController animated:YES completion:nil];
}

(you can see this in the chatSDKButtonPressed function)

If you load up the project and click the ChatSDK button it will load up the Chat and immediately prompt the user to sign in.

Well done you have now successfully loaded the Chat SDK. The important thing now is to work out the Chat SDK flow to allow users to return to your main app and exit the Chat area.

This leads me onto another important point, you should never be directly changing code inside the Chat SDK, instead you should always subclass to ensure that you can update with the latest Chat SDK code. It also means any modifications won't break other functionality in the Chat SDK.

You will see that I have changed the challenge view controller to the BSunilLoginViewController subclass and in this view I have added a back button to close the Chat SDK.

Now we look at getting back from the Chat SDK once logged in. Load up the project, click Chat SDK then login (just make up a password and user name then click register) you will access the main tab view of the Chat SDK. Click the public threads or contact tab and you'll see I have added a "back to app" button. This will take you back to the main view.

If you look in the code you'll see I have subclassed some of these tabs for you:

BSunilPrivateThreadsViewController BSunilContactsViewController

This means that they have the same functionality as the original plus a bit I added into the project.

If you look in these view controllers you can see that we only need to dismiss the Chat SDK to get rid of it and return to the main view:

[self dismissViewControllerAnimated:YES completion:nil]; 

You will also notice I subclassed the BDefaultInterfaceAdapter. This was so I could set the tabBar tabs without changing the Chat SDK code:

    // Set the default interface manager
    [BInterfaceManager sharedManager].a = [[BSunilInterfaceAdapter alloc] init];

In the app delegate I set the new interface manager

-(UIViewController *) publicThreadsViewController {
    return [[BSunilPublicThreadsViewController alloc] init];
}

-(UIViewController *) contactsViewController {
    return [[BSunilContactsViewController alloc] init];
}

I then override the tab methods to return the subclasses.

Finally:

Accessing the threads view

MAKE SURE YOU ARE LOGGED IN. Then click on the threads button in the main view. This will load up the Public threads view controller. This is to show how easy it is to load a Chat SDK view controller from anywhere in the app. This would be useful if you want to login the user in immediately then add the threads view controller in a custom area of your app (or add any Chat SDK view controller in an area of your app).

Conclusion

To conclude, completing this up took substantially longer than a single hour. Because of this, and not wanting to leave it half finished I had to write up this documentation much faster than I would have liked. It should be completed though and has been tested so should all be in working order. You can access the project at this URL: https://www.dropbox.com/sh/j5jsbrv0hi4r1ko/AAAJeJ08fPKyMH_wBsgdh31Fa?dl=0

Please download it immediately as the URL will only be maintained for about a week.

If you need further help then I can answer basic questions on this in this thread - if you want me to continue working on the documentation and project examples I can provide more priority support if you want it.

Please let me know how you get on, once you get the hang of the Chat SDK it is very easy to use and manipulate so hopefully this tutorial will get you on your way.

Simon

sunilhs1986 commented 7 years ago

Hi Simon,

Thanks for you support and the sample project you have sent.

I tried to build the project i am getting the below error. Can u please check it ?

/Users/sunil.h.shivamurthy/Library/Developer/Xcode/DerivedData/TestSunilProject-gzpqdazwgryzuqemjokziaotttih/Build/Intermediates/TestSunilProject.build/Debug-iphonesimulator/TestSunilProject.build/Script-AD62BC906B707396BD9C9A04.sh: line 2: /Users/sunil.h.shivamurthy/Downloads/Sunil/TestSunilProject/Pods/Target Support Files/Pods-TestSunilProject/Pods-TestSunilProject-frameworks.sh: Permission denied

It says permission denied.

Regards Sunil

simonsmiley64 commented 7 years ago

Hi @sunilhs1986,

Can you confirm how you are running it? Are you loading up the file as shown below?

The project is working for me from the Dropbox file just fine

screen shot 2017-08-30 at 20 57 56

If this doesn't work it might be worth changing the console to the project file and calling pod update to ensure the pods are up to date but they should be.

screen shot 2017-08-30 at 21 00 05

Let me know if you continue to have issues as it should be working fine,

Simon

sunilhs1986 commented 7 years ago

Hi Simon,

I was able to run the project now and pod update worked but its crashing in BCoreDataManager.m class in this method "NSURL * momURL = [NSURL fileURLWithPath:path];"

Regards Sunil

simonsmiley64 commented 7 years ago

Hey @sunilhs1986,

Can you confirm a few things:

  1. Did you delete and reinstall the app when you ran this - I would recommend deleting any Chat SDK apps from your device / simulator before running it
  2. Can you post a full stack trace if the problem persists after 1. this will help me find the issue as it currently compiles and runs on my devices.

Simon

sunilhs1986 commented 7 years ago

Hi Simon,

Yes i deleted the project and compiled in simulator. Here is error i am getting when application loads.

Applications/Xcode 8.3.3.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/AssetsLibraryServices.framework/AssetsLibraryServices (0x11a083cc0) and /Applications/Xcode 8.3.3.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/PhotoLibraryServices.framework/PhotoLibraryServices (0x119e9a6f0). One of the two will be used. Which one is undefined. 2017-08-31 15:57:49.715 TestSunilProject[35218] [Firebase/Core][I-COR000022] Firebase Analytics is not available. 2017-08-31 15:57:49.871 TestSunilProject[35218:512689] Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: ' -[NSURL initFileURLWithPath:]: nil string parameter' *** First throw call stack: ( 0 CoreFoundation 0x000000010775eb0b exceptionPreprocess + 171 1 libobjc.A.dylib 0x0000000106bce141 objc_exception_throw + 48 2 CoreFoundation 0x00000001077c7625 +[NSException raise:format:] + 197 3 Foundation 0x000000010716b727 -[NSURL(NSURL) initFileURLWithPath:] + 127 4 Foundation 0x000000010716b694 +[NSURL(NSURL) fileURLWithPath:] + 45 5 ChatSDKCoreData 0x000000010650c5fb -[BCoreDataManager managedObjectModel] + 171 6 ChatSDKCoreData 0x000000010650c795 -[BCoreDataManager persistentStoreCoordinator] + 245 7 ChatSDKCoreData 0x000000010650c2c9 -[BCoreDataManager managedObjectContext] + 57 8 ChatSDKCoreData 0x000000010650b9d0 -[BCoreDataManager fetchEntitiesWithName:withPredicate:] + 176 9 ChatSDKCoreData 0x000000010650bca9 -[BCoreDataManager fetchEntityWithID:withType:] + 217 10 ChatSDKFirebaseAdapter 0x000000010653265c -[BFirebaseCoreHandler currentUserModel] + 188 11 ChatSDKFirebaseAdapter 0x000000010653282f -[BFirebaseCoreHandler goOnline] + 95 12 ChatSDKCore 0x00000001064df7c6 -[BNetworkManager appDidBecomeActive] + 150 13 CoreFoundation 0x00000001076fdc2c CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER + 12 14 CoreFoundation 0x00000001076fdb29 CFXRegistrationPost + 425 15 CoreFoundation 0x00000001076fd892 CFXNotificationPost_block_invoke + 50 16 CoreFoundation 0x00000001076c1102 -[_CFXNotificationRegistrar find:object:observer:enumerator:] + 1826 17 CoreFoundation 0x00000001076c0261 _CFXNotificationPost + 673 18 Foundation 0x0000000107140ca4 -[NSNotificationCenter postNotificationName:object:userInfo:] + 66 19 UIKit 0x0000000108260914 -[UIApplication _stopDeactivatingForReason:] + 1052 20 UIKit 0x0000000108269a52 -[UIApplication _runWithMainScene:transitionContext:completion:] + 2843 21 UIKit 0x00000001082667f3 -[UIApplication workspaceDidEndTransaction:] + 182 22 FrontBoardServices 0x000000010c2f35f6 FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK + 24 23 FrontBoardServices 0x000000010c2f346d -[FBSSerialQueue _performNext] + 186 24 FrontBoardServices 0x000000010c2f37f6 -[FBSSerialQueue _performNextFromRunLoopSource] + 45 25 CoreFoundation 0x0000000107704c01 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17 26 CoreFoundation 0x00000001076ea0cf CFRunLoopDoSources0 + 527 27 CoreFoundation 0x00000001076e95ff CFRunLoopRun + 911 28 CoreFoundation 0x00000001076e9016 CFRunLoopRunSpecific + 406 29 UIKit 0x000000010826508f -[UIApplication _run] + 468 30 UIKit 0x000000010826b134 UIApplicationMain + 159 31 TestSunilProject 0x00000001063977cf main + 111 32 libdyld.dylib 0x000000010aa8865d start + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException

sunilhs1986 commented 7 years ago

Hi Simon,

I was finally able to run the project in simulator, but in device its crashing below is the error log.

dyld: Library not loaded: @rpath/Firebase.framework/Firebase Referenced from: /private/var/containers/Bundle/Application/8591F32F-203B-4E0D-8B60-FE40914028F4/TestSunilProject.app/Frameworks/ChatSDKFirebaseAdapter.framework/ChatSDKFirebaseAdapter Reason: image not found

Regards Sunil

simonsmiley64 commented 7 years ago

Hi @sunilhs1986,

If you can get it to run in the simulator that should be fine. The example project is only to show you how to load the Chat SDK in different areas of your actual project. If you work through the code and the documentation you should be able to copy it into your project to get the functionality you are after.

Simon

sunilhs1986 commented 7 years ago

Hi Simon,

I just ran the sample code u shared in device, could you please let me know why its crashing.

Regards Sunil

simonsmiley64 commented 7 years ago

Hi @sunilhs1986,

I don't know why the sample code is crashing on your device, the sample project is designed to show you how to architect the Chat SDK code. It currently compiles and runs on both my devices and my simulator.

You previously mentioned the project was running on a simulator, this should be enough to understand the flow of the test app and incorporate it into your project.

Simon

sunilhs1986 commented 7 years ago

Hi Simon,

I have tried all possible ways but its not loading on device. i have integrated the chat sdk into my project and still the issue persists. Below is the error which i am getting.

dyld: Library not loaded: @rpath/Firebase.framework/Firebase Referenced from: /private/var/containers/Bundle/Application/EA33044D-4EAE-4523-945A-A0D4E08AD370/SampleApp.app/Frameworks/ChatSDKFirebaseAdapter.framework/ChatSDKFirebaseAdapter Reason: image not found

Please help us on this.

Regards sunil

simonsmiley64 commented 7 years ago

Hi @sunilhs1986,

I won't be able to troubleshoot this issue without having your project and manually adding the Chat SDK to it myself. For this you would need to purchase more priority support or buy the integration package.

This seems to be an issue with your project or set up instead of a problem with the Chat SDK which runs and compiles fine when downloaded.

Simon

sunilhs1986 commented 7 years ago

Hi Simon,

Thanks for getting back. Actually, we develop white label Apps for lawyers. We have over 300 law firm clients. We will be implementing your chat solution on all their Apps and our future clients.

We agree to pay your company $100 for each lawyer client App (iPhone and Android). But first, we need our pilot client to test the chat solution successfully.

Hence, I would request you to resolve the bugs in the sample code which u have sent and send us the working code.

I have tried all possible ways but its not loading on device. Below is the error which i am getting.

dyld: Library not loaded: .framework/Firebase Referenced from: /private/var/containers/Bundle/Application/EA33044D-4EAE-4523-945A-A0D4E08AD370/SampleApp.app/Frameworks/ChatSDKFirebaseAdapter.framework/ChatSDKFirebaseAdapter Reason: image not found

Please help us on this.

Thanks, Sunil

bensmiley commented 7 years ago

Hi Sunil,

When I added the latest version of the library using the instructions outlined here the project complied just fine. Here's the updated project: Sunil.zip

When you get it you should run pod install then find the setup_links.sh script which is inside the TestSunilProject and run sh setup_links.sh. This will setup the symbolic links to the Firebase Adapter.

Thanks,

Ben

sunilhs1986 commented 7 years ago

Thank you Ben for timely help and support , the new code which you sent works perfectly on device.

Regards Sunil

AnotherWayIn commented 5 years ago

It would be soooo helpful if this could be explained fully in Swift

mahesh-ivy commented 7 months ago

Hi Simon,

I was finally able to run the project in simulator, but in device its crashing below is the error log.

dyld: Library not loaded: @rpath/Firebase.framework/Firebase Referenced from: /private/var/containers/Bundle/Application/8591F32F-203B-4E0D-8B60-FE40914028F4/TestSunilProject.app/Frameworks/ChatSDKFirebaseAdapter.framework/ChatSDKFirebaseAdapter Reason: image not found

Regards Sunil

can you please help me understand what you did to fix the issue of initFileURLWithPath nil string parameter.