iOS SDK integration

SDK integration

CocoaPods integration mode

  • Update Podfile file

    Add the following codes in the Target corresponding to the Podfile of the project

      pod 'VerifyCode'
    
  • Integrate SDK

    Under the current directory of the project, run pod install or pod update

  • Project setting

    In the project target directory, set Build Settings —> other link flags to -ObjC.

    Remarks

    (1). Execute pod search VerifyCode on the command line. If the version of VerifyCode displayed is not up to date, execute the pod update operation to update the contents of the local repo.

    (2). If you want to use the latest version of the SDK, execute pod update

    (3). If you project has a "Deplyment Target" lower than 8.0,Then add the following statement in front of the Podfile file.Platform :ios, '8.0'

Manual integration

  • Download VerifyCode SDK

    Address: https://github.com/yidun/captcha-ios-demo

  • Import VerifyCode.framework to XCode project: Drag and dropVerifyCode.frameworkfile to Xcode project(please check Copy items if needed option)

  • Import NTESVerifyCodeResources.bundleto project: Go to Build Phase and in the Copy Bundle Resources option, add the NTESVerifyCodeResources.bundle file (check theCopy items if neededoption).

  • Add dependent library SystemConfiguration.framework JavaScriptCore.frameworkWebKit.framework

  • Project setting

    In the project target directory, set Build Settings —> other link flags to -ObjC.

    Remarks
    (1).Ignore if the above system framework already exists

    (2).SDK minimum compatible system version iOS 8.0

SDK usage

Object-C project

  • Introduce the VerifyCode SDK header file in the project that needs to use the SDK, as follows:

    #import <VerifyCode/NTESVerifyCodeManager.h>

  • Initialize the SDK where the page is initialized,The SDK supports both Senseless Captcha and normal Captcha. You need to apply for different captchaID on the official website, as follows:

          (void)viewDidLoad {
      	[super viewDidLoad]; 
      	// Sdk call
      	self.manager = [NTESVerifyCodeManager sharedInstance];
      	self.manager.delegate = self;
    
      	// Set transparency
      	self.manager.alpha = 0.7;
    
      	// Set frame
      	self.manager.frame = CGRectNull;
    
      	// captchaId applied from Netease,E.g. @"a05f036b70ab447b87cc788af9a60974"
    
      	// Normal captcha,icnclude Silde,Text click,icon click,SMS verification code
      	// NSString *captchaid = @"deecf3951a614b71b4b1502c072be1c1";
      	// self.manager.mode = NTESVerifyCodeNormal;
    
          // Senseless Captcha
          NSString *captchaid = @"6a5cab86b0eb4c309ccb61073c4ab672";
          self.manager.mode = NTESVerifyCodeBind;
      }
    
  • In the place where verification code verification is required, call the SDK's openVerifyCodeView interface as follows:

       [self.manager openVerifyCodeView:nil];
    
  • If you need to handle the callback information of the VerifyCode SDK, you can implementNTESVerifyCodeManagerDelegate.

    (1) initialization completed

      /**
      * Captcha component initialization completed
      */
      - (void)verifyCodeInitFinish{
      	// App add your own processing logic
      }
    

    (2) Initialization error

      /**
      * Captcha component initialization error
      *
      * @param error error message
      */
      - (void)verifyCodeInitFailed:(NSArray *)error{
      	// App add your own processing logic
      }
    

    (3) Verification result callback

      /**
      * Callback after verification is completed
      *
      * @param result Validation results BOOL:YES/NO
      * @param validate Secondary check data, if the verification result is `false`, `validate` returns empty
      * @param message Result message
      *
      */
      - (void)verifyCodeValidateFinish:(BOOL)result 
      							validate:(NSString *)validate 
      							message:(NSString *)message{
      	// App add your own processing logic
      }
    

    (4) The callback of turn off the captcha window

      /**
      * The callback of turn off the captcha window
      */
      - (void)verifyCodeCloseWindow{
      	//App add your own processing logic
      }
    

    (5) Network error

      /**
      * Network error
      *
      * @param error Network error message
      */
      - (void)verifyCodeNetError:(NSError *)error{
      	//App add your own processing logic
      }
    

    Remarks
    If you don't need to handle the callback information of the VerifyCode SDK, ignore it.

Swift Project

  • Introduce the header file in the bridging-header.h corresponding to the project, as follows:

      #import <VerifyCode/NTESVerifyCodeManager.h>
    

    Remark:
    Swift calls Objective-C to require a bridge connector file named <project name>-Bridging-Header.h. The role of the file is to provide a bridge for Swift to call Objective-Cobjects.

  • Other calls are the same as above

SDK interface

  • Enumerate

      /**
      * @abstract    Set the captcha language type
      */
      typedef NS_ENUM(NSInteger, NTESVerifyCodeLang) {
          // Chinese
          NTESVerifyCodeLangCN = 1,
          // Englishe
          NTESVerifyCodeLangEN,
          // Traditional chinese
          NTESVerifyCodeLangTW,
          // Japanese
          NTESVerifyCodeLangJP,
          // Korean
          NTESVerifyCodeLangKR,
          // Thai
          NTESVerifyCodeLangTL,
          // Vietnamese
          NTESVerifyCodeLangVT,
          // French
          NTESVerifyCodeLangFRA,
          // Russian
          NTESVerifyCodeLangRUS,
          // Arabic
          NTESVerifyCodeLangKSA,
          // German
          NTESVerifyCodeLangDE,
          // Italian
          NTESVerifyCodeLangIT,
          // Hebrew
          NTESVerifyCodeLangHE,
          // Hindi
          NTESVerifyCodeLangHI,
          // Indonesian
          NTESVerifyCodeLangID,
          // Burmese
          NTESVerifyCodeLangMY,
          // Laotian
          NTESVerifyCodeLangLO,
          // Malay
          NTESVerifyCodeLangMS,
          // Polish
          NTESVerifyCodeLangPL,
          // Portuguese
          NTESVerifyCodeLangPT,
          // Spanish
          NTESVerifyCodeLangES,
          // Turkish
          NTESVerifyCodeLangTR,
      };
    
      /**
      * @abstract    Set captcha type
      */
      typedef NS_ENUM(NSInteger, NTESVerifyCodeMode) {
          // Normal Captcha,include slide,Text click,Icon click,SMS verification code
          NTESVerifyCodeNormal = 1,
          // Senseless captcha
          NTESVerifyCodeBind,
      };
    
  • Attributes

       /**
        * @abstract    Captcha image display `frame`
        *
        * @Description   The location where the captcha control is displayed may not be passed.
        *              (1)If not passed or passed as` CGRectNull (CGRectZero)`, the default value is used: centered display of `topView`, width is 4/5 of screen width, height: view width / 2.0 + 65
        *              (2)If passed, the width of the frame is at least 270; the height is at least: width / 2.0 + 65.
        */
        @property(nonatomic) CGRect            frame;
    
	/**
 	* @abstract    Captcha image background transparency
	*
	* @Description   Range: 0~1, 0 means full transparency, 1 means opaque. Default: 0.8
	*/
	@property(nonatomic) CGFloat           alpha;
	/**
	 * @abstract    Captcha image background color
	 *
	 * @Description         Default:black
	 */
	@property(nonatomic) UIColor           *color;
  •   /**
       * @abstract    Captcha language type
       *
       * @Description   captcha language type NTESVerifyCodeLang, NTESVerifyCodeLangCN means Chinese, NTESVerifyCodeLangEN means English.
       *              Do not pass the default Chinese.
       */
       @property(nonatomic) NTESVerifyCodeLang    lang;
    
	/**
	* @abstract    Captcha slider icon url,If not, use the Netease default slider to display.
	*/
	@property(nonatomic) NSString *slideIconURL;
	/**
	 * @abstract    Set captcha type
	 *
	 * @Description   Captcha enumeration type NTESVerifyCodeMode, optional type see enumeration definition
	 *   Do not pass the default normal captcha.
	 *
	 */
	@property(nonatomic) NTESVerifyCodeMode mode;
  •   /**
       * @abstract    In extreme cases, when the captcha service is unavailable, whether to enable the downgrade scheme.
       * The default is on. When the downgrade switch is triggered, it will pass the verification directly and proceed to the next step.
       */
      @property(nonatomic) BOOL openFallBack;
    
	/**
	 * @abstract    Degradation is triggered when the first fallBackCount error occurs. Value range >=1
	 *              The default setting is 3 times. When an error occurs in the third server, the downgrade is triggered and the verification is passed directly.
	 */
	@property(nonatomic) NSUInteger fallBackCount;				
  • Single case
  •   /**
      *  @abstract 	Single case
      *
      *  @return 		return NTESVerifyCodeManager Object
      */
      + (NTESVerifyCodeManager *)sharedInstance;
    
  • Initialization
  •   /**
       *  @abstract   Configuration parameter
       *
       *  @param      captcha_id      captcha id
       *  @param      timeoutInterval The timeout period for loading the verification code, up to 12s. Try to set this time longer, such as 7 seconds or more (7-12s)
       *
       */
      - (void)configureVerifyCode:(NSString *)captcha_id
                  timeout:(NSTimeInterval)timeoutInterval;
    
  • Popup captcha

       /**
       *  @abstract Show captcha view
       *
       *  @Description      Placement:[[[UIApplication sharedApplication] delegate] window];Full screen centered display, width is 4/5 of the screen width, height: view width / 2.0 + 65.
       */
       - (void)openVerifyCodeView;
    
	/**
	*  @abstract   Show captcha view on specified view
	*
	*  @param      topView         Load the parent view of the captcha control, which can be nil。
	*                              (1)If the value is passed is nil,then use default value:[[[UIApplication sharedApplication] delegate] window]
	*                              (2)If the value is passed is not  nil,note the width and height of the topView, the width is at least 270; the height is at least: width / 2.0 + 65.
	*
 	*/
	- (void)openVerifyCodeView:(UIView *)topView;
  • log print

      /**
      *  @abstract	Whether to open sdk log printing
      *
      *  @param 		enabled 		YES:open ;NO:close
      *
      *  @Description The default is NO, only the `workflow` is printed; when set to YES, only the `workflow `and `BGRLogLevelError` will be printed under Release.		   
      */
      - (void)enableLog:(BOOL)enabled;
    

Effect demonstration

  • Initialization

  • Slide Captcha

Online Chat Tel:95163223