This is a migrated thread and some comments may be shown as answers.

Call WebAPI via DataSource to fillfull listview

4 Answers 132 Views
ListView - Xamarin.iOS
This is a migrated thread and some comments may be shown as answers.
Mansi
Top achievements
Rank 1
Mansi asked on 18 Aug 2016, 02:23 AM

Hello, 

I'm trying to call http://lotmaker.dumouchelles.com:8082/api/AuctionMobile

and receive json via data source and show it in tableView or ListView.

am trying something like 

 

base.ViewDidLoad();

            UITableView tableView = new UITableView(this.View.Bounds);

            this.View.AddSubview(tableView);
            //string url = "http://api.myjson.com/bins/3kj37";
            string url = "http://lotmaker.dumouchelles.com:8082/api/AuctionMobile";

            dataSource.LoadDataFromURL(url, TKDataSourceDataFormat.JSON, "AuctionMobile", (NSError err) =>
            {
                if (err != null)
                {
                    Console.WriteLine("Can't connect with the server!");
                    return;
                }
                this.dataSource.DisplayKey = "LotNumber";
                tableView.DataSource = this.dataSource;
            });

 

Any thought why I'm not getting data ? 

 

Thanks

TYK

4 Answers, 1 is accepted

Sort by
0
Lance | Manager Technical Support
Telerik team
answered on 18 Aug 2016, 09:50 PM
Hi,

Unfortunately. even though you're using a TKDataSource, debugging your API endpoint is out of the scope of Telerik Support. However, I have some suggestions that may be useful.

I tested your first test API json and it works fine, here's the full code and attached is a screenshot at runtime (notice I have the rootItemKeyPath and DisplayKey properly defined)

public override void ViewDidLoad()
{
            base.ViewDidLoad();
             
            UITableView tableView = new UITableView(this.View.Bounds);
            this.View.AddSubview(tableView);
             
            NSString url = new NSString("http://api.myjson.com/bins/3kj37");
 
            dataSource = new TKDataSource();
            dataSource.LoadDataFromURL(url, TKDataSourceDataFormat.JSON, "fridayLotList", error =>
            {
                if (error != null)
                {
                    Console.WriteLine("Can't connect with the server!");
                    return;
                }
                 
                dataSource.DisplayKey = "Inv_Prim_Cat_Desc";
                tableView.DataSource = dataSource;
            });
}


I notice your second URL doesn't work, the API's server is not responding lotmaker.dumouchelles.com/API, does this API need authentication? Take a look at how to authenticate using Telerik DataSource

Lastly, you should check your debug output window to make sure you haven't forgotten to add your insecure (http) URL to the safe list. iOS only allows from https connections, see here for more info on how to accomplish this.

Here's what the error looks like in the console:
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.

To fix this for the test API, add the following to your Info.plist:

<key>NSAppTransportSecurity</key>
  <dict>
    <key>NSExceptionDomains</key>
    <dict>
      <key>api.myjson.com</key>
      <dict>
        <key>NSExceptionMinimumTLSVersion</key>
        <string>TLSv1.0</string>
        <key>NSExceptionRequiresForwardSecrecy</key>
        <false/>
        <key>NSExceptionAllowsInsecureHTTPLoads</key>
        <true/>
        <key>NSIncludesSubdomains</key>
        <true/>
      </dict>
    </dict>
  </dict>


I hope I was able to clarify some pain points, if this still doesn't work. Please update this thread when you've got a working API.

Regards,
Lance | Tech Support Engineer, Sr.
Telerik by Progress
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Accepted
Lance | Manager Technical Support
Telerik team
answered on 19 Aug 2016, 03:04 PM
Hello Mansi,

I wanted to do a quick follow up to let you know that if you decide to use TKListView
 instead of UITableView, make sure you call ReloadData() after setting the data source.

Here's my previous example but using a TKListView instead:

public override void ViewDidLoad()
{
            base.ViewDidLoad();
             
            TKListView listView = new TKListView(this.View.Bounds);
            listView.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
            this.View.AddSubview(listView);
             
            NSString url = new NSString("http://api.myjson.com/bins/3kj37");
 
            dataSource = new TKDataSource();
            dataSource.LoadDataFromURL(url, TKDataSourceDataFormat.JSON, "fridayLotList", error =>
            {
                if (error != null)
                {
                    Console.WriteLine("Can't connect with the server!");
                    return;
                }
                 
                dataSource.DisplayKey = "Inv_Prim_Cat_Desc";
                 
                listView.WeakDataSource = this.dataSource;
                listView.ReloadData();
            });
}


Regards,
Lance | Tech Support Engineer, Sr.
Telerik by Progress
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Mansi
Top achievements
Rank 1
answered on 19 Aug 2016, 06:15 PM

it's working.Thank You. Now will start look into custom cell

0
Lance | Manager Technical Support
Telerik team
answered on 24 Aug 2016, 05:33 PM
Hi Mansi,

I'm happy to hear everything is working for you. If you have any further questions about this specific issue you can reply here.

If you have any trouble or have questions about cells, please open a new thread where the thread title matches the discussion.

Thank you for contacting Support and for choosing Telerik.

Regards,
Lance | Tech Support Engineer, Sr.
Telerik by Progress
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
ListView - Xamarin.iOS
Asked by
Mansi
Top achievements
Rank 1
Answers by
Lance | Manager Technical Support
Telerik team
Mansi
Top achievements
Rank 1
Share this question
or