Skip to Content

This is part 3 of my series on creating an iOS application that connects to an SAP system using the Sybase Unwired Platform.

We are going to use our model from part 2 to enable our iOS app to communicate with our back-end SAP system (using the function modules from part 1) through the Sybase Unwired Platform.

First we need to do a little bit of groundwork on our Sybase Unwired Platform server. Go to your Sybase control centre (usually https://supServerURL:8283/scc) and login (default credentials supAdmin and s3pAdmin) and go to the applications area listed along the left side of the console. Under the application connections tab we now need to create a new entry for our device. We do this by selecting “Register”.

/wp-content/uploads/2012/11/1_153648.png

The user I am using is “supTut1”. My template should have been automatically created for me and in my case is SupTut1_preConfLogin. The only other setting I am worried about is my activation code (password) which I have specified to be the very secure “123”.

There may be some extra configuration required in your “Application Connection Template” for your app to work correctly and these settings are generally environment specific. For more information on these configurations please visit the Sybase info-center.

Now we are ready to start coding our app. Rather than go through a process that is pretty well documented on the Sybase info-centre, the first step is to setup a new iOS project in Xcode called “SUPTut” by following the instructions for “Developing an iOS application” as can be found here:

http://infocenter.sybase.com/help/topic/com.sybase.infocenter.dc01213.0213/doc/html/mqu1264543829068.html

Make sure to continue and follow the next section on “Adding source code files, libs and resources” which can be found here:

http://infocenter.sybase.com/help/topic/com.sybase.infocenter.dc01213.0213/doc/html/eka1321300509413.html

Next, follow the instructions for “Configure Build Settings” found here:

http://infocenter.sybase.com/help/topic/com.sybase.infocenter.dc01213.0213/doc/html/eka1321302920114.html

Finally, you will need a file called a “CallbackHandler” which handles all of the messages received from the Sybase Unwired Platform during communications. Sample files can be found for this here.

Once all these steps are complete, the next step is to add our generated code to our project. This is the code we ended up with at the end of part 2 of this series. This code represents the ability for us to access the data we need via the SUP libraries that you included in your Xcode project.

So we are now ready to start getting our app ready for its first connection. For ease of coding I create a new “NSObject” subclass called “ConnectionController”. This class will take care of all of the connection APIs.

My ConnectionController.h file will have defined a single static method to trigger our connection.

/wp-content/uploads/2012/11/2_153651.png

Our ConnectionController.m will contain our static method implementation as well as a single instance method. But first, lets start with our imports:

/wp-content/uploads/2012/11/3_153652.png

Next we need to define any properties we will need which in our case is one. This will be our “CallbackHandler”.

/wp-content/uploads/2012/11/4_153653.png

As we only reference this class statically we need a static instance to reference as follows:

/wp-content/uploads/2012/11/5_153654.png

Next we can implement our static method “beginApplicationSetup”. The method will first check if this class has been instantiated before, if not it will create a new instance to be stored in our static variable. Finally it will call our (yet to be defined) instance method for connecting to the server.

/wp-content/uploads/2012/11/6_153655.png

Now we must define our instance method, which we will call “setupApplicationConnection”. The first thing we will do in this method is to setup a “SUPApplication” object and set our callback handler for the app.

/wp-content/uploads/2012/11/7_153656.png

Next we setup our connection properties. This is generally over port 5001 on your unwired server and is called “Message Based Synchronisation” or MBS. All SUP connections are initiated using MBS over this port. At this stage of the registration the application is identifying itself to the server and checking if it is able to register using the credentials we created on the SUP server earlier. We also create our local database on our device at this stage.

/wp-content/uploads/2012/11/8_153657.png

Our next step is to setup our synchronization profile. This is the profile used for actual data synchronization. The protocol used is called Replication based synchronization and usually takes place over ports 2480/2481 (insecure/secure).

Our final step here just prior to connection is to setup our callback handler on our database and then set our configured “SUPApplication” object on our database class.

/wp-content/uploads/2012/11/9_153658.png

So now we are ready for our connection code, which goes at the end of this instance method:

/wp-content/uploads/2012/11/10_153659.png

For this tutorial we are going to go for a simple UI on our application and rely on the Xcode debugger for most of the important information. Our application will have 4 buttons.

/wp-content/uploads/2012/11/11_153660.png

  • Start connection will simply register our device with the SCC over port 5001.
  • Synchronise will synchronize our data from SAP down to our device
  • Find All – will give us a count indicating how many rows of data we have on the device
  • Create new Entry will create a new entry on SAP using our create operation in our model.

Start Connection:

/wp-content/uploads/2012/11/12_153661.png

Synchronise:

/wp-content/uploads/2012/11/13_153662.png

Find All:

/wp-content/uploads/2012/11/14_153663.png

And finally, Create new Entry. Simply taking the class of the MBO in our case “SupTut1BusinessData” and calling the method “getInstance” create new entries.  Once we have set any properties on this new instance of a line of our “BusinessData” MBO we call “save” on it. Once saved, we call “submitPending” which, submits all pending operations on our MBO line. Finally for good measure we call synchronise.

/wp-content/uploads/2012/11/15_153664.png

And that is it; once you have added these actions to your view and hooked up your buttons you can give your app a try. On first launch, you will need to register your device for the first time. This can take about 30 seconds.

  • Tap the “Start connection” button, and watch the Xcode console. If you have everything setup correctly you should see various messages scrolling as your SUP server sends various configuration information to your device. Eventually you will see a status of 203, which means successfully registered (for re-connects this would be a 103).
  • Once you are connected you can synchronise.
  • Once synchronised you can check how many lines of data you have on your device, which should now match SAP.
  • Finally you can then create a new entry on SAP by tapping that button. After a few seconds you should be able to see this new line on your SAP system.

If all of this works then congratulations you now have a fully working SUP/SAP sample iOS application, which both receives and sends data.

This tutorial is a small snapshot of how to get an end-to-end Sybase Unwired Platform based SAP mobile app working. There are a lot more options, configurations and options available under the hood and I recommend checking out the Sybase documentation for more information on these.

In the meantime – Happy coding!

To report this post you need to login first.

10 Comments

You must be Logged on to comment or reply to a post.

  1. Ponnu Rose

    Hi,
    we have followed all the steps mentioned in the blog.
    StartConnection,Synchronise,Findall worked well.
    fourth method i tried was to fetch the details of all the flights having airline id AA.

    We have done the code as below.

      

      Flight_DetailsPersonalizationParameters *pp = [Flight_DetailsFlightDB getPersonalizationParameters];

        [pp setAirline_PK:@”AA”];

        [pp save];

       

        while([Flight_DetailsFlightDB hasPendingOperations])

        {

            [NSThread sleepForTimeInterval:1];

           

        }

       

        [Flight_DetailsFlightDB beginSynchronize];

       

        Flight_DetailsFlight_MBO *flight = nil;

        SUPObjectList *cl = nil;

        cl =[Flight_DetailsFlight_MBO findAll];

       

       

        if(cl && cl.length > 0)

        {

            int i;

            for(i=0;i<cl.length;i++)

            {

                flight = [cl item:i];

                 if(flight)

                 {

                     NSLog(@”details are %@”,flight.CITYFROM);

                 }

            }

        }

       

       While running the app i am getting the error as follows

    1)

    error retriving public key from serversource. code 515.

    2)

    error sending request to server Native Error

    please help us to fix it

    (0) 
  2. Mark Teichmann

    Hi Brenton,

    nice blog, strange that I discovered it only today…

    I like the usage of the static ConnectionController. I implemented the connection process following the Sybase help pages but this is very cumbersome.

    Cheers,  Mark

    (0) 
  3. Steffen Boelaars-Spurnรก

    Good concise write-up this. I had to make 2 amendments to make it work for me:

    1) You state to follow some of the iOS app setup steps outlined on the Sybase site. But I found that I should NOT remove the SUP101 folder, and NOT add the demo files from SUP_iOS_Custom_Dev_Tutorial_code.zip with the exception of the CallbackHandler.h/.m files.

    2) At some point you’re calling [properties setFarmId:0]; on the SUPConnectionProperties object. I found that this throws a cryptic error that only disappears when changing the variable from an int to a string like this: [properties setFarmId:@”0″];

    Those two things actually made me search and dig all over the place to figure out what is going on/wrong probably giving me more insight than the tutorial intended, so job well done ๐Ÿ˜‰ Thanks!

    (0) 
  4. Carsten Wedege

    Has somebody out there created this demo for the SUP 2.2 SP04 environment

    I would very much like to get my hands on a project export or a detailed guide as I find it very hard to understand exactly how to merge the SUP101 tutorial with this SUPTut tutorial and get it build.

    Kind Regards

    Carsten

    (0) 
    1. Brenton OCallaghan Post author

      Hi Carsten,

      Could you share some more information about where it is not working – it would be good to see if there is a common problem that perhaps others have seen before.

      The APIs have most definitely changed since I wrote this piece so it would be good to understand where the gaps are now.

      Thanks,

      Brenton.

      (0) 
      1. Carsten Wedege

        As I am not used to this environment and is not an experienced developer I am struggling to understand how to merge this tutorial with the standard Sybase SUP101 tutorial you refer to. Exactly how much of the SUP101 code should I include and do I need to do some modifications to the SUP101 part? Reading one of the previous posts I thought that maybe I should not delete the SUP101 folder and not add the tutorial files from the Sybase SUP101 zip archive. But doing this just gave me a number of other build errors. So in my last attempt I have tried to follow the instructions you refer to on the Sybase site but for the SUP2.2 SP04 version.
        At the moment I get a number of build errors when I try to build the project as described in the “Configure Build Settings” link. I have not even gotten to the part where I have to add the callbackhandler.

        That is why I thought it would be nice if an experienced developer had done the work or a reference to where I could find a similar demo. Because what I really need is to get my hands on a simple demo that can show that it is possible to manipulate data on an SAP system using a SUP / SMP app on a mobile device connected to our new SUP / SMP server (we have both versions 2.2 and 2.3).

        Kind Regards

        Carsten

        (0) 

Leave a Reply