Xamarin Native IPhone and Apple Watch for Plant Stock – Part2
I had developed Xamarin IOS native app for Plant Stock. Here we will extend the app to develop Apple Watch app to provide a similar functionality.
In the Phone app I could enter or scan the Material Code – There is no input Text Box where for you can enter on the watch – There are table controls that you can scroll and Pick. For this Watch App I ddi not want any material to be used and further I don’t want the user to select Plant and Batch – The list of Materials that Watch app user can Choose are determined in SAP – I develop a REST call that will return a List of Materials that a watch app user can choose. This can be changed by SM30 in a Ztable on SAP side.
Here are the steps to create a watch app project using Xamarin
1) Open the Project Created in Part1 in Xamarin Studio
2) Right Click on the solution and choose Add new project and choose IOS – Extension and WatchKitApp
When you do this you have 3 projects – In my case I started with project PlantstockIOS in part1 when I added the wachkit app project I have two more projects
A) PlatnstockIOS ( IPhone app created in Part1)
B) PlantstockIOSWatchExtensionApp – The runs on iPhone – When you want to test you have set this as start up project
C)PlantStockIOSWatchKitapp runs on Watch – This has interface.Storyboard file –
The prjoject C references Project B and B in turn references Project A. Double click on info.plist file and make sure that Bundel ids are correct otherwise
the complier will error out.
3) Select Watchkit App project (Project C) and double click on interface.StoryBoard file – This opens up Xamarin Watch kit designer.
4) Add 3 interfaces controls
a) Starting interface Controller – Add tablecontrol -give it a name, There is a RowController – Assign it class name and id – Drag a label and give it a name
This will display the list of materials that the user is allowed to select to fetch the stock records from SAP
b) The Second will also be very similar – this will display records giving break down by Plant, Location and Batch – You can Click on this to display a details record
c) This interface control had 5 labels that will display Material ,Plant, Location, ,Batch and Stock – If the stock is less than 10 the color will be displayed as red otherwise green
5) When ever you give a name to the controls that you added in storyboard the corresponding Classes are created in the Extension project and you have write the code in the extension project.
6) Some of Events that required coding in the Watch kit interface to make the application happen
a) async overrid void WillActivate() – In this I call SAP to get Materialist – await getSAPMaterial() and load the rows in the first Controller
b) overrid void DidSelectRow
get the row that the user clicked on – the row index is parameter to this call
c) override NSObject GetcontextForSeque
get the selectedRow (index is parameter for this call) and pass the selected material to the next call
d) Second Controller –
Get the Selected Parameter from the context material = context.ToString();
e) async overide void willActivate()
await getstock(material) – Call SAP to get the stock records
bind the records to the table rows
f)override NSobject GetContextForSegue – Get the selected record to be passed on the next controller
7) Third Controller Detail Record – Again get the different fields check qty for > 10 and display green other wise red. All this is done in the WillActivate method of this controller
The Current Version of the apple Watch requires phone app (Extension app) – The recently accounced 2.0 does not require phone app – Xamarin has announced the release of preview version which I have not yet explored. As Apple Watch is becoming popular I feel that for C# developer developing SAP Based Apple Watch should be interesting .