App Development and Execution (iOS)

Establish App Development Environment

iOS apps are developed with Xcode and the iOS SDK, which both can run not in Windows computers but in Mac computers. Moreover, you need an Apple developer account to download Xcode, develop an app and test it.

Basically, you should follow the below steps to establish the environment for developing an iOS app. The detailed process may vary according to the updates on the developer site.

  1. Create an Apple developer account

  2. Install Xcode and the iOS SDK

  3. Necessary tasks for distribution

This chapter was written based on the 12.5.1 version of Xcode.

Develop App Project

Follow the below steps to work on an iOS app project in Xcode. Before entering an app project, you should find the archive files that you built in Nexacro Studio and locate them in the designated directory.

Create a project

After creating an iOS project that will contain your Nexacro-based app, configure basic settings. You can create a project by accessing the below menu.

File > New > Project

Select App as a template for the created project.

project_new_01

After deciding on the options for your new project such as the product's name, click the Next button to open a pop-up. Click the Create button in the pop-up after designating the location of the new project and then you will finally see the new project created.

project_new_02_01

A project may be created in a different way depending on the versions of Xcode.

If you use iPhone X, you should add a Launch Storyboard to your project to prevent blanks at the top and bottom of the screen.

Click on the below links for the detailed information.

https://developer.apple.com/ios/update-apps-for-iphone-x/

https://developer.apple.com/ios/human-interface-guidelines/icons-and-images/launch-screen/

Set iOS libraries and frameworks

Set the libraries and frameworks necessary for using the APIs provided by iOS. If you select a target in your project, you will see the General tab at the top of the Xcode screen. In the tab, you can add libraries and frameworks in the 'Frameworks, Libraries, and Embedded Content' section.

project_new_03_01

Click the + button at the bottom of the section and add the below "libc++.tbd" items.

Set Nexacro libraries

Add Nexacro libraries to your iOS project to establish an optimal environment for Nexacro.

The Nexacro library is provided in the form of a compressed file and is provided under the file name nexacro.framework.zip. Click the [+] button in the 'Frameworks, Libraries, and Embedded Content’, select the Add Files, then select the nexacro.framework.zip file.

nexacro_library_추가_자름

Set resources

In this stage, you can set launch images, icons, messages and layouts applied to your app. You can adjust those options according to projects.

Set images

A project in Xcode created with a template contains an empty asset catalog, which is used to manage resources. You can add app icons, launch images, etc. to the catalog.

You can individually set the app icons and launch screen images used in an iOS app. Moreover, you can bring images that are made already.

You must use images that are designed appropriately for the iOS devices you target. Assume that you set an image whose size does not fit target devices or set an image with a property incompatible with target devices. In those cases, an error will occur in the build process or your app will not work properly even if it is built.

Click on the below link to visit the Apple developer web page that provides the details on the settings of icons and images.

https://developer.apple.com/ios/human-interface-guidelines/icons-and-images/image-size-and-resolution/

You can set icons and images in the project configuration. If you select a target in your project, you will see the General tab at the top of the Xcode screen. In the tab, go to the "App Icons and Launch Images" section.

appicon_launch_image_설정_01

By clicking the arrow beside the "App Icons Source" option, you can set app icons at the asset catalog, as illustrated below. Drag and drop icon images into the slots appropriate for each device and use.

appicon_launch_image_설정_02

Set messages

You can create a separate file to save messages that can be used in your app.

To create a new file, select the project folder and select [File > New > File] from the menu.

project_new_07

Choose "Strings Files" from a selection of templates.

project_new_08

Name the file "Localizable" in the Save As field.

project_new_09

Modify the created Localizable.strings file as presented below.

/* 
  Localizable.strings
  HelloiOS
*/
"needupdate" = "It needs an update.";
"loadingFail" = "First loading fails.  \r\nPlease restart.";
"updateFail" = "Update fails.  \r\nPlease restart.";
"notexist" = "Start file does NOT exist.  \r\nPlease restart.";
"BeingUpdated" = "Being updated.";
"wantreplace" = "There is a file of the same name. Do you want to replace? ";
"ok" = "OK";
"cancel" = "Cancel";
"move" = "Move";
"upper" = "Upper";
"filter" = "Filter";
"home" = "Home";
"nofilename" = "No File Name.";
"checkforupdates" = "Check for update.";
"installforupdates" = "Install update.";
"downloadingforupdates" = "Downloading update.";
"force_close" = "Update is Completed.";

In the Utilities pane on the right side of the Xcode screen, click "Localize..." button in the Localization section to select the language for your app. If you do not add another language in advance in the project's settings, the language will be English by default.

Localization_01

To support languages other than English, navigate to the menu [PROJECT > Info > Localizations] and click + button to add another language.

Localization_02

Click on the below link to visit the Apple developer web page that provides the details on localization.

https://developer.apple.com/library/content/documentation/MacOSX/Conceptual/BPInternational/Introduction/Introduction.html

Set Config

Set the nexacro_config.xml file to apply the functionalities provided by Nexacro to your app. You can activate features including app updating, notification and error processing. You should create the nexacro_config.xml file by yourself and locate the file under the folder [{Asset} > data]. This file should be included in the project when your app is built in Xcode.

Even if the nexacro_config.xml file does not exist, there will be no problem in running your app because the default configuration will be applied instead.

The nexacro_config.xml file is in the XML format and written like the below sample.

<?xml version="1.0" encoding="utf-8"?>
<nexacro-config>
  <application dialog-position="top" use-wkwebview="true" file-logging="true" />
  <notification enable="true" handler="DefaultNotificationManagerHandler"/>
  <updator force="false" cancelable="false" quiet="true" errormsg="true" failpass="true"/>
  <xpush-server request-missing-message="true" />
</nexacro-config>

The below table shows the features that you can set in nexacro_config.xml.

Features

Property

Value

Description

application

dialog-position

"top" | "center" | "bottom"

This property sets the position of a pop-up for showing the progress of app updating.

file-logging

"true" | "false"

This property determines whether to log loading errors in the form of a file.

You can check the log file through iTunes.

updator

force

"true" | "false"

This property determines whether to display a pop-up for announcing the existence of an update, contained in start_ios.json.

If "true", updating will be conducted automatically without pop-up announcement.

cancelable

"true" | "false"

This property determines whether to display a "Cancel Update" button in a pop-up for announcing the existence of an update.

If you click the "Cancel" button, the updating will not be conducted and the app will be closed.

errormsg

"true" | "false"

This property determines whether to display a pop-up for showing the error information when the loading of the app fails.

quiet

"true" | "false"

This property determines whether to display a pop-up that asks you whether to update the app.

Even if you specify "true", the progress of app updating will be displayed when there is an update file.

failpass

"true" | "false"

Set whether to ignore the update errors or not

xpush-server

request-missing-message

"true" | "false"

This property determines whether to automatically request reliable messaging messages that you have not received from an XPush server.

notification

enable

"true" | "false"

This property determines whether to use the notification feature.

handler

"[class name]"

This property sets the class to define a handler for processing notification.

The default value is “DefaultNotificationManagerHandler”.

Set build environment

You should modify AppDelegate.h, AppDelegate.m and main.m—default files created in the process of creating an iOS project—in a way that suits Nexacro.

AppDelegate.h

Modify the created AppDelegate.h file as below so that the file inherits the Nexacro's AppDelegate class. Then, the nexacro framework will work properly.

//
//  AppDelegate.h
//  HelloiOS
//

#import <UIKit/UIKit.h>
#import <nexacro/NexacroAppDelegate.h>
#import <nexacro/NexacroMainViewController.h>

@interface AppViewController : NexacroMainViewController
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation;
@end

@interface AppDelegate : NexacroAppDelegate <UIApplicationDelegate>
-(NexacroMainViewController*)initializeMainViewController;
@end

AppDelegate.m

In the AppDelegate.m file, you should specify the URL of the start_ios.json file located in the server. The JSON file is created with Nexacro Studio. Replace the portion written in bold in the below code listings with something appropriate for your settings.

//
//  AppDelegate.m
//  HelloiOS
//

#import "AppDelegate.h"
#import <nexacro/NexacroWKWebViewDelegate.h>

@interface WebViewDelegate : NexacroWKWebViewDelegate
@end

@implementation AppViewController

// Supporting auto rotation (return: YES|NO)
- (BOOL)shouldAutorotate
{
    return YES;
}

// Supporting rotation direction (return: plug with rotation direction bit value set)
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAll;
}

@end

@implementation AppDelegate
    
- (NexacroMainViewController*)initializeMainViewController
{
    NSString *bootstrapUrl = @"http://[URL]/start_ios.json";

    [[NexacroResourceManager sharedResourceManager] setBootstrapURL:bootstrapUrl isDirect:NO];
    
    // Initialize if the delegate event from WKWebView is not needed
    // AppViewController* controller = [[AppViewController alloc] initWithFullScreen:NO];
    
    // Initialize if the delegate event from WKWebView need to be received
    WebViewDelegate* webviewDelegate = [[WebViewDelegate alloc] init];
    AppViewController* controller = [[AppViewController alloc] initWithFullScreen:NO
                                                               andWebviewDelegate:webviewDelegate];

    return controller;
}
    
@end

// Embodiment delivered when initializing the AppViewController to receive WKWebView's delegate event
@implementation WebViewDelegate

#pragma mark - WKWebView - WKNavigationDelegate
- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
{
    [super webView:webView didFinishNavigation:navigation];
    
    // The point when the content data loading is complete
}
@end

main.m

UIApplicationMain is a default function provided by the UIKit framework, serving as a starting point of an app. This function gets the app ready to receive inputs from the user by preparing for the operation of the app and setting up the main event loop.

After checking whether the main.m file is written as below, modify the file if different.

//
//  main.m
//  HelloiOS
//

#import <UIKit/UIKit.h>
#import "AppDelegate.h"

int main(int argc, char * argv[]) {
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
    }
}

Other settings

You need to change some options in "Build Settings".

Build Settings > Architectures > Build Active Architecture Only

Debug: No
Release: No
Build Settings > Apple LLVM 9.0 - Language - Object C > Objective-C Automatic Reference Counting

Yes

Set your app stand-alone in disconnected environments

When packing an app in Nexacro Studio, if the Update Type is set to Local or Update (Local+Server), the app can be run without a network connection. In general, the Local type is used when a network connection is not required, and the Update (Local+Server) type is used when you need to run the app with a local file after running the app while connected to the network. To enable the app to run without a network connection or independently there is a problem with the network, the files necessary to run the app must be loaded and deployed when building the app.

The files necessary for executing an app include modules, sources, resources, Run.zip and start_ios.json, which are all obtained through the Packing (Archive&Update) process of Nexacro Studio. If you load those files onto the "archive" folder in your Xcode project before building an app, you can run the app without a network connection.

Even if you set the update type to "Local" in the Packing (Archive&Update) process of Nexacro Studio, you must specify a bootstrap URL in the AppDelegate.m file of your Xcode project.

For example, you can specify a random URL like the below one, which is either virtual or unused actually.

NSString *bootstrapUrl = @"http://192.168.0.1/_ios_/start_ios.json";

1

Create an "archive" folder in Finder and copy module, source and resource files to the folder.

Open Finder and create an "archive" folder under your Xcode project. Then, find the files created through the Packing (Archive&Update) process of Nexacro Studio and copy them to the archive folder, as illustrated below.

01_Finder에_폴더생성및파일복사

2

Add the archive folder to your Xcode project.

Click the plus (+) button at the bottom of Xcode's project navigator and select Add Files to "project name".

02_Xcode_파일추가

Select the archive folder and choose "Create folder references" as an "Added folders" option. Then, click the Add button.

03_Xcode_파일추가2

3

Check whether the folder and files have been added to your project successfully.

Go to the project navigator of Xcode and check whether the archive folder and the files under the folder have been added successfully.

04_Xcode_확인

Folders in Xcode's project navigator are displayed in either yellow or blue. Yellow folders are nonexistent since they are just logical groups that serve as an indicator of the project's organization. By contrast, blue ones are actual Finder folders. After an app is built, files in yellow folders are included in the app's root directory while files in blue folders are contained in their respective folders with the folder structure unchanged.

Test App

You can test your app by connecting an iOS device to your PC using a USB cable or by using a simulator. If you use a physical device, you should install an appropriate profile on the device.

  1. As seen below, access the Scheme menu at the top of the Xcode screen and choose a destination—a connected iOS device or an iOS simulator where your app will be tested.

select_device_01

select_device_02_01

  1. Run your app by clicking the Run button at the top of the Xcode screen or accessing the Run menu.

select_device_01

Product > Run

project_new_13_resize