Latest 1.0.1
Homepage https://github.com/tobedefined/TPreventUnrecognizedSEL
License MIT
Platforms ios 3.1, osx 10.6, tvos 9.0, watchos 1.0, requires ARC
Frameworks Foundation
Authors

TPreventUnrecognizedSEL
——

![platform](https://img.shields.io/badge/Platform-iOS%20%7C%20tvOS%20%7C%20macOS%20%7C%20watchOS-brightgreen.svg) 
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) 
[![CocoaPods](https://img.shields.io/badge/Cocoapods-compatible-brightgreen.svg?style=flat)](http://cocoapods.org/) 
[![Build Status](https://travis-ci.org/tobedefined/TPreventUnrecognizedSEL.svg?branch=master)](https://travis-ci.org/tobedefined/TPreventUnrecognizedSEL) 
[![License MIT](https://img.shields.io/badge/license-MIT-green.svg?style=flat)](https://github.com/tobedefined/TPreventUnrecognizedSEL/blob/master/LICENSE)

[中文文档](README_CN.md)

[Instructions and Principle](http://tbd.ink/2017/11/25/iOS/170112501.TPreventUnrecognizedSEL%E4%BD%BF%E7%94%A8%E6%96%B9%E6%B3%95%E4%BB%A5%E5%8F%8A%E5%AE%9E%E7%8E%B0%E5%8E%9F%E7%90%86/index/)

Features

  • Using runtime to dynamically add methods to prevent Unrecognized Selector errors prevents the app from crashing due to missing object and class methods.
  • Can get the specific information of the missing method, including:
    • The class name of the missing class method or object method;
    • The name of the missing method;
    • The missing object method or class method.

Installation

Source File

The source file contains two module directories: TPUSELFastForwarding and TPUSELNormalForwarding; Drag all the files inside the Sources folder in the corresponding module directory into you project.

Note: you can only use one of the modules to use, the module directory corresponding to all the files inside the Sources file can be dragged into the project.

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

To integrate TPreventUnrecognizedSEL into your Xcode project using CocoaPods, specify it in your Podfile:

pod 'TPreventUnrecognizedSEL/FastForwarding'

or this:

pod 'TPreventUnrecognizedSEL/NormalForwarding'

Then, run the following command:

$ pod install

Note: you can only use one of the subspec, NormalForwarding or FastForwarding
Use pod 'TPreventUnrecognizedSEL default is pod'TPreventUnrecognizedSEL/FastForwarding

Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate TPreventUnrecognizedSEL into your Xcode project using Carthage, specify it in your Cartfile:

github "tobedefined/TPreventUnrecognizedSEL"

Run carthage update to build the framework and drag the built TPUSELFastForwarding.framework or TPUSELNormalForwarding.framework into your Xcode project.

Note: You can only use one of the two frameworks, TPUSELFastForwarding.framework or TPUSELNormalForwarding.framework.

How to use

Simple Use

Import into the project without any action to take effect

Get Run error message

Import Header
Module and lang Import module mode Source File CocoaPods Carthage
TPUSELFastForwarding & ObjC #import "TPUSELFastForwarding.h" #import <TPreventUnrecognizedSEL/TPUSELFastForwarding.h> #import <TPUSELFastForwarding/TPUSELFastForwarding.h>
TPUSELFastForwarding & Swift add ⤴ in Bridging-Header import TPreventUnrecognizedSEL import TPUSELFastForwarding
TPUSELNormalForwarding & ObjC #import "TPUSELNormalForwarding.h" #import <TPreventUnrecognizedSEL/TPUSELNormalForwarding.h> #import <TPUSELNormalForwarding/TPUSELNormalForwarding.h>
TPUSELNormalForwarding & Swift add ⤴ in Bridging-Header import TPreventUnrecognizedSEL import TPUSELNormalForwarding
Set Block

In the main() function of the APP’s main.m file or in the APP’s didFinishLaunching method add the following code to get the specific information about the missing method:

[NSObject setHandleUnrecognizedSELErrorBlock:^(Class  _Nonnull __unsafe_unretained cls, SEL  _Nonnull selector, UnrecognizedMethodType methodType) {
    // DO SOMETHING
    // like upload to server or print log or others
}];
NSObject.setHandleUnrecognizedSELErrorBlock { (cls, selector, methodType) in
    // DO SOMETHING
    // like upload to server or print log or others
}

For some definitions: The following definitions and methods are in NSObject+TPUSELFastForwarding.h or NSObject+TPUSELNormalForwarding.h

typedef NS_ENUM(NSUInteger, UnrecognizedMethodType) {
    UnrecognizedMethodTypeClassMethod       = 1,
    UnrecognizedMethodTypeInstanceMethod    = 2,
};

typedef void (^ __nullable HandleUnrecognizedSELErrorBlock)(Class cls, SEL selector, UnrecognizedMethodType methodType);

@interface NSObject (TPUSELFastForwarding) // or (TPUSELNormalForwarding)

+ (void)setHandleUnrecognizedSELErrorBlock:(HandleUnrecognizedSELErrorBlock)handleBlock;

@end
  • cls: Class type; the Class of missing instance method or class method, NSStringFromClass(cls) can be used to return the NSString for the class name
  • selector: SEL type; the missing method name, NSStringFromSelector(selector) can be used to return the NSString for the method name
  • methodType: UnrecognizedMethodType type; for the missing method type (class method or object method)

Latest podspec

{
    "name": "TPreventUnrecognizedSEL",
    "version": "1.0.1",
    "summary": "TPreventUnrecognizedSEL unified the UIWebView and WKWebView",
    "description": "use TPreventUnrecognizedSEL can make you project prevent the unrecognized selector crashnyou just can use `FastForwarding` subspec **or**  use `NormalForwarding` subspec, you can not use both them at the same time.nin podfile `pod 'TPreventUnrecognizedSEL/FastForwarding'` to use `FastForwarding` subspecnin podfile `pod 'TPreventUnrecognizedSEL/NormalForwarding'` to use `NormalForwarding` subspecnremember, **JUST USE ONE OF THEM**ngithub : https://github.com/tobedefined/TPreventUnrecognizedSEL",
    "homepage": "https://github.com/tobedefined/TPreventUnrecognizedSEL",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "ToBeDefined": "[email protected]"
    },
    "social_media_url": "http://tbd.tech/",
    "source": {
        "git": "https://github.com/tobedefined/TPreventUnrecognizedSEL.git",
        "tag": "1.0.1"
    },
    "frameworks": "Foundation",
    "default_subspecs": "FastForwarding",
    "requires_arc": true,
    "platforms": {
        "ios": "3.1",
        "osx": "10.6",
        "tvos": "9.0",
        "watchos": "1.0"
    },
    "subspecs": [
        {
            "name": "FastForwarding",
            "public_header_files": "TPUSELFastForwarding/Sources/*.h",
            "source_files": "TPUSELFastForwarding/Sources/*.{h,m}"
        },
        {
            "name": "NormalForwarding",
            "private_header_files": "TPUSELNormalForwarding/Sources/*.h",
            "source_files": "TPUSELNormalForwarding/Sources/*.{h,m}"
        }
    ]
}

Pin It on Pinterest

Share This