iOS Quick Start Guide Not Working

Hi,

I am currently working on a iOS and Android project which requires a BaaS system. I have been comparing different ones online and came across backendless.

I have tried following the iOS quick start guide in Swift for iOS 9.2.1 with no success. I have followed all the steps one by on inside this guide and I get stuck at point 17 and 18 where running the app in the emulator throws an exception defined as Fault.

I have tried also running some of your iOS examples and the same error ‘Fault’ is thrown, this time showing 2002 as the error code.

I have tried using the proper app ID and secret key for both iOS and REST with no success. I pasted the Swift code in section 17 of the quick start guide in the view controller file under viewDidLoad and it crashes always in the AppDelagate class, it seems to crash at the following line:

var backendless = Backendless.sharedInstance()

I don’t know why this is happening. Please can someone help. Is there updated guides for new iOS or updated examples to run latest iOS with Swift?

Hi Dino,

The guide is up to date and if you follow it precisely, you should get a working up. There must be something different about your environment or perhaps you missed a step.

If you do not follow steps 17 and 18 (meaning stop at 16), does the app compile?

Also, could you please attach a screenshot of the project structure and build settings similar to the one we have in step 13?

Regards,
Mark

Hi Mark,

Thank you for such a speedy response. Let me try all this and get back to you. Will actually restart an entirely new project.

Regards,

Dino

Hi Mark,

Jus to update you as I go along. I have created a new project called backendless and I have followed all steps up until step 9 in this guide: Quick Start Guide - Backendless SDK for iOS API Documentation

Here I see some discrepancies between what my Library Search Paths is saying and what your picture in step 9 is saying. Must I remove all the search paths I currently have and only add:

$(inherited)
$(PROJECT_DIR)/lib

Or must I leave it like I have it here (Which is how XCode set it up after I followed all steps up until step 9):

http://support.backendless.com/public/attachments/2eb67f36b6f44bfeb6dbcabd3b73a5de.png</img>

Hi Dino,

If you add $(PROJECT_DIR)/lib (recursive), it should take care of all libraries.

Please take a look at this image, this is how you should have it:
https://backendless.com/wp-content/uploads/2015/11/lib-search-paths.png

Regards,
Mark

Hi Mark,

Ok so I have completed up until step 16. The app compiles and also runs (Doesn’t do anything for now but show blank single view as expected) like normal and I have the following image (Which is the same as your step 13 as you requested).

http://support.backendless.com/public/attachments/1e149d496e0488d61d87e9cd8e7da98d.png</img>

I am going to carry on with the next step and see what happens, but I suspect the same will happen where the app will compile but crash on run.

Where would you suggest I paste the following code:

let backendless = Backendless.sharedInstance()
let user: BackendlessUser = BackendlessUser()
user.email = "michael@backendless.com"
user.password = "my_super_password"
backendless.userService.registering(user)

All inside the viewDidLoad method in my ViewController.swift file? Step 17 wasn’t to clear on this.

Regards,

Dino

Hi Dino,

Yes, you can add it to viewDidLoad. Please let me know how it goes.

Regards,
Mark

So in the meantime I simply added all that code in step 17 into the viewDidLoad method just to see what happens. When I click run I get the same thrown exception. I have attached photo here:

http://support.backendless.com/public/attachments/9af4cfef8b8f9b3707080cdd85fd8016.png</img>

Oh but I forgot to mention something. I am running your Standalone Backendless 3.0.0-16 as a localhost and created my backend app on there and not on your online service. Does this require different steps? How does the emulator know to contact the standalone “offline” server on my laptop through localhost and not the online one through your website?

The backend is throwing an error which is not handled. Try changing the code to:

let backendless = Backendless.sharedInstance()
let user: BackendlessUser = BackendlessUser()
user.email = "michael@backendless.com"
user.password = "my_super_password"
backendless.userService.registering(user,
   response: { (registeredUser : BackendlessUser!) -> () in
       print("User has been registered : \(registeredUser)")
    },
   error: { ( fault : Fault!) -> () in
       print("Server reported an error: \(fault)")
  })

That’s a VERY important detail you missed. Did you do step 11 from the Standalone guide?

https://backendless.com/products/standalone-backendless-quick-start-guide/

Mark

I just saw it now, I feel a little silly over looking this.

This may seem like another silly question, but where do I put this line of code:

backendless.hostURL = @"http://[IP ADDRESS]:8080/api";

Well in Swift it should be:

backendless.hostURL = "http://[IP ADDRESS]:8080/api"

I am seeing now that for some reason the mongodb is not starting. I have tried starting it manually and still no success. Do you know what could be causing this? I assume backendless uses this for user db?

http://support.backendless.com/public/attachments/0e18d6c437a29b69aaabb50751a96f3b.png</img>

Right before you call backendless.initApp.

Many things could cause it:

    not enough memory not enough hard drive space another instance of mongo is running
if MongoDB is not running, things should still work. Mongo is used for analytics.

Ok so I added the following line just before the backendless.initApp method call:

backendless.hostURL = "http://10.0.0.7:8080/api"

I also added the code you suggested as follows inside viewDidLoad:









let backendless = Backendless.sharedInstance()

        let user: BackendlessUser = BackendlessUser()

        user.email = "ddralves@hotmail.com "

        user.password = "123456"

        backendless.userService.registering(user,

            response: { (registeredUser : BackendlessUser!) -> () in

                print("User has been registered : \(registeredUser)")

            },

            error: { ( fault : Fault!) -> () in

                print("Server reported an error: \(fault)")

        })

Now I am getting the following error:

http://support.backendless.com/public/attachments/14069c9d9f9f2f2334fe938d2fa880f4.png</img>

Here is the output (Incase the photo is not too clear):

2016-03-09 10:56:50.996 backendless[42445:119238] App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file.

Server reported an error: FAULT = '-1022' [NSURLErrorDomain] <The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.> 

You need to add this to your info.plist:

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>

More info about it here: http://stackoverflow.com/questions/31254725/transport-security-has-blocked-a-cleartext-http

So I added the following to my Info.plist file:

 
 
 
 
 
 
 
 
<key>NSAppTransportSecurity</key> 
 
	<dict> 
 
 <key>NSAllowsArbitraryLoads</key> 
 
 <false></false> 
 
 <key>NSExceptionDomains</key> 
 
 <dict> 
 
 <key>localhost</key> 
 
 <dict> 
 
 <key>NSIncludesSubdomains</key> 
 
 <true></true> 
 
 <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key> 
 
 <true></true> 
 
 <key>NSTemporaryExceptionMinimumTLSVersion</key> 
 
 <string>TLSv1.1</string> 
 
 </dict> 
 
 </dict> 
 
	</dict>


And it is still throwing the same exception. I have tried with http://10.0.0.7:8080/api and I have tried with just 10.0.0.7 and same thing happens.

The forum topic on stackoverflow you sent me recommends to never set NSAllowsArbitraryLoads as true since this does not follow best practices and they recommend to use the code i posted above.

But why is it still not working?

Below is a pic of my Info.plist in property list view for you to see:

http://support.backendless.com/public/attachments/30b0868f5ae72aaf9c930cac5d8f71ab.png</img>

How about you start with the Cloud version of backendless to at least bypass these completely unrelated to backendless errors and just to see how the basic interaction with the service works?

However, if you still want to get it working with Standalone, I suggest you stick to my recommendation for the changes in info.plist (the changes you made are not what I recommended). Here’s how I have it and it works beautifully:
http://support.backendless.com/public/attachments/205ea30f0a7331dd9b9b354d8e99673a.jpg</img>

205ea30f0a7331dd9b9b354d8e99673a.jpg

Hi Mark,

Thanks for the assistance. Reason I wanted to get it working on a Standalone server (Local or remote) is to test the ease of use and ease of setup for my project and compare it with other BaaS services. Hence why I am trying to get it working on the backendless standalone version.

I agree that these problems seem to exist due to Apple’s new ATS requirements and are not caused by the backendless system directly. However, I feel that others may encounter this problem when trying the standalone backendless and therefore would still be useful to have this content on the forum for them to resolve it (Without having to search the web for it).

I did follow you recommendation of setting the “Allow Arbitrary Loads” to YES (true if editing directly in the source code of the Info.plist) but as mentioned in my previous post, Apple and many other developers on that Stackoverflow topic highly advise against this and to rather allow only certain domains (i.e. in this case my localhost or in deployment cases my actual remote server host) if the domain does not have a minimum TLS 1.2

Therefore this is why I want to make sure I can get this running using Apple’s guidelines rather than just doing the work around. I know this is just a development testing phase, but I like resolving small issues from the beginning so that in proper development and deploying I can potentially avoid small problems. Especially when they are related to security.

But I thank you again for your time and assistance, I did not mean to offend you with my questions. But I just like learning, especially on a system I have never used before (And to this I mean any BaaS system in general).

Kind regards,

Dino