PallyCon NCG iOS SDK Guide

PallyCon NCG iOS SDK makes it easy to apply INKA's NCG(Netsync Content Guard) DRM when developing media service apps for iOS. This document describes how to use the libraries and sample project included in the SDK.

Details of PallyCon Multi DRM service integration are provided in License Callback API and License Token API guides. For technical questions about using the SDK, please visit our Helpdesk site.

SDK products can be requested when subscribing to PallyCon cloud commercial service. Then SDK can be downloaded from the Download page of PallyCon admin site.


Supported environment

  • iOS 9.0 or later
  • ARC(Automatic Reference Counting) required
  • This SDK has been tested in Xcode 8 and will not work on the simulator.

Playback Scenario

The playback scenarios and content types supported by the NCG iOS SDK are:

  • Local download : MP4 video encrypted by NCG DRM (*.mp4.ncg file)
  • Progressive Download : MP4 video encrypted by NCG DRM (*.mp4.ncg file)
  • HLS Streaming : HLS(HTTP Live Streaming) content protected by NCG DRM

Local Download

MP4 content encrypted by NCG is downloaded to local storage and played back.

Progressive Download

MP4 content encrypted by NCG is streamed directly from a remote server.

HLS Streaming

HLS content protected by NCG is streamed from a remote server.

SDK Workflow

  1. Initialize SDK
  2. Check DRM license of content
  3. If license data already exist, validate the license
  4. If there is no license data, acquire license from PallyCon server
  5. Playback content
  6. Play DRM content using the valid license

1. SDK Initialization

Initialize

SDK sets the data such as RODB(Right Object DataBase), Device ID, On/Off line policies, Secure Time, start of Local Web Server, etc. through the initialization.

+ sharedInstance

Singleton pattern is applied to SDK, and to use Ncg2Agent object, it needs to be approached through sharedInstance:. If you try to create the object in the form of alloc or init, an exception will occur; therefore, direct object creation should be avoided. Acquire instance by creating Ncg2Agent object.

Ncg2Agent.h
+ (id) sharedInstance Ncg2Agent object creation

- initialize:

Ncg2Agent.h
- (BOOL) initialize : (OfflineSupportPolicy)policy On/off-line scenario policy decision
rodbPath : (NSString*)rodbPath license - set the path of DB storage; automatically created when nil is input
deviceId : (NSString*)deviceId Device - ID input, automatically extracted when nil is input
error : (NSError**)error return error if it is not nil
- (BOOL) initialize : (OfflineSupportPolicy)policy On/off-line scenario policy decision
executionLimit : (int)executionLimit if it is off-line, designate the number of times it is executed; infinite if it is "0"
rodbPath : (NSString*)rodbPath license - set the path of DB storage; automatically created when nil is input
deviceId : (NSString*)deviceId Device - ID input, automatically extracted when nil is input
error : (NSError**)error return error if it is not nil

If Ncg2Agent object is created, data in SDK is set by calling initialize:. To use SDK, it needs to be called at least once, and it is recommended to be called when the App is initialized.

OfflineSupportPolicy has an effect on SDK operation scenario when the device is offline.

typedef enum _OfflineSupportPolicy
{
    OfflineSupportNo = 1,
    OfflineSupportYes = 2,
} OfflineSupportPolicy;
  • OfflineSupportNo: It is a policy that is only operated when SDK is On-line. Even if a valid license exists in the device, the license is always acquired through the license server. It there is need to enhance web security and stabilize the operation, it is recommended to use OfflineSupportNo policy.

  • OfflineSupportYes: It is a policy that is only operated when SDK is On/Off-line. If a valid license exists in the device, the license is used; if not, the license is acquired through the license server. If there are previously downloaded contents in the device with a valid license, they can be played regardless of On/Off-line.

executionLimit can decide the number of times SDK (or app) can executed when it is Off-line. If it is used more times than the predefined number of times, initialize: needs to be called on-line, and the number of times is initialized. Designation of the number of times to be executed is operated only under OfflineSupportYes policy; infinite if it is ‘0’.

NOTE:

  • executionLimit is the number of times initialize: is called off-line, and the status change which is from the Background to the Foreground does not affect the number.
  • excutionLimit - initialize: without a parameter sets the number of times SDK is used off-line to be 10 times if OfflineSupportPolicy is OfflineSupportYes.

rodbPath designates the storage path of RODB. If it is not designated, it is designated to be same as the path set in the SDK. deviceId is a value that is importantly used for limiting the number of devices per user ID and for encrypted communication with the license server. ID must be unique, and must not be changed. If ‘nil’ is input, it is automatically created inside SDK.

NOTE:

  • Device ID created inside SDK is stored the KeyChain, and the Device ID is not deleted even if the app is deleted.
  • If the app is reinstalled, the Device ID in the KeyChain is used.
  • If DFU (Device Firmware Upgrade) is executed in the device, the Device ID is deleted since the KeyChain is initialized.
  • If the Device ID is deleted, SDK issues new Device ID.

Local Web Server

The Local Web Server has the role of sensing external output and multiple connection, decryption, and interface with external servers. To receive the events that are created in the Local Web Server, you can register Delegate at the location you want to receive. If license verification process and Play place are different class, the Delegate needs to be installed in both location.

- getLocalWebServerInstance

Ncg2Webserver object created in initialize: is acquired.

Ncg2Agent.h
- (Ncg2Webserver*) getLocalWebServerInstance Ncg2Webserver object return

Local Web Server Protocol

Call back function that receives events created in the Local Web Server

- onNotification:

It returns an alarm, if there is the alarm in the Local Web Server.

WebServerDelegate(Required)
- (void) onNotification : (int)notificationCode Notification Code is returned
notifyMessage : (NSString*)notifyMessage Notification message is returned
- onError:

It returns the error, if there is an error in the Local Web Server.

WebServerDelegate(Required)
- (void) onError : (int)errorCode Error Code is returned
errorMessage : (NSString*)errorMessage Error message is returned
- onCheckPlayerStatus:

It is used to check whether the data is sent to a real player, when the local web server sends the data. The local web server calls this function in every certain term.

WebServerDelegate(Required)
- (PlayerState) onCheckPlayerStatus : (NSString*)uri Playback URL is returned
- (PlayerState) onCheckPlayerStatus:(NSString *)uri
{
    int nReturnVal = 0;//NCGPlayerStatusFailed;

    switch ([self.mPlayer.currentItem status])
    {
        case AVPlayerItemStatusUnknown:
            nReturnVal = PlayerStateUnknown;
            break;
        case AVPlayerItemStatusReadyToPlay:
            nReturnVal = PlayerStateReadyToPlay;
            break;
        default:
            nReturnVal = PlayerStateFail;
            break;
    }

    return nReturnVal;
}

PlayerState

It is a value that is used to show the status of the player.

PlayerState
      PlayerStateUnknown State of the player is unknown
      PlayerStateReadyToPlay Ready to play state
      PlayerStateFail error or released state

- setWebServerDelegate:

It is a function that registers an object of class that will receive the event of the local web server. WebServerDelegate is declared to the related class.

Ncg2Webserver.h
- (void) setWebServerDelegate : (id< WebServerDelegate >)webServerDelegate Register an object that will receive the event

NOTE:

  • The event created from the local web server must be received and handled appropriately. For example, if external display occurs during the use of contents that the external display is restricted, the local web server stops encryption and creates the event; it needs to be received and handled appropriately.

HTTP Callback (Optional)

SDK exchanges necessary data with servers using internal HTTP. But there are some cases that external communication is needed, rather than internal HTTP communication. For example, if services such as one-time URL or HTTPS communication are used, HTTP communication must be controlled from outside.

HTTP Callback Protocol

It is the HTTP callback function. If an object is registered to setHttpRequestDelegate:, internal HTTP communication is proceeded with the following function.

NcgHttpRequestDelegate(Required)
- (NSData*) handleHttpRequest : (NSString*)requestURL Request URL
urlParameter : (NSString *)parameter Additional URL information
- (int) getResponseStatus HTTP state code callback
- (NSString*) getResponseMessage HTTP response message callback
- (NSString*) getLastErrorMessage HTTP error message callback

- setHttpRequestDelegate:

It is a function that receives HTTP callback event. It declares NcgHttpRequestDelegate to the related class.

Ncg2Agent.h
- (void) setHttpRequestDelegate : (id< NcgHttpRequestDelegate >)delegate Register an object that will receive the event

Exception Handle (Optional)

It is used when you want to receive an error or log occurred inside SDK. Also, when a commercial crash report product is used, prompt understanding of the cause becomes possible by checking the error occurred inside.

Exceptional Event Protocol

It is a function that will receive exceptional events. You can declare it to implement inside.

NcgExceptionalEventDelegate(Optional)
- (void) log : (NSString*)logMessage returns log messages
- (void) logHandle : (NSError*)error returns error codes

- setExceptionalEventDelegate:

It is a function that registers an object of class which will receive the exception event.

Ncg2Agent.h
- (void) setExceptionalEventDelegate : (id< NcgExceptionalEventDelegate >)delegate Register an object that will receive the event

2. License

In this chapter, the method for a validity test and acquiring/removing of packaged contents’ license is explained.

Contents Check

Check whether the contents are packaged contents.

- isNcgContent:

If the file path or URL is entered, it will return the result whether they are packaged contents.

Ncg2Agent.h
-(BOOL) isNcgContent : (NSString*)path Path or URL of contents
error : (NSError**)error Returns an error

NOTE:

  • isNcgContent: function is used frequently in functions provided by SDK. For example, checking whether they are packaged contents takes place first inside functions such as checking, acquiring, and verifying of license.

License Check

Check existence and validity of license for packaged contents.

- checkLicenseValidByPath:

Validity of license can be verified by inputting the path or URL of packaged contents.

Ncg2Agent.h
-(BOOL) checkLicenseValidByPath : (NSString*)path Path or URL of contents
result : (LicenseValidation*)lv Returns the result of the license verification
error : (NSError**)error Returns an error

- checkLicenseValidByCID:

Validity of the license can be checked by inputting CID and Site ID of packaged contents. cid and siteID can be acquired with getNcg2HeaderInfo:.

Ncg2Agent.h
-(BOOL) checkLicenseValidByCID : (NSString*)cid contents ID
siteID : (NSString*)siteID contents Site ID
result : (LicenseValidation*)lv Returns the result of the license
error : (NSError**)error Returns an error

License Acquisition

It is a function that can acquire a license, if packaged contents do not have a license.

- acquireLicenseByPath:

The license can be acquired by inputting the path or URL of packaged contents. orderID is the information that a contents Provider (CP) provides.

Ncg2Agent.h
-(BOOL) acquireLicenseByPath : (NSString*)path path or URL of contents
userID : (NSString*)userID user ID
orderID : (NSString*)orderID order ID
isTemporary : (BOOL)isTemporary whether the license is stored
error : (NSError**)error returns an error

- acquireLicenseByCID:

License can be acquired by inputting CID and Site ID of packaged contents. cid and siteID can be acquired with getNcg2HeaderInfo:. orderID is the information that a contents Provider (CP) provides.

Ncg2Agent.h
-(BOOL) acquireLicenseByCID : (NSString*)cid contents ID
siteID : (NSString*)siteID contents Site ID
userID : (NSString*)userID userID
orderID : (NSString*)orderID orderID
acquisitionUrl : (NSString*)acquisitionUrl license server URL
isTemporary : (BOOL)isTemporary whether the license is stored
error : (NSError**)error returns an error

NOTE:

  • When the license is acquired, isTemporary parameter decides the operation of the license. YES: The license is not stored. It is suitable for the scenario that the license is acquired every time from the license server without storing the license. After using the license, the license in the memory must be removed by calling removeAllTemporaryLicense:. NO: The license is stored to be used. It is suitable for the scenario that uses the stored license, if the license is received and stored. If necessary, the license can be removed by calling removeLicenseByPath:, removeLicenseByCID:.
  • If the returned value of License Acquisition is NCGERR_LICENSE_SERVER_RESPONSE_ERROR(0xF0002003), this error (NSError) must be checked, since it is a definite server error. Especially, if the server error code is 8002, the error must be checked and treated since it is a custom error.

- acquireLicenseByToken:

You can acquire licenses using tokens. cid and siteID can be acquired with getNcg2HeaderInfo:.

Ncg2Agent.h
-(BOOL) acquireLicenseByToken : (NSString*)token token
cid : (NSString*)cid content ID
siteID : (NSString*)siteID Site ID
userID : (NSString*)userID User ID(optional)
acquisitionUrl : (NSString*)acquisitionUrl License Server URL
isTemporary : (BOOL)isTemporary whether the license is stored
error : (NSError**)error returns an error

NOTE:

  • The token has already been created in order to acquire the license using the token.
  • The token requires content-packaged information Site ID, ContentID(cid), and Access Key.
  • The token issuance process can be checked in PallyCon Multi-DRM License Token API.
  • For more information on token generation, please contact INKA HelpDesk.

License Remove

It is a function that can remove the license of packaged contents.

- removeLicenseByPath:

It deletes the stored license. The license can be removed by inputting the path of packaged contents.

Ncg2Agent.h
-(BOOL) removeLicenseByPath : (NSString*)path Path or URL of contents
error : (NSError**)error returns an error

- removeLicenseByCID:

The stored license is removed. The license can be removed by inputting CID of packaged contents. cid and siteID can be acquired with getNcg2HeaderInfo:.

Ncg2Agent.h
-(BOOL) removeLicenseByCID : (NSString*)cid contents ID
error : (NSError**)error returns an error
-(BOOL) removeLicenseByCID : (NSString*)cid contents ID
siteID : (NSString*)siteID contents Site ID
error : (NSError**)error returns an error

- removeAllTemporaryLicense:

It deletes the license stored in the memory. When acquiring the license of packaged contents (acquireLicenseByPath, acquireLicenseByCID), if it is temporarily acquired (`isTemporary=YES), it must be called to remove the license after the use of related contents is finished.

Ncg2Agent.h
-(BOOL) removeAllTemporaryLicense : (NSError**)error returns an error

NOTE:

  • If the temporarily acquired license is not removed, License Acquisition is not tried until the application is terminated.

License Information

The license information of packaged contents can be verified. To verify the license information, it should be in state which the license is already acquired.

- getLicenseInfoByPath:

If there is a license already acquired, the information of the license can be validated by inputting the path of packaged contents.

Ncg2Agent.h
-(BOOL) getLicenseInfoByPath : (NSString*)path Path or URL of contents
licenseValidation : (LicenseValidation*)lv returns the license validation result
licenseInformation : (Ncg2LicenseInformation**)li returns the license information
error : (NSError**)error returns an error

- getLicenseInfoByCID:

If there is the acquired license, the license information can be verified by inputting ID(CID) and Site ID of packaged contents. cid and siteID can be acquired with getNcg2HeaderInfo:.

Ncg2Agent.h
-(BOOL) getLicenseInfoByCID : (NSString*)cid contents ID
siteID : (NSString*)siteID contents Site ID
licenseValidation : (LicenseValidation*)lv returns the license verification result
licenseInformation : (Ncg2LicenseInformation**)li returns the license information
error : (NSError**)error returns an error

Ncg2LicenseInformation

It is the license information class.

Ncg2LicenseInformation
      - (NSString*) getPlayStartDate start date for license validity
      - (NSString*) getPlayEndDate end date for license validity
      - (long) getPlayFirstDate date of the initial usage
      - (NSString*) getPlayVerificationMethod verification method when the period is checked
      - (long) getPlayDurationHour total available time
      - (long) getPlayTotalCount remaining available number of times
      - (long) getPlayRemainCount does not use
      - (Ncg2LicenseOutputProtectionPermission*) getOutputProtectionPermission whether external output is permitted

Ncg2LicenseOutputProtectionPermission

It is the external output permission information class.

Ncg2LicenseOutputProtectionPermission
      - (bool) getIsExternalDisplayAllow whether to permit external output
      - (int) getAps does not use
      - (int) getCgms_a does not use
      - (int) getCavendish does not use
      - (int) getHdcp does not use
      - (bool) getIsJailBreakAllow whether to permit a jail breaking terminal
      - (int) getSendReport does not use
      - (int) getIsJailBreakExternalDisplayAllow whether to permit external output of a jail breaking terminal

LicenseValidation

It is the license authority information.

LicenseValidation process
      LicenseValidationValid valid license Playback
      LicenseValidationNotExist when the license does not exist. License Acquisition
      LicenseValidationExpired license expired contents can’t be used
      LicenseValidationBeforeStartDate When it is before the start date yet wait until the start date
      LicenseValidationExceededPlayCount the play count is expired contents can’t be used
      LicenseValidationExternalDeviceDisallowed external output is not permitted External Display
      LicenseValidationNotSupportOffline does not support Off-line operation requires On-line environment
      LicenseValidationAbnormalDevice Jail breaking terminals are not permitted contents can’t be used
      LicenseValidationOfflineTooLong Secure Time update is needed updateSecureTimeFromServer is called
      LicenseValidationScreenRecorderDetected when the screen monitoring APP is detected Screen Recorder

Header Information

Information regarding the contents are stored in the header of packaged contents.

- getNcg2HeaderInfo:

It gets the header information of packaged content file.

Ncg2Agent.h
-(Ncg2HeaderInformation*) getNcg2HeaderInfo : (NSString*)path Path or URL of contents
error : (NSError**)error returns an error

Ncg2HeaderInformation

It is a class that shows the header information of packaged contents.

Ncg2HeaderInformation
      - (NSString*) contentID contents ID
      - (NSString*) siteID site ID
      - (NSString*) acquisitionUrl license server URL
      - (NSString*) source service provider
      - (NSString*) packDate date of packaging
      - (int) encryptionLevel encryption level
      - (int) encryptionRange encryption range

3. Playback

If the license of packaged contents is valid, the contents can be used. But the packaged contents are encrypted and need to be decrypted; such role is taken by the local web server. Therefore, it needs to be requested to the local web rather than the actual path or URL of contents, when the packaged contents are played.

  1. Playback URL is acquired from the local web server.
  2. The player requests the contents data with the playback URL received from the local web server.
  3. The local web server requests the downloaded contents or the contents data in the remote location.
  4. The contents are sent to local web server in encryption.
  5. The local web server decrypts the encrypted data.
  6. The decrypted data is sent to the player.
  7. The player plays the decrypted data.
  8. If the playback is finished, temporary license/playback URL is removed.

Download Contents

For the contents that are downloaded or being downloaded, the playback URL is requested using the function below.

- addLocalFilePathForPlayback:

Ncg2Webserver.h
- (NSString*) addLocalFilePathForPlayback : (NSString*)path path of stored contents or contents being downloaded
remoteUrlForDnp : (NSString*)remoteUrlForDnp contents download URL
fileSize : (int64_t)fileSize contents file size
error : (NSError**)error returns an error

Progressive Download

If packaged contents are the contents uploaded to the web server, the playback URL is requested using the function below.

- addProgressiveDownloadUrlForPlayback:

Ncg2Webserver.h
- (NSString*) addProgressiveDownloadUrlForPlayback : (NSString*)url contents URL
error : (NSError**)error returns an error

HTTP Live Streaming(HLS)

If packaged contents are HLS contents, the playback URL can be requested.

- addHttpLiveStreamUrlForPlayback:

Ncg2Webserver.h
- (NSString*) addHttpLiveStreamUrlForPlayback : (NSString*)url contents URL
error : (NSError**)error returns an error
- (NSString*) addHttpLiveStreamUrlForPlayback : (NSString*)url contents URL
cid : (NSString*)cid contents ID
error : (NSError**)error returns an error

- decreasePlaybackCount:

For the contents that the number of times is limited, it must be called to deduct the number when the contents are started or finished to be used.

Ncg2Agent.h
- (BOOL) decreasePlaybackCount : (NSString*)path Path or URL of contents
error : (NSError**)error returns an error

NOTE:

  • Before deducting the number, it is recommended to send a message to notify it.
  • The remaining number of times can be viewed by checking getPlayRemainCount in (License Information).
  • In Sample Project, the number is deducted when the video contents start to play.

Playback Finish

If the playback ends, the playback URL that is used, is removed.

- clearVirtualPlaybackUrls

Ncg2Webserver.h
- (void) clearVirtualPlaybackUrls It is called when the player ends.

4. Security

Factors in security operation and security issues that can occur during SDK operation, are explained.

Secure Time

Device time is not suitable to be used to verify the usage time of packaged contents since the user can change it. To solve such problem, SDK manages secure time internally. But the time may not be accurate due to battery discharge or OS/device/application errors. In these cases, SDK needs to return that time needs to be updated on-line, and guides to update the time in the application. The secure time is managed as GMT time, and it is used for the verification of short-term contents’ license.

- getNcgSecureTime:

The time used inside of SDK can be checked.

Ncg2Agent.h
- (NSString*) getNcgSecureTime returns GMT time

- updateSecureTimeFromServer:

Among the value of LicenseValidation, if LicenseValidationOfflineTooLong is returned, it means there is an error in Secure Time; the Secure Time must be updated to valid time. Since the time is received from the external server, the device must be in On-line state.

Ncg2Agent.h
- (BOOL) updateSecureTimeFromServer : (NSError**)error

External Display

In the license, the information that can limit external display is included. According to this information, the external display can be permitted. In case the external display is permitted, the video can be played in some other screens through HDMI, Mirror, and AirPlay. For the contents that the external display is limited, it needs to be notified to the user that ‘the contents that external display is limited’. Notification of the external display has two scenarios.

  • Before the contents playback When checking the license of contents while the external display is connected (License Check), if the external display is limited, they do not play.
  • During the contents playback If the external display is connected during the playback of contents, the local web server stops the decryption and creates an event to onNotification: that the external display is connected; then stops the playback with an appropriate guide message.

NOTE:

-If the external display is connected during the playback, the local web server stops the decryption and does not send the data to the player. At that time, the alarm code to onNotification: is LWS_NOTIFY_HDMI_DETECTED.

  • Even if the local web server doesn’t send the data, the player stops after it plays all the data it had in the cache; therefore, it is recommended to stop the playback when the event is created.
  • The screen of iOS device can be recorded with iOS8.0 or above + lightening cable + MAC OS Yosemite QuickTime Player. To prevent such recording, HLS contents must be used.

Screen Recorder

The contents that are played can be recorded with the screen recording App. If such App is installed, the contents playback must be stopped.

- setScreenRecorderAppDetecting:

In case SDK recording App is installed, it is set to disallow the contents playback (default). But for the audio contents, using the recording App may be inconvenient. In this case, you can set not to use this function.

Ncg2Agent.h
- (BOOL) setScreenRecorderAppDetecting : (BOOL)enabled whether the recording App is detected

- getDetectedScreenRecorderName:

It returns the name of App that is detected. It notifies the user what it is, so that the user can remove it.

Ncg2Agent.h
- (NSString*) getDetectedScreenRecorderName returns the name of recording App that is detected.

NOTE:

  • The recording App is detected through the recording App list. If the recording App is not in the list, it is not detected.
  • In this case, the related App information should be provided to Inka, so that it can be included in the list, and the latest SDK can be used.

5. NCG File I/O

Packaged contents can’t be controlled by general file I/O(fopen, fread, fseek..). To read the packaged contents accurately, Ncg2File interface needs to be used. In this chapter, File I/O interface that can control the packaged NCG contents and unpacking (Decryption) are explained.

- createNcgFile:

To handle the NCG contents, Ncg2File object should not be directly created; rather, it should be created with the createNcgFile: method.

Ncg2Agent.h
- (Ncg2File*) createNcgFile : (NSError**)error returns NCG file object

- open:

It opens the packaged NCG contents.

Ncg2File.h
- (BOOL) open : (NSString*)path file path
isPrepare : (BOOL)isPrepare whether to open a file in state which it can be decrypted
error : (NSError**)error returns an error

isPrepare If YES, it becomes possible to unpack by acquiring the packaged contents information and license information. If NO, only packaged contents information can be acquired.

NOTE:

  • It can be opened open only if a valid license for the contents to be unpacked exists.
  • If the license of contents to be unpacked does not exist, the license must be acquired License Acquisition](#license-acquisition)).

- read:

By reading the encrypted file, it returns the data size of decrypted data and data actually read.

Ncg2File.h
- (int) read : (unsigned char*)buffer buffer that the decrypted data is stored
sizeToRead : (int)sizeToRead buffer size
error : (NSError**)error returns an error

- seek:

It is used to move to a desired location of file.

Ncg2File.h
- (BOOL) seek : (int64_t)offset designates the location to be moved (offset)
method : (SeekMethod)method decides where to offset
error : (NSError**)error returns an error

Seek Method

The seek method is explained.

Seek Method
      SM_Begin initial location of file
      SM_Current current location of a file pointer
      SM_End location of the end of file

- getCurrentPointer:

It returns the current location of a file pointer.

Ncg2File.h
- (int64_t) getCurrentPointer : (NSError**)error returns the current location of a file pointer

- getContentSize:

It returns the size of original file.

Ncg2File.h
- (int64_t) getContentSize : (NSError**)error returns the size of original file.

- getNcgHeaderSize:

It returns the header size of packaged contents.

Ncg2File.h
- (int64_t) getNcgHeaderSize : (NSError**)error returns the header size

- close:

It closes the opened file and allocated resources.

Ncg2File.h
- (void) close open file is closed.

Unpack Sample Code

It is a sample code that unpacks the packaged contents.

NSError* error = nil;
Ncg2File* ncgFile = [Ncg2Agent createNcgFile:&error];
if( error != nil )
{
    NSLog(@"createNcgFile() Failed!");
    return;
}

if( [ncgFile open:ncgFilePath isPrepare:YES error:&error] == NO )
{
    NSLog(@"open() Failed!");
    return;
}

FILE* fp = fopen( [unpackFilePath UTF8String], "wb" );
fseeko(fp, 0, SEEK_SET);
unsigned char buffer[8192] = {0};
while( TRUE )
{
    int32_t read = [ncgFile read:buffer sizeToRead:sizeof(buffer) error:&error];
    if(error != nil)
    {
        NSLog(@"read() Failed!");
        [ncgFile close];
        fclose( fp );
        return;
    }

    if ( read <= 0 )
        break;

    fwrite( buffer, 1, read, fp );
}

fclose( fp );
[ncgFile close];

results matching ""

    No results matching ""