# iOS Native

## Learn how to

1. Add iOS Viewer library to your project
2. Connect to the server, open iOS viewer, and load an e-Form in your storyboard.
3. Trigger the e-Form submit button from an action button

## Preparations

### Required skills/experiences

* iOS native App development experience with Xcode

### XCode

* Here we use Xcode ver. 12.1

### OZ products

* e-Form Server installed on the WAS server
* iOS Viewer library

  Download **ozrv80\_ios\_version.number.tar.gz** from 👉 [Product Downloads](https://edu.ozeform.io/product-downloads)

## Sample project

Create a new iOS App project ("app") with Objective-C and Storyboard.

### Add iOS viewer library to the project

1. Create a folder (ex: **ozviewer**) under your project folder.
2. Add the license file to **ozviewer** (Your instructor will provide the license file).
3. Copy **custom\_ui** and **Framework** folder into **ozviewer** from extracted files.
4. Remove the **Device** folder from **Framework** (We will run the app on the simulator).

   If you want to run the app on your device, remove the **Framework** folder.
5. Remove the **optional** folder from **Simulator** ( We don't need optional features for now).
6. Right-click your project folder > **Add Files to "app"** > select the **ozviewer** folder > **Add**
7. Right-click the target, go to the **Build Phases** tab, and add more libraries and frameworks:

   libc++.tbd\
   libxml2.tbd\
   libiconv.tbd\
   UIKit.framework\
   Foundation.framework\
   CoreText.framework\
   CoreGraphics.framework
8. And in the **Copy Files**, add the **OZRViewer.framework**.

![](https://2677009089-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MjDM4l4HfP5CuJGFF23-887967055%2Fuploads%2Fy6TuAN2U11QEAtq1VHF8%2Fios_library.png?alt=media\&token=7c8355c7-87cf-4dae-843c-b96def6138a0)

### Storyboard

#### Add a view for OZ viewer

![](https://2677009089-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MjDM4l4HfP5CuJGFF23-887967055%2Fuploads%2FglXDZ007hcpOk9TvPS3S%2Fios_storyboard_view.png?alt=media\&token=9afad357-f588-45cc-a550-1b555a7acfdf)

#### Add a button for Submit

![](https://2677009089-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MjDM4l4HfP5CuJGFF23-887967055%2Fuploads%2FEGeAq6KGFkp41VLHw8XH%2Fios_storyboard_button.png?alt=media\&token=fd0f1b74-7767-4bd8-a4a0-d444f19773b2)

#### ViewController.h

```objectivec
//  ViewController.h
//  app
//
//  Created by John Kim on 2021/10/27.
//
 
#import <UIKit/UIKit.h>
#import <OZRViewer/OZReportViewer.h>
@interface ViewController : UIViewController <OZReportCommandListener> {
}
@property (weak, nonatomic) IBOutlet UIButton *SubmitBtn;
@property (nonatomic, retain) OZReportViewer* viewer;
@property (nonatomic, retain) IBOutlet UIView *OZViewer;
@end
```

#### ViewerController.m

```objectivec
//  ViewController.m
//  app
//
//  Created by John Kim on 2021/10/27.
//
 
#import "ViewController.h"
#import <OZRViewer/OZReportAPI.h>
 
@interface ViewController ()
 
@end
 
@implementation ViewController
@synthesize viewer, OZViewer;
 
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
 
    [self performSelector:@selector(createViewer) withObject:nil afterDelay:0.1];
 
}
 
-(void)createViewer{
    NSString* ozserverUrl = @"http://oz.ozeform.io/oz/server";
    NSString* ozrFileName = @"demo/customer.ozr";
 
    NSString* paramStr = [NSString stringWithFormat:@"connection.servlet=%@\n", ozserverUrl];
    paramStr = [NSString stringWithFormat:@"%@connection.reportname=%@", paramStr, ozrFileName];
 
    OZReportViewer* newViewer = [OZReportAPI createViewer:self view:self.OZViewer listener:self param:paramStr closeButton:nil];
    self.viewer = newViewer;
}
 
- (IBAction)Submit:(id)sender {
    NSString* validity = [self.viewer GetInformation:@"INPUT_CHECK_VALIDITY"];
    if ([validity isEqualToString:@"valid"]) {
        NSString* inputData = [self.viewer GetInformation:@"INPUT_JSON_ALL"];
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Input data" message:inputData preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *closeAction = [UIAlertAction actionWithTitle:@"Close" style:UIAlertActionStyleCancel handler:nil];
        [alert addAction:closeAction];
        [self presentViewController:alert animated:YES completion:nil];
    }
}
 
@end
```

#### Info.plist

App Transport Security Settings > Allow Arbitrary Loads > **YES**

### Run the app

![](https://2677009089-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MjDM4l4HfP5CuJGFF23-887967055%2Fuploads%2FKnS8xJABgGqOnfA6NaCT%2Frun_app_simulator.png?alt=media\&token=24ed0bc7-3a25-45ac-8563-9b0ab83be762)
