SUP iPhone Development

Published on December 2016 | Categories: Documents | Downloads: 28 | Comments: 0 | Views: 201
of 48
Download PDF   Embed   Report

Comments

Content

Sybase Unwired Platform: How to develop an iPhone Application using SUP.

Applies to:
Sybase Unwired Platform 1.5.2 onwards

Summary
This document talks about creating an iPhone Application using Sybase Unwired Platform. Here we take Customer and Sales Order tables as example MBO’s. Below procedure gives an insight to create the MBO’s and Mobile Client Customization and deployment of MBO’s on the server, which in turn interact with Mobile Client (iPhone) Author(s): Pradeep Gudipati Company: Advent Global Solutions Inc. Created on: 16 May 2011

Author Bio
Pradeep Gudipati Lead Engineer Advent Global Solutions Inc.

SAP COMMUNITY NETWORK © 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 1

Sybase Unwired Platform: How to develop an iPhone Application using SUP.

Table of Contents
Applies to:.........................................................................................................................................................1 Summary...........................................................................................................................................................1 Author Bio.........................................................................................................................................................1 Table of Contents..............................................................................................................................................2 Creating an MBO..............................................................................................................................................3 Pre-requisites ...............................................................................................................................................3 Procedure .....................................................................................................................................................3 Generate the SUP Code for iOS development ...............................................................................................12 Pre-requisites .............................................................................................................................................12 Procedure ...................................................................................................................................................12 Custom development for iphone.....................................................................................................................15 Procedure....................................................................................................................................................15 Creating Custom Code................................................................................................................................16 Building & Running the application..............................................................................................................40 Related Content..............................................................................................................................................47 Copyright.........................................................................................................................................................48

SAP COMMUNITY NETWORK © 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 2

Sybase Unwired Platform: How to develop an iPhone Application using SUP.

Creating an MBO
Pre-requisites Sybase Unwired Platform installed on a Windows System.

Procedure 1. Create a new Mobile Application

SAP COMMUNITY NETWORK © 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 3

Sybase Unwired Platform: How to develop an iPhone Application using SUP.

2. Open Diagram Editor by Right clicking on project and selecting Open in Diagram Editor

SAP COMMUNITY NETWORK © 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 4

Sybase Unwired Platform: How to develop an iPhone Application using SUP.

3. Create MBOs by dragging & dropping Customer & Sales Order Tables onto the Device Diagram editor

SAP COMMUNITY NETWORK © 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 5

Sybase Unwired Platform: How to develop an iPhone Application using SUP.

4. Create relationship

SAP COMMUNITY NETWORK © 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 6

Sybase Unwired Platform: How to develop an iPhone Application using SUP.

5. Deploy the MBO(Remember to select the “Message-based” option)

SAP COMMUNITY NETWORK © 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 7

Sybase Unwired Platform: How to develop an iPhone Application using SUP.

Click Next

SAP COMMUNITY NETWORK © 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 8

Sybase Unwired Platform: How to develop an iPhone Application using SUP.

Click Next

SAP COMMUNITY NETWORK © 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 9

Sybase Unwired Platform: How to develop an iPhone Application using SUP.

Select the Connection Profile to the DB if already existing else create new one by selecting the template from the drop down. Click Finish and the MBO’s are deployed to the SUP server.

SAP COMMUNITY NETWORK © 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 10

Sybase Unwired Platform: How to develop an iPhone Application using SUP.

SAP COMMUNITY NETWORK © 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 11

Sybase Unwired Platform: How to develop an iPhone Application using SUP.

Generate the SUP Code for iOS development
Pre-requisites Apple Macintosh Machine with XCode .

Procedure

1. Right Click on the Project and select Generate the code option then click next

SAP COMMUNITY NETWORK © 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 12

Sybase Unwired Platform: How to develop an iPhone Application using SUP.

2. Select the following options
1. Language : Objective C, 2. Unwired server : My Unwired 3. Server Domain : default 4. Project path : the default option / optionally you can change it Click next.

SAP COMMUNITY NETWORK © 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 13

Sybase Unwired Platform: How to develop an iPhone Application using SUP.

Select all the MBOs and tick the “Generate metadata classes” option and click finish

Now the Objective-C code is generated into the specified output location.

SAP COMMUNITY NETWORK © 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 14

Sybase Unwired Platform: How to develop an iPhone Application using SUP.

Custom development for iphone
Procedure 1) Create a new project in Xcode with template as windows-based project 2) Setup the environment.Follow the following steps:• Copy the Generated code & Objective C folder to your Mac machine and import in your project. • Import libraries “libMO.a”, “libSUPObj.a”, “libclientrt.a” in Objective folder .The library version should correspond to the configuration you are building. For example, if you are building a configuration for a debug version of the simulator, then add the libraries to libs/Debugiphonesimulator/ . • Import Settings Bundle in your project. “QuartzCore.framework” and

• Add “AddressBook.framework”,”Security.framework”, “CoreFoundation.framework”.

Under Targets select SupDemo, click on info and General tab and add “libicucore.A.dylib”, “libz.1.2.3.dyli” and “libstdc++.6.dyli”

SAP COMMUNITY NETWORK © 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 15

Sybase Unwired Platform: How to develop an iPhone Application using SUP.



Set up Library search Path & header search path.

Creating Custom Code

1. Open MainWindow.xib and add NavigationController in it .In the appdelegate create an outlet for navigation controller & connect it to the navigation controller added under MainWindow.xib

Add the following code in SupDemoAppDelegate

SupDemoAppDelegate.h
#import <UIKit/UIKit.h>

@interface SupDemoAppDelegate : NSObject <UIApplicationDelegate> { UIWindow *window; UINavigationController *navController; }

@property (nonatomic, retain) IBOutlet UIWindow *window; @property (nonatomic, retain) IBOutlet UINavigationController *navController;

-(void)showNoTransportAlert:(NSInteger)ret;

@end

SupDemoAppDelegate.m
#import "SupDemoAppDelegate.h" #import "SUPMessageClient.h" #import "SupDemoCallbackHandler.h" #import "SupDemo_SupDemoDB.h"

SAP COMMUNITY NETWORK © 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 16

Sybase Unwired Platform: How to develop an iPhone Application using SUP.

@implementation SupDemoAppDelegate

@synthesize window; @synthesize navController;

-(void)showNoTransportAlert:(NSInteger)ret { NSString *message = nil; if(ret == kSUPMessageClientNoSettings) { message=@"No required settings,use the Settings app to enter the provisioning information."; } else if(ret == kSUPMessageClientKeyNotAvailable) { message=@"Unable to access the key"; } else { message = @"Operation fails."; } UIAlertView *noTransportAlert = [[[UIAlertView alloc]initWithTitle:@"Message Client Fails to Start" message:message delegate:self cancelButtonTitle:NSLocalizedString(@"OK",@"Label for alert button OK") otherButtonTitles:nil]autorelease]; [noTransportAlert show]; }

- (void)applicationDidFinishLaunching:(UIApplication *)application {

// Override point for customization after application launch NSInteger result = [SUPMessageClient start]; //int connectionStatus = [SUPMessageClient status]; if(result == kSUPMessageClientSuccess) { [window addSubview:navController.view]; [window makeKeyAndVisible]; } else { [self showNoTransportAlert:result]; }

}

SAP COMMUNITY NETWORK © 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 17

Sybase Unwired Platform: How to develop an iPhone Application using SUP.

-(void)applicationWillTerminate:(UIApplication *)application { [SupDemo_SupDemoDB unsubscribe]; [SUPMessageClient stop]; }

-(void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {

} -(void)dealloc { [navController release]; [window release]; [super dealloc]; } @end

2. Create call back handler named SupDemoCallbackHandler that handles the asynch login request sent to the server. SupDemoCallbackHandler.h
#import "SUPDefaultCallbackHandler.h" @interface SupDemoCallbackHandler : SUPDefaultCallbackHandler {

SUPInt field_importCount; SUPInt field_replaySuccessCount; SUPInt field_replayFailureCount; SUPInt field_searchSuccessCount; SUPInt field_searchFailureCount; SUPInt field_loginSuccessCount; SUPInt field_importSuccessCount; } + (SupDemoCallbackHandler*)newInstance; - (SUPInt)importCount; - (void)setImportCount:(SUPInt)_importCount; @property(assign) SUPInt importCount; - (SUPInt)replaySuccessCount;

SAP COMMUNITY NETWORK © 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 18

Sybase Unwired Platform: How to develop an iPhone Application using SUP.

- (void)setReplaySuccessCount:(SUPInt)_replaySuccessCount; @property(assign) SUPInt replaySuccessCount; - (SUPInt)replayFailureCount; - (void)setReplayFailureCount:(SUPInt)_replayFailureCount; @property(assign) SUPInt replayFailureCount; - (SUPInt)searchSuccessCount; - (void)setSearchSuccessCount:(SUPInt)_searchSuccessCount; @property(assign) SUPInt searchSuccessCount; - (SUPInt)searchFailureCount; - (void)setSearchFailureCount:(SUPInt)_searchFailureCount; @property(assign) SUPInt searchFailureCount; - (SUPInt)loginSuccessCount; - (void)setLoginSuccessCount:(SUPInt)_loginSuccessCount; @property(assign) SUPInt loginSuccessCount; - (SUPInt)importSuccessCount; - (void)setImportSuccessCount:(SUPInt)_importSuccessCount; @property(assign) SUPInt importSuccessCount; - (void)onImport:(id)theObject; - (void)onReplayFailure:(id)theObject; - (void)onReplaySuccess:(id)theObject; - (void)onSearchFailure:(id)theObject; - (void)onSearchSuccess:(id)theObject; - (void)onLoginSuccess; - (void)onSubscribeSuccess; - (void)onUnsubscribeSuccess; - (void)onImportSuccess; - (void)dealloc; @end

SupDemoCallbackHandler.m #import "SupDemoCallbackHandler.h"

@implementation SupDemoCallbackHandler

+ (SupDemoCallbackHandler*)newInstance { SupDemoCallbackHandler* _me_1 = [[SupDemoCallbackHandler alloc] init]; [_me_1 autorelease]; return _me_1; } - (SUPInt)importCount { return field_importCount;

SAP COMMUNITY NETWORK © 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 19

Sybase Unwired Platform: How to develop an iPhone Application using SUP.

} - (void)setImportCount:(SUPInt)_importCount { field_importCount = _importCount; } - (SUPInt)replaySuccessCount { return field_replaySuccessCount; } - (void)setReplaySuccessCount:(SUPInt)_replaySuccessCount { field_replaySuccessCount = _replaySuccessCount; } - (SUPInt)replayFailureCount { return field_replayFailureCount; } - (void)setReplayFailureCount:(SUPInt)_replayFailureCount { field_replayFailureCount = _replayFailureCount; } - (SUPInt)searchSuccessCount { return field_searchSuccessCount; } - (void)setSearchSuccessCount:(SUPInt)_searchSuccessCount { field_searchSuccessCount = _searchSuccessCount; } - (SUPInt)searchFailureCount { return field_searchFailureCount; } - (void)setSearchFailureCount:(SUPInt)_searchFailureCount { field_searchFailureCount = _searchFailureCount; } - (SUPInt)loginSuccessCount { return field_loginSuccessCount; } - (void)setLoginSuccessCount:(SUPInt)_loginSuccessCount { field_loginSuccessCount = _loginSuccessCount; } - (SUPInt)importSuccessCount { return field_importSuccessCount; } - (void)setImportSuccessCount:(SUPInt)_importSuccessCount { field_importSuccessCount = _importSuccessCount; } - (void)onImport:(id)theObject { self.importCount = self.importCount + 1; }

SAP COMMUNITY NETWORK © 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 20

Sybase Unwired Platform: How to develop an iPhone Application using SUP.

- (void)onReplayFailure:(id)theObject { self.replayFailureCount = self.replayFailureCount + 1; } - (void)onReplaySuccess:(id)theObject { self.replaySuccessCount = self.replaySuccessCount + 1; MBOLogInfo(@"================================================"); MBOLogInfo(@"================================================="); } - (void)onSearchFailure:(id)theObject { self.searchFailureCount = self.searchFailureCount + 1; } - (void)onSearchSuccess:(id)theObject { self.searchSuccessCount = self.searchSuccessCount + 1; } - (void)onLoginSuccess { MBOLogInfo(@"================================================"); MBOLogInfo(@"Login Successful"); MBOLogInfo(@"================================================="); self.loginSuccessCount++; }

- (void)onSubscribeSuccess { MBOLogInfo(@"================================================"); MBOLogInfo(@"Subscribe Successful"); MBOLogInfo(@"================================================="); }

- (void)onUnsubscribeSuccess { MBOLogInfo(@"================================================"); MBOLogInfo(@"Unsubscribe Successful"); MBOLogInfo(@"================================================="); }

- (void)onImportSuccess{ MBOLogInfo(@"================================================"); MBOLogInfo(@"import ends Successful"); MBOLogInfo(@"================================================="); self.importSuccessCount++; } - (void)dealloc { [super dealloc]; }

SAP COMMUNITY NETWORK © 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 21

Sybase Unwired Platform: How to develop an iPhone Application using SUP.

@end

3. Create Subscribe.xib with UITableView Outlet.Create SubscribeController as the view controller file for Subscribe.xib.

SubscribeController.h
#import <UIKit/UIKit.h> #import "CustomerListController.h"

@interface SubscribeController : UIViewController<UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate> { IBOutlet UITableView *tblView; UITextField *txtfield_username; UITextField *txtfield_password; CustomerListController *listController;

} @end

SubscribeController.m #import "SubscribeController.h" #import "SupDemo_SupDemoDB.h" #import "SupDemoCallbackHandler.h" #import "SupDemoAppDelegate.h" #import "SUPMessageClient.h"

@implementation SubscribeController @synthesize subscribeButton;

-(void)subscribe { [SupDemo_SupDemoDB subscribe]; while ([(SupDemoCallbackHandler *)[SupDemo_SupDemoDB callbackHandler] importCount]<1) {

SAP COMMUNITY NETWORK © 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 22

Sybase Unwired Platform: How to develop an iPhone Application using SUP.

sleep(1); } sleep(3); if(listController == nil) { listController = [[CustomerListController alloc] initWithStyle:UITableViewStyleGrouped];

} SupDemoAppDelegate *delegate =[[UIApplication sharedApplication]delegate]; [delegate.navController pushViewController:listController animated:YES];

}

// The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) { // Custom initialization } return self; }

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib. - (void)viewDidLoad { self.title=@"Subscribe"; [super viewDidLoad]; }

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; }

// Customize the number of rows in the table view. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 2; }

// Customize the appearance of table view cells. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";

SAP COMMUNITY NETWORK © 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 23

Sybase Unwired Platform: How to develop an iPhone Application using SUP.

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; }

UILabel *lblUserName,*lblPassword; switch (indexPath.row) { case 0: lblUserName=[[UILabel alloc]initWithFrame:CGRectMake(20,10, 70,30)]; lblUserName.text=@"UserName"; lblUserName.font=[UIFont boldSystemFontOfSize:14]; [cell addSubview:lblUserName]; [lblUserName release];

txtfield_username=[[UITextField alloc]initWithFrame:CGRectMake(100, 10, 200,30)]; txtfield_username.returnKeyType= UIReturnKeyNext; txtfield_username.tag=1; txtfield_username.font=[UIFont boldSystemFontOfSize:14]; txtfield_username.delegate=self; [txtfield_username becomeFirstResponder]; [cell addSubview:txtfield_username]; break;

default: lblPassword=[[UILabel alloc]initWithFrame:CGRectMake(20, 10, 70, 30)]; lblPassword.text=@"Password"; lblPassword.font=[UIFont boldSystemFontOfSize:14]; [cell addSubview:lblPassword]; [lblPassword release];

txtfield_password=[[UITextField alloc]initWithFrame:CGRectMake(100, 10, 200, 30)]; txtfield_password.returnKeyType= UIReturnKeyGo; txtfield_password.font=[UIFont boldSystemFontOfSize:14]; txtfield_password.delegate=self; txtfield_password.secureTextEntry=YES; txtfield_password.tag=2; [cell addSubview:txtfield_password];

break; }

SAP COMMUNITY NETWORK © 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 24

Sybase Unwired Platform: How to develop an iPhone Application using SUP.

return cell; }

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { }

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 50; } #pragma UITextField Delegate Methods

- (BOOL)textFieldShouldReturn:(UITextField *)textField { [textField resignFirstResponder]; if(textField == txtfield_password) { [UIApplication sharedApplication].networkActivityIndicatorVisible=YES; [SupDemo_SupDemoDB deleteDatabase]; // Set log Level [MBOLogger setLogLevel:LOG_INFO]; //Set up connection profile(server, user, password,cid) SupDemoCallbackHandler *databaseCH = [SupDemoCallbackHandler newInstance]; [SupDemo_SupDemoDB registerCallbackHandler:databaseCH]; [SupDemo_SupDemoDB createDatabase]; [SupDemo_SupDemoDB startBackgroundSynchronization]; NSInteger result = [SUPMessageClient start]; [SupDemo_SupDemoDB asyncOnlineLogin:txtfield_username.text password:txtfield_password.text];

while([databaseCH loginSuccessCount]<1) { sleep(1); } sleep(3); [self subscribe]; [UIApplication sharedApplication].networkActivityIndicatorVisible=NO; } else [txtfield_password becomeFirstResponder];

SAP COMMUNITY NETWORK © 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 25

Sybase Unwired Platform: How to develop an iPhone Application using SUP.

return YES; }

- (void)didReceiveMemoryWarning { // Releases the view if it doesn't have a superview. [super didReceiveMemoryWarning];

// Release any cached data, images, etc that aren't in use. }

- (void)viewDidUnload { // Release any retained subviews of the main view. // e.g. self.myOutlet = nil; }

- (void)dealloc {

if(listController) { [listController release]; listController = nil; } [super dealloc]; }

@end

4. Create CustomerListController

CustomerListController.h
#import "DetailController.h" #import <UIKit/UIKit.h>

@interface CustomerListController : UITableViewController<UITableViewDelegate,UITableViewDataSource> {

SAP COMMUNITY NETWORK © 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 26

Sybase Unwired Platform: How to develop an iPhone Application using SUP.

NSArray *customerList; DetailController *childController; }

@property (nonatomic, retain) NSArray *customerList;

@end

CustomerListController.m
#import "CustomerListController.h" #import "SupDemoAppDelegate.h" #import "DetailController.h" #import "SupDemo_Customer.h"

@implementation CustomerListController

@synthesize customerList; - (id)initWithStyle:(UITableViewStyle)style { // Override initWithStyle: if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad. if (self = [super initWithStyle:style]) { } return self; }

/* - (void)viewDidLoad { [super viewDidLoad];

// Uncomment the following line to display an Edit button in the navigation bar for this view controller. // self.navigationItem.rightBarButtonItem = self.editButtonItem; } */

- (void)viewWillAppear:(BOOL)animated {

self.title = @"Customers";

SAP COMMUNITY NETWORK © 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 27

Sybase Unwired Platform: How to develop an iPhone Application using SUP.

NSMutableArray *array = [[NSMutableArray alloc]init];

SupDemo_CustomerList *customers = [SupDemo_Customer findAll]; if([customers length] > 0) { for (SupDemo_Customer *oneRec in customers) { [array addObject:oneRec]; } } self.customerList = array; //[array release]; [[self tableView] reloadData]; [super viewWillAppear:animated]; }

- (void)didReceiveMemoryWarning { // Releases the view if it doesn't have a superview. [super didReceiveMemoryWarning];

// Release any cached data, images, etc that aren't in use. }

- (void)viewDidUnload { // Release any retained subviews of the main view. // e.g. self.myOutlet = nil; }

#pragma mark Table view methods

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; }

// Customize the number of rows in the table view. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [self.customerList count]; }

SAP COMMUNITY NETWORK © 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 28

Sybase Unwired Platform: How to develop an iPhone Application using SUP.

// Customize the appearance of table view cells. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; }

NSUInteger row = [indexPath row]; SupDemo_Customer *customer = [self.customerList objectAtIndex:row];

// Set up the cell... cell.textLabel.text = [NSString stringWithFormat:@"%@ %@",[customer fname],[customer lname]]; cell.textLabel.font=[UIFont boldSystemFontOfSize:16];

/*cell.detailTextLabel.text = [NSString stringWithFormat:@"%@",[customer phone]]; cell.detailTextLabel.font=[UIFont systemFontOfSize:12];*/

cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

return cell; }

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [self tableView:tableView accessoryButtonTappedForRowWithIndexPath:indexPath]; }

-(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath { if ( childController == nil) childController = [[DetailController alloc] initWithNibName:@"DetailController" bundle:nil]; else { [childController release]; childController=nil;

SAP COMMUNITY NETWORK © 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 29

Sybase Unwired Platform: How to develop an iPhone Application using SUP.

childController = [[DetailController alloc] initWithNibName:@"DetailController" bundle:nil]; }

NSUInteger row = [indexPath row];

SupDemo_Customer *selectedCustomer = [customerList objectAtIndex:row]; childController.title = [NSString stringWithFormat:@"%d",[selectedCustomer id]]; childController.originalObj = selectedCustomer;

SupDemoAppDelegate *delegate = [[UIApplication sharedApplication]delegate]; [delegate.navController pushViewController:childController animated:YES];

}

- (void)dealloc {

[customerList release]; [childController release]; [super dealloc]; }

@end

5. Create DetailController and DetailController.xib

DetailController.h
#import <UIKit/UIKit.h> #import "SupDemo_Customer.h"

@interface DetailController : UIViewController<UITableViewDelegate,UITableViewDataSource> {

IBOutlet UITableView *tblView; IBOutlet UITextField *fname; IBOutlet UITextField *lname;

SAP COMMUNITY NETWORK © 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 30

Sybase Unwired Platform: How to develop an iPhone Application using SUP.

IBOutlet UITextField *phone; SupDemo_Customer *originalObj;

} @property (nonatomic, retain) IBOutlet UITextField *fname; @property (nonatomic, retain) IBOutlet UITextField *lname; @property (nonatomic, retain) IBOutlet UITextField *phone; @property (nonatomic, retain) SupDemo_Customer *originalObj;

-(SupDemo_Customer *)originalObj; -(void)setOriginalObj: (SupDemo_Customer *)newObj; -(IBAction)buttonPressed:(id)sender; @end

DetailController.m
#import "DetailController.h" #import "SupDemoAppDelegate.h" #import "SupDemo_SupDemoDB.h" #import "EditCustomerDetails.h"

@implementation DetailController

@synthesize fname; @synthesize lname; @synthesize phone;

-(SupDemo_Customer *)originalObj { return originalObj; }

-(void)setOriginalObj: (SupDemo_Customer *)newObj { if (originalObj != newObj) {

SAP COMMUNITY NETWORK © 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 31

Sybase Unwired Platform: How to develop an iPhone Application using SUP.

[originalObj release]; originalObj = [newObj retain]; } } - (id)initWithNibName:(NSString *)nibNameOrNil bundle: (NSBundle *)nibBundleOrNil { if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) { // Custom initialization return self; } UIBarButtonItem *barButtonitemEdit =[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(editDetails)]; self.navigationItem.rightBarButtonItem=barButtonitemEdit; return self; } -(void)viewWillAppear { [tblView reloadData]; } #pragma mark Table view methods

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; }

// Customize the number of rows in the table view. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 7; }

// Customize the appearance of table view cells. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease]; }

switch(indexPath.row)

SAP COMMUNITY NETWORK © 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 32

Sybase Unwired Platform: How to develop an iPhone Application using SUP.

{ case 0: cell.textLabel.text=@"Address"; cell.detailTextLabel.text=[originalObj address]; break; case 1: cell.textLabel.text=@"City"; cell.detailTextLabel.text=[originalObj city]; break; case 2: cell.textLabel.text=@"State"; cell.detailTextLabel.text=[originalObj state]; break; case 3: cell.textLabel.text=@"Zip"; cell.detailTextLabel.text=[originalObj zip]; break; case 4: cell.textLabel.text=@"Phone"; cell.detailTextLabel.text=[originalObj phone]; break; case 5: cell.textLabel.text=@"Company"; cell.detailTextLabel.text=[originalObj company_name]; break; case 6: cell.textLabel.text=@"Sales Order"; cell.accessoryType=UITableViewCellAccessoryDetailDisclosureButton; break;

} return cell; }

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [self tableView:tableView accessoryButtonTappedForRowWithIndexPath:indexPath]; }

-(void)editDetails {

SAP COMMUNITY NETWORK © 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 33

Sybase Unwired Platform: How to develop an iPhone Application using SUP.

EditCustomerDetails *editCustomerDetailsCntller=[[EditCustomerDetails alloc]initWithNibName:@"EditCustomerDetails" bundle:[NSBundle mainBundle] forCustomer:originalObj]; [self.navigationController pushViewController:editCustomerDetailsCntller animated:NO];

}

@end

6. Create EditCustomerDetails

EditCustomerDetails.h
#import <UIKit/UIKit.h> #import "SupDemo_Customer.h"

@interface EditCustomerDetails : UITableViewController<UITextFieldDelegate> {

UITextField *txtfieldFname; UITextField *txtfieldLname; UITextField *txtfieldAddress; UITextField *txtfieldStreet; UITextField *txtfieldPin; UITextField *txtfieldPhone; UITextField *txtfieldCompany; SupDemo_Customer *customer;

}

@end

EditCustomerDetails.m
#import "EditCustomerDetails.h" #import "SupDemo_Customer.h"

@implementation EditCustomerDetails - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil forCustomer:(SupDemo_Customer *)customerobj{ if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) { // Custom initialization }

SAP COMMUNITY NETWORK © 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 34

Sybase Unwired Platform: How to develop an iPhone Application using SUP.

UIBarButtonItem *barButtonitemEdit =[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(updateDetails)]; self.navigationItem.rightBarButtonItem=barButtonitemEdit; customer=customerobj; return self; }

- (void)didReceiveMemoryWarning { // Releases the view if it doesn't have a superview. [super didReceiveMemoryWarning];

// Release any cached data, images, etc that aren't in use. }

- (void)viewDidUnload { // Release any retained subviews of the main view. // e.g. self.myOutlet = nil; }

-(void)viewWillAppear {

}

#pragma mark Table view methods

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; }

// Customize the number of rows in the table view. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 7; }

// Customize the appearance of table view cells. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell"; UILabel *lblFname,*lblLname,*lblAddress,*lblState,*lblCity,*lblZip,*lblPhone,*lblCompany;

SAP COMMUNITY NETWORK © 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 35

Sybase Unwired Platform: How to develop an iPhone Application using SUP.

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; }

switch (indexPath.row) { case 0: lblFname=[[UILabel alloc]initWithFrame:CGRectMake(20,10, 80,30)]; lblFname.text=@"First Name"; lblFname.font=[UIFont boldSystemFontOfSize:14]; [cell addSubview:lblFname]; [lblFname release];

txtfieldFname=[[UITextField alloc]initWithFrame:CGRectMake(100, 10, 200,30)]; txtfieldFname.text=[customer fname]; txtfieldFname.returnKeyType= UIReturnKeyNext; txtfieldFname.tag=1; txtfieldFname.font=[UIFont systemFontOfSize:14]; txtfieldFname.delegate=self; [txtfieldFname becomeFirstResponder]; [cell addSubview:txtfieldFname];

break;

case 1: lblLname=[[UILabel alloc]initWithFrame:CGRectMake(20,10,80,30)]; lblLname.text=@"Last Name"; lblLname.font=[UIFont boldSystemFontOfSize:14]; [cell addSubview:lblLname]; [lblLname release];

txtfieldLname=[[UITextField alloc]initWithFrame:CGRectMake(100, 10, 200,30)]; txtfieldLname.text=[customer lname]; txtfieldLname.returnKeyType= UIReturnKeyNext; txtfieldLname.tag=1; txtfieldLname.font=[UIFont systemFontOfSize:14]; txtfieldLname.delegate=self; [txtfieldLname becomeFirstResponder];

SAP COMMUNITY NETWORK © 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 36

Sybase Unwired Platform: How to develop an iPhone Application using SUP.

[cell addSubview:txtfieldLname]; break; case 2: lblAddress=[[UILabel alloc]initWithFrame:CGRectMake(20,10, 70,30)]; lblAddress.text=@"Address"; lblAddress.font=[UIFont boldSystemFontOfSize:14]; [cell addSubview:lblAddress]; [lblAddress release];

txtfieldAddress=[[UITextField alloc]initWithFrame:CGRectMake(100, 10, 200,30)]; txtfieldAddress.text=[customer address]; txtfieldAddress.returnKeyType= UIReturnKeyNext; txtfieldAddress.tag=1; txtfieldAddress.font=[UIFont systemFontOfSize:14]; txtfieldAddress.delegate=self; [txtfieldAddress becomeFirstResponder]; [cell addSubview:txtfieldAddress]; break;

case 3: lblState=[[UILabel alloc]initWithFrame:CGRectMake(20,10, 70,30)]; lblState.text=@"State"; lblState.font=[UIFont boldSystemFontOfSize:14]; [cell addSubview:lblState]; [lblState release];

txtfieldStreet=[[UITextField alloc]initWithFrame:CGRectMake(100, 10, 200,30)]; txtfieldStreet.text=[customer state]; txtfieldStreet.returnKeyType= UIReturnKeyNext; txtfieldStreet.tag=1; txtfieldStreet.font=[UIFont systemFontOfSize:14]; txtfieldStreet.delegate=self; [txtfieldStreet becomeFirstResponder]; [cell addSubview:txtfieldStreet]; break;

case 4: lblZip=[[UILabel alloc]initWithFrame:CGRectMake(20,10, 70,30)]; lblZip.text=@"Pin"; lblZip.font=[UIFont boldSystemFontOfSize:14]; [cell addSubview:lblZip];

SAP COMMUNITY NETWORK © 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 37

Sybase Unwired Platform: How to develop an iPhone Application using SUP.

[lblZip release];

txtfieldPin=[[UITextField alloc]initWithFrame:CGRectMake(100, 10, 200,30)]; txtfieldPin.text=[customer zip]; txtfieldPin.returnKeyType= UIReturnKeyNext; txtfieldPin.tag=1; txtfieldPin.font=[UIFont systemFontOfSize:14]; txtfieldPin.delegate=self; [txtfieldPin becomeFirstResponder]; [cell addSubview:txtfieldPin]; break;

case 5: lblCompany=[[UILabel alloc]initWithFrame:CGRectMake(20,10, 70,30)]; lblCompany.text=@"Company"; lblCompany.font=[UIFont boldSystemFontOfSize:14]; [cell addSubview:lblCompany]; [lblCompany release];

txtfieldCompany=[[UITextField alloc]initWithFrame:CGRectMake(100, 10, 200,30)]; txtfieldCompany.text=[customer company_name]; txtfieldCompany.returnKeyType= UIReturnKeyNext; txtfieldCompany.tag=1; txtfieldCompany.font=[UIFont systemFontOfSize:14]; txtfieldCompany.delegate=self; [txtfieldCompany becomeFirstResponder]; [cell addSubview:txtfieldCompany]; break;

case 6: lblPhone=[[UILabel alloc]initWithFrame:CGRectMake(20,10, 70,30)]; lblPhone.text=@"Phone"; lblPhone.font=[UIFont boldSystemFontOfSize:14]; [cell addSubview:lblPhone]; [lblPhone release];

txtfieldPhone=[[UITextField alloc]initWithFrame:CGRectMake(100, 10, 200,30)]; txtfieldPhone.text=[customer phone]; txtfieldPhone.returnKeyType= UIReturnKeyNext; txtfieldPhone.tag=1; txtfieldPhone.font=[UIFont systemFontOfSize:14];

SAP COMMUNITY NETWORK © 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 38

Sybase Unwired Platform: How to develop an iPhone Application using SUP.

txtfieldPhone.delegate=self; [txtfieldPhone becomeFirstResponder]; [cell addSubview:txtfieldPhone]; break;

}

return cell; }

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

} -(void)updateDetails { SupDemo_Customer *newCustomer = [SupDemo_Customer find: [customer id]]; if (newCustomer) { [newCustomer setFname:txtfieldFname.text]; [newCustomer setLname:txtfieldLname.text]; [newCustomer setAddress:txtfieldAddress.text]; [newCustomer setState:txtfieldStreet.text]; [newCustomer setZip:txtfieldPin.text]; [newCustomer setPhone:txtfieldPhone.text]; [newCustomer setCompany_name:txtfieldCompany.text]; [newCustomer save]; [newCustomer submitPending]; while ([SupDemo_SupDemoDB hasPendingOperations]) { sleep(1); } //SupDemoAppDelegate *delegate = [[UIApplication sharedApplication] delegate]; [self.navigationController popViewControllerAnimated:YES]; } }

- (void)dealloc { [super dealloc]; }

SAP COMMUNITY NETWORK © 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 39

Sybase Unwired Platform: How to develop an iPhone Application using SUP.

@end

Building & Running the application



Register Your device to SCC (Sybase Control Center) o Launch Sybase control center & login with username supAdmin and password s3pAdmin o Click on Device Users and select Devices tab. On the devices tab ,click on Register.

Make following entries:-

User name Server Name Port Farm Id Activation Code Activation expiration (hours)

iphoneuser Name of the server / IP Address 5001 Farm1 123 72

SAP COMMUNITY NETWORK © 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 40

Sybase Unwired Platform: How to develop an iPhone Application using SUP.

SAP COMMUNITY NETWORK © 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 41

Sybase Unwired Platform: How to develop an iPhone Application using SUP.

On The device go to Settings > Sybase Settings and enter the same details as shown below

SAP COMMUNITY NETWORK © 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 42

Sybase Unwired Platform: How to develop an iPhone Application using SUP.

7. Launch the application and enter the same credentials as used for SCC or use username : supuser, password : s3pUser

SAP COMMUNITY NETWORK © 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 43

Sybase Unwired Platform: How to develop an iPhone Application using SUP.

SAP COMMUNITY NETWORK © 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 44

Sybase Unwired Platform: How to develop an iPhone Application using SUP.

SAP COMMUNITY NETWORK © 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 45

Sybase Unwired Platform: How to develop an iPhone Application using SUP.

SAP COMMUNITY NETWORK © 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 46

Sybase Unwired Platform: How to develop an iPhone Application using SUP.

Related Content
SUP 1.5.5 : MBO development SUP 1.5.5 : iOS development documentation SUP 2.0.0 : Documentation SUP 2.0.0 : SCC

SAP COMMUNITY NETWORK © 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 47

Sybase Unwired Platform: How to develop an iPhone Application using SUP.

Copyright
© Copyright 2011 Advent Global Solutions Inc., All rights reserved. © Copyright 2011 SAP AG., All rights reserved. No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP AG. The information contained herein may be changed without prior notice. Some software products marketed by SAP AG and its distributors contain proprietary software components of other software vendors. Microsoft, Windows, Excel, Outlook, and PowerPoint are registered trademarks of Microsoft Corporation. IBM, DB2, DB2 Universal Database, System i, System i5, System p, System p5, System x, System z, System z10, System z9, z10, z9, iSeries, pSeries, xSeries, zSeries, eServer, z/VM, z/OS, i5/OS, S/390, OS/390, OS/400, AS/400, S/390 Parallel Enterprise Server, PowerVM, Power Architecture, POWER6+, POWER6, POWER5+, POWER5, POWER, OpenPower, PowerPC, BatchPipes, BladeCenter, System Storage, GPFS, HACMP, RETAIN, DB2 Connect, RACF, Redbooks, OS/2, Parallel Sysplex, MVS/ESA, AIX, Intelligent Miner, WebSphere, Netfinity, Tivoli and Informix are trademarks or registered trademarks of IBM Corporation. Linux is the registered trademark of Linus Torvalds in the U.S. and other countries. Adobe, the Adobe logo, Acrobat, PostScript, and Reader are either trademarks or registered trademarks of Adobe Systems Incorporated in the United States and/or other countries. Oracle is a registered trademark of Oracle Corporation. UNIX, X/Open, OSF/1, and Motif are registered trademarks of the Open Group. Citrix, ICA, Program Neighborhood, MetaFrame, WinFrame, VideoFrame, and MultiWin are trademarks or registered trademarks of Citrix Systems, Inc. HTML, XML, XHTML and W3C are trademarks or registered trademarks of W3C®, World Wide Web Consortium, Massachusetts Institute of Technology. Java is a registered trademark of Sun Microsystems, Inc. JavaScript is a registered trademark of Sun Microsystems, Inc., used under license for technology invented and implemented by Netscape. SAP, R/3, SAP NetWeaver, Duet, PartnerEdge, ByDesign, SAP Business ByDesign, and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP AG in Germany and other countries. Business Objects and the Business Objects logo, BusinessObjects, Crystal Reports, Crystal Decisions, Web Intelligence, Xcelsius, and other Business Objects products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of Business Objects S.A. in the United States and in other countries. Business Objects is an SAP company. All other product and service names mentioned are the trademarks of their respective companies. Data contained in this document serves informational purposes only. National product specifications may vary. These materials are subject to change without notice. These materials are provided by SAP AG and its affiliated companies ("SAP Group") for informational purposes only, without representation or warranty of any kind, and SAP Group shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP Group products and services are those that are set forth in the express warranty statements accompanying such products and services, if any. Nothing herein should be construed as constituting an additional warranty.

SAP COMMUNITY NETWORK © 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 48

Sponsor Documents

Or use your account on DocShare.tips

Hide

Forgot your password?

Or register your new account on DocShare.tips

Hide

Lost your password? Please enter your email address. You will receive a link to create a new password.

Back to log-in

Close