모바일 Api 호출

Oracle Mobile Hub 에서 백엔드는 앱에서 사용할 수 있는 사용자정의 api, 저장 영역 모음 및 기타 리소스의 논리적 그룹화입니다. 또한 백엔드는 이러한 리소스에 액세스하기 위한 보안 컨텍스트를 제공합니다.

IOS 앱에서 백엔드를 사용하기 위한 일반 단계는 다음과 같습니다.

  1. 앱에 클라이언트 SDK를 추가합니다.

  2. 백엔드에 대한 환경 및 인증 세부정보로 OMC.plist 를 입력합니다.

  3. 구성 정보를 로드할 수 있도록 앱에 SDK 호출을 추가합니다.

  4. 인증을 처리하기 위해 앱에 SDK 호출을 추가합니다.

  5. 사용할 다른 SDK 호출을 추가합니다.

백엔드 구성 로드

IOS 클라이언트 SDK를 사용하여 Oracle Mobile Hub API를 성공적으로 호출하려면 앱의 OMC.plist 파일에서 모바일 백엔드의 구성이 로드되어 있어야 합니다. OMCMobileBackend 클래스를 사용하여 다음 작업을 수행합니다.

/**
 * Returns the mobile backend that is configured in OMC.plist file
 */
OMCMobileBackend* mbe = [[OMCMobileManager sharedManager] mobileBackend];

플랫폼 Api 호출

백엔드의 구성 정보가 앱에 로드되면 iOS 코어 라이브러리 클래스를 기반으로 클라이언트 SDK 클래스를 호출할 수 있습니다.

IOS 코어 라이브러리 (libOMCCore.a) 는 다음과 같은 주요 인터페이스를 제공합니다.

  • OMCMobileManager

  • OMCMobileBackend (OMCMobileComponent 의 하위 클래스)

  • OMCCxAAnalyticsApp (OMCMobileComponent 의 하위 클래스)

  • OMCServiceProxy

SDK의 루트 객체는 OMCMobileManager 입니다. OMCMobileManagerOMCMobileBackend 객체를 관리합니다.

OMCMobileBackend 객체는 플랫폼 api 호출과 정의한 사용자 정의 api를 비롯하여 애플리케이션과 연관된 모바일 백엔드 간의 접속, 인증 및 기타 트랜잭션을 관리하는 데 사용됩니다. OMCLocationOMCStorage 와 같은 OMCServiceProxy 의 하위 클래스를 통해 플랫폼 api에 대한 호출을 관리합니다.

다음은 스토리지 API를 호출하기 위해 SDK 클래스를 사용하는 예입니다.

#import "OMCMobileBackend.h"
#import "OMCMobileManager.h"
#import "OMCAuthorization.h"
#import "OMCStorage.h"
#import "OMCMobileBackend+OMC_Storage.h"
#import "OMCSynchronization.h"

- (NSData*)dataFromStorageObjectWithID:(NSString*)objectID collectionID:(NSString*)collectionID {     

  // Get mobile backend
  OMCMobileBackend* mbe = [[OMCMobileManager sharedManager] mobileBackend];

  // Get storage object
  OMCStorage* storage = [mbe storage];
    
  // Get your collection
  OMCStorageCollection* collection = [storage getCollection:collectionID];
    
  // Get your object from your collection
  OMCStorageObject* object = [collection get:objectID];
    
  // Get the data from payload of your object
  NSData* data = [object getPayloadData];

   return data; }

}

주:

IOS용 Oracle Mobile Hub SDK에서 사용되는 Objective-C에 작성된 메소드는 Swift에 매핑할 수도 있습니다.

사용자정의 Api 호출

클라이언트 SDK는 Oracle Mobile Hub 에서 사용자정의 api 호출을 단순화하는 OMCCustomCodeClient 클래스를 제공합니다.

이 클래스를 사용하여 요청 페이로드가 JSON이거나 비어 있고 응답 페이로드가 JSON이거나 비어 있는 끝점에서 REST 메소드 (GET, PUT, POST, DELETE) 를 호출합니다.

또한 요청 호출이 완료될 때 (처리기가 비동기적으로 실행될 경우) 완료 처리기를 호출할 수 있습니다.

완료 처리기가 설정된 경우, 메소드 호출 완료 시 UI (기본) 스레드에서 호출되어 UI 항목 업데이트를 허용합니다. 완료 블록에는 JSON 객체에 대한 형식별 데이터 (즉, NSDictionary 또는 NSArray) 가 포함됩니다. 반환된 데이터 또는 오류 (HTTP 또는 시스템) 에 대해 완료 블록을 사용합니다.

Authorization(사용자가 인증된 경우) 와 같이 필요한 모든 Oracle Mobile Hub 헤더가 요청에 자동으로 삽입됩니다.

OMCCustomCodeClient 를 사용하면 다음과 같이 표시될 수 있습니다.

#import "OMCCore/OMCMobileBackend.h"
#import "OMCCore/OMCCustomCodeClient.h"
...
 
// A GET, PUT, POST, or DELETE method may be specified here - sent or returned JSON data object may be nil as appropriate.
OMCMobileBackend *backend = [[OMCMobileManager sharedManager] mobileBackend];
OMCCustomCodeClient *ccClient = backend.customCodeClient;
NSDictionary *jsonPayload = @{@"myKey": @"myValue"};
[ccClient invokeCustomRequest: @"API2/endpoint2" 
                       method: "@PUT" 
                         data: jsonPayload, 
                   completion: ^(NSError* error,
                                NSHTTPURLResponse *response,
                                id responseData) {
        // error will be nil if no problems occurred, otherwise it will contain the error object
        // response will be complete HTTP response
        // response data will be Map or Array for JSON object if success or nil if error
}];