Cocoa Pods framework

platform :ios, '7.0'

target 'store' do

pod 'AFNetworking'.'~ > 3.1.0'
pod 'JSONKit'.'~ > 1.5 pre'
pod 'MBProgressHUD'.'~ > 0.9.2'
pod 'SDWebImage'.'~ > 3.7.6'
pod 'SVPullToRefresh'.'~ > 0.4.1'
pod 'JTObjectMapping'.'~ > 1.1.2'
pod 'MagicalRecord'.'- >' 2.3.2
pod 'GetuiSDK'.'~ > 1.4.2'
pod 'XTSafeCollection'.'- >' 1.0.4
pod 'libWeChatSDK'.'~ > 1.6.2'
pod 'XMLDictionary'.'~ > 1.4'
pod 'Masonry'.'~ > 1.0.0'
pod 'OpenUDID'.'~ > 1.0.0'
pod 'SAMKeychain'.'~ > 1.5.0
pod 'iVersion'.'~ > 1.11.4'
pod 'iCloudDocumentSync'.'~ > 7.4.1'

end
Copy the code

Second, NSInteger printing and string conversion

Use %zd to print NSInteger and %tu to print NSUInteger.

NSInteger integer = 1;
NSLog(@"first number: %zd".integer);

NSUInteger uinteger = 1;
NSLog(@"second number: %tu", uinteger);
Copy the code

In iOS7, Autolayout is used for UIScrollView

- (void)viewDidLayoutSubviews
{
     [_mainScrollView setContentSize:CGSizeMake(SCREEN_WIDTH, SCREEN_HEIGHT + 10)]; // Add 10 pixels for scrollView to slide up and down}Copy the code

Add the content height of the scrollView.

Iv. APP package slimming

1. Delete images that are not used in the project.Find images that are not used in XCode projects
2. Delete classes and XIBs and storyboards that are not used in the project.Class is not used in analysis projects

Sudo gem install fui -n /usr/local/bin

fui usage: github.com/dblock/fui

Go to the project directory and run the fui find command to find all unused class files.

3. Analyze ipA packages to find files or contents larger than 500K
 find . -type f -size +500000c | xargs ls -lh
Copy the code

Five, direct iOS7 continuous jump

- (void)back
{
    [self dismissViewControllerAnimated:YES
                             completion:^{
                                 if(self.loginCanceled) { self.loginCanceled(); self.loginCanceled = nil; }}]; }Copy the code

An implementation of loginCanceled

[weakSelf.navigationController popViewControllerAnimated:YES];

6. Remove the Preferred Max warning

Reasons for warning:

  1. Xib or storyboard controls that add UILabel
  2. UILabel’s number lines are greater than 1
  3. UILabel preferred Max has no set value (@property(nonatomic) CGFloat preferredMaxLayoutWidth NS_AVAILABLE_IOS(6_0);)

Solutions:

  1. If it’s a Storyboard, right click on the warning
  2. View the details of the warning

  1. Set preferred Width to 0 and select Explicit
  2. Warning to solve

If the warning is for Xib, click warning directly

Cocoa Pods update to 1.0 no longer works

Errno::ENOTEMPTY -directory not empty @dir_s_rmdir – /Users/ arthurWang /SVN// */Pods

[!] Oh no, an error occurred. The Search for existing lot issues similar to yours:github.com/CocoaPods/C… None exists, create a ticket, have the template displayed above, on:github.com/CocoaPods/C… Sure to first read the contributing guide for details on how to properly submit a ticket:github.com/CocoaPods/C… Don’t forget to anonymize any private data!

Solutions:

Remove the Pods folder from the project and install Pod Install

Eight, interactivepopgesturerecognizer use

After setting the left bar button, the effect returned by right swipe will be invalid.

In order to get to right slip returned event at the same time, you can perform [self. NavigationController. InteractivePopGestureRecognizer addTarget: self action: @ the selector (back)];

** added in ViewController viewDidAppare, removed in viewWillDisappear. **

Update the code on Cocoapods

1. Use private Cocoapods to manage code, which needs to be added

pod repo add HXSpec [email protected]:ios/HXSpecs.git

Add the private Spec management Git to pod specs. To make it easier to update private libraries.

2. If you want to update your code on GitHut while using Cocoapods to manage your code, you need to execute Pod Install in project to refresh your codeDelete the Pods and Podfile.lock files

Then execute Pod Install to refresh the code

Update the REPO with POD Update (update the private library)

3. Multiple pod installs will result in multiple Check Pods manifest.Lock options in Build Phase, which can be removed.

If you place the specs file directly into the HXSpecs repository, then you need to execute pod Update for Updating local Specs repositories or an error will be reported

4. Delete the cache files in the directory and obtain the third-party library files again

/Users/arthurwang/Library/Caches/CocoaPods/Pods

5. An error occurs when two components depend on each other:

[!] There is a circular dependency between StoreLocation and StoreBase

UICollectionView data is not enough to slide — solution

No matter how much data is in a tableView, its interface is sliding by default. Compared to a tableView, when the collectionView has less data than a screen, it can’t slide. Solution:

_collectionView.alwaysBounceVertical = YES;
Copy the code

Set it to always slide vertically.

MLeaksFinder checks for memory leaks

MLeaksFinder can be imported directly with Pod. Check for memory leaks according to the DEBUG macro, and assert if a memory leak is found. So Good

Delete String from Chinese

Delete the characters that do not need to be retained

// Numbers and letters#define ALPHANUM @"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"/ / digital#define NUM @"0123456789"

NSCharacterSet *cs = [[NSCharacterSet characterSetWithCharactersInString:ALPHANUM] invertedSet];
NSString *filteredStr = [[textStr componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""];
Copy the code

Also: UITextField can only enter numbers and letters

[[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(textFieldChanged:)
                                                 name:UITextFieldTextDidChangeNotification
                                               object:nil];
Copy the code

Monitor name: UITextFieldTextDidChangeNotification and – (BOOL) textField: (textField UITextField at *) shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string

Use it together to achieve.

- (BOOL)validatePasswordString:(NSString *)resultMStr
{
    BOOL result = YES;
    switch (self.mode) {
        case HXSChangePasswordLogin: {
            NSString *regex = @"^[a-zA-Z0-9]+$";
            NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
            result = [pred evaluateWithObject:resultMStr];
            break;
        }
            
        case HXSChangePasswordPay: {
            NSString *regex = @"^ [0-9] + $";
            NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
            result = [pred evaluateWithObject:resultMStr];
            break; }}return result;
}
Copy the code

After iOS8, use WKWebView instead of UIWebView

IOS8 before the use of UIWebView HTML display, UIWebView has a large memory does not release the problem.

WKWebView solves the memory footprint problem.

Xib UILabel newline

When you Enter a long text in the Xib and need to wrap a line according to the number, press Enter does not work.

Method: Write the Text in the Text editing tool and copy it to UILabel. I have a newline

15, Workspace — project — targets explain

A workspace can contain multiple projects, and a project can contain multiple targets (artifacts).

In a project, different compilation Settings can be performed depending on the type of targets being run. Project is the base parent and targets is a subclass. The targets setting overrides the project setting.

DrawRect: drawRect: drawRect: drawRect: drawRect: drawRect

[yourView.layer setBorderWidth: 5.0]; [yourView.layersetBorderColor:
[[UIColor colorWithPatternImage:[UIImage imageNamed:@"DotedImage.png"]] CGColor]]; //just add image name and create image with dashed or doted drawing and add hereCopy the code

Here you just need to add the QuartzCore/ quartzcore.h framework and import the.m file as follows:

#import <QuartzCore/QuartzCore.h>
Copy the code

Note: When using Autolayout, draw dashed lines according to frame, then in

- (void)drawRect:(CGRect)rect
{
    [self drawBorderLayer];
}
Copy the code

In the drawRect method, draw.

Deep copy of Array

DataArray3 =[dataArray2 mutableCopy]; The knowledge makes a deep copy of dataArray2, and the contents of the array are just copies of Pointers.

DataArray3 =[[NSMutableArray alloc]initWithArray:dataArray2 copyItems:YES]; DataArray2 makes a deep copy of itself and its content. Alone is just the first layer of content

Deep copy completely dataArray3 = [NSKeyedUnarchiver unarchiveObjectWithData: [NSKeyedArchiver archivedDataWithRootObject: dataArray2]]. No matter how many layers can be deeply copied

Enterprise certificate download version can be directly opened in the APP

There is a page of H5 in the APP, which can be directly clicked to download other applications

19. Handle # in URL

NSString *str = @"Http://test.fd.com/#/dte {} | | |? LSFJ = 12 & SDLFJ = 34 & hao = how are you";       
NSURL *url = [NSURL URLWithString:[str stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet characterSetWithCharactersInString:@"` % ^ {} \" [] | \ \ < >"].invertedSet]];
       
NSLog(@"url is %@", url);
Copy the code

Output: test.fd.com/#/dte {} | | |?…

# are not escape iOS9 version you need to use the * * * * stringByAddingPercentEncodingWithAllowedCharacters instead of before StringByAddingPercentEscapesUsingEncoding.

NSString *str = @"Http://test.fd.com/#/dte {} | | |? LSFJ = 12 & SDLFJ = 34 & hao = how are you";       
NSURL *url = [NSURL URLWithString:[str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSLog(@"[url scheme] is %@.", [url scheme]);
NSLog(@"[url host] is %@.", [url host]);
NSLog(@"[url password] is %@.", [url password]);
NSLog(@"[url user] is %@.", [url user]);
NSLog(@"[url path] is %@.", [url path]);
NSLog(@"[url query] is %@.", [url query]);
NSLog(@"[url fragment] is %@.", [url fragment]);
NSLog(@"[url resourceSpecifier] is %@.", [url resourceSpecifier]);
NSLog(@"[url parameterString] is %@.", [url parameterString]);
NSLog(@"[url relativePath] is %@.", [url relativePath]);
Copy the code

Output: 2016-08-09 18:57:52.913 store[20150/672790] [url scheme] is HTTP. 2016-08-09 18:57:52.913 store[20150/672790] [url scheme] is HTTP. 2016-08-09 18:57:52.913 store[20150/672790 2016-08-09 18:57:52.914 store[20150:672790] [URL password] is (null).2016-08-09 18:57:52.914 Store [20150-672790] [user] url is (null). The 2016-08-09 18:57:52. 914 store [20150:672790] [url path] is / # / dte {} | | |. 2016-08-09 18:57:52.914 store[20150:672790] [URL query] is LSFJ =12&sdlfj=34&hao=%E4%BD%A0%E5%A5% BD.2016-08-09 [url query] is LSFJ =12&sdlfj=34&hao=%E4%BD%A0%E5%A5% BD.2016-08-09 18:57:52.914 store[20150:672790] [URL fragment] is (null). 2016-08-09 18:57:52.915 store[20150:672790] [URL fragment] is (null). 2016-08-09 18:57:52.915 store[20150:672790] [URL fragment] is (null) Is / / test.fd.com/%23/dte resourceSpecifier] {} | | |? LSFJ = 12 & SDLFJ = 34 & hao = how are you. The 2016-08-09 18:57:52. 915 store (20150-672790) [url parameterString] is (null). 2016-08-09 18:57:52. 915 store [20150-672790] [url relativePath] is / # / dte {} | | |.

20. The APP startup page is not updated

Launchscreen.xib works fine on the emulator but not on the real machine.

Cause: Application cache

Solution:

Delete the APP on the real phone, restart the phone, and reinstall the APP.

21. Use HTTPSDNS

Apply for the Account ID to download the SDK

Check the SDK documentation for initialization and replace the domain name with IP

Help.aliyun.com/document_de…

Configure the domain name in Aliyun

Display nil for variables that cannot be printed

Always return nil when debugging a variable and printing its value. But the interface can display content.

The reason:

Indicates that the variable is in a thread and the debugger is not in the thread.

23, judge whether it is the correct posture of GIF/PNG pictures

- (NSString *)contentTypeForImageData:(NSData *) Data {uint8_t c; [data getBytes:&c length:1]; switch (c) {case 0xFF:
            return @"jpeg";
        
        case 0x89:
            return @"png";
        
        case 0x47:
            return @"gif";
        
        case 0x49:
        case 0x4D:
            return @"tiff";
        
        case 0x52:
        if ([data length] < 12) {
            return nil;
        }
        
        NSString *testString = [[NSString alloc] initWithData:[data subdataWithRange:NSMakeRange(0, 12)] encoding:NSASCIIStringEncoding];
        if ([testString hasPrefix:@"RIFF"]
            && [testString hasSuffix:@"WEBP"])
        {
            return @"webp";
        }
            
        return nil;
    }
    
    return nil;
}
Copy the code

In fact, the first byte of image data is fixed, the first byte of a type of image is its identifier, let’s call this method:

// Suppose this is a network-fetched URL NSString *path = @"http://pic.rpgsky.net/images/2016/07/26/3508cde5f0d29243c7d2ecbd6b9a30f1.png"; NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:path]]; / / call get photo extension nsstrings * string = [self contentTypeForImageData: data]; // PNG NSLog(@"% @",string);
Copy the code

Xxiv. JSPatch convertor tool use

On the left side of the input

@implementation HXSAdTableViewCell
+ (CGFloat)getCellHeightWithObject:(HXSStoreAppEntryEntity *)storeAppEntryEntity
{
    CGFloat scale = [storeAppEntryEntity.imageHeightIntNum floatValue]/[storeAppEntryEntity.imageWidthIntNum floatValue];
    
    return ([UIScreen mainScreen].bounds.size.width) / 3 * scale + 30;
}
@end
Copy the code

On the right side of the output

require('UIScreen');
defineClass('HXSAdTableViewCell', {} {
getCellHeightWithObject: function(storeAppEntryEntity) {
    var scale = storeAppEntryEntity.imageHeightIntNum().floatValue() / storeAppEntryEntity.imageWidthIntNum().floatValue();
    
    return(UIScreen.mainScreen().bounds().size().width()) / 3 * scale + 30; }});Copy the code

There is a BUG: ** defineClass(‘HXSAdTableViewCell’, {} {** missing a ** “after {},” **.

Correct:

require('UIScreen');
defineClass('HXSAdTableViewCell', {}, {
getCellHeightWithObject: function(storeAppEntryEntity) {
    var scale = storeAppEntryEntity.imageHeightIntNum() / storeAppEntryEntity.imageWidthIntNum();
    
    return(UIScreen.mainScreen().bounds().width) / 3 * scale + 30; }});Copy the code

Navigation bar left bar button jump

- (void)jumpToViewController:(UIViewController *)vc
{
    // show the navigation bar in other vcs
    [self.navigationController setNavigationBarHidden:NO];
    
    [self.navigationController pushViewController:vc animated:YES];
}
Copy the code

When set up the self. The navigationItem. LeftBarButtonItem. ImageInsets = self. NavigationController. ViewControllers. Count = = 1? UIEdgeInsetsZero : UIEdgeInsetsMake(0, -5, 0, 5);

So when displaying navigation bar, the left bar button will jump.

This can be resolved by setting the Navigation bar hidden before the push.

Usystem: com.apple.UIKit, category: HIDEventFiltered… The log

Solutions: [product] – [scheme] – [Edit scheme] – [Run] – [Argument] – [Environment Variable] OS_ACTIVITY_MODE disable

The intrinsic size of two uilabels of variable length in one row

Content Hugging Priority represents the Priority at which the control rejects stretching. The higher the priority, the less easily the control will be stretched.

The Content Compression Resistance Priority below represents the Priority at which the control refuses to compress the built-in space. The higher the priority, the less easily the control’s built-in space can be compressed

Setting Content Hugging Priority and Content Compression Resistance Priority enables which label to compress and which to display completely when the contents of both UILabel s are very long.

28. Pusher push test

Github.com/noodlewerk/…

Test push directly. 👍 👍 👍

29, Float precision solution

Accuracy distortion when converting NSNumber to CGFloat.

NSString *decimalNumberMutiplyWithString(NSString *multiplierValue,NSString *multiplicandValue)
{
    NSDecimalNumber *multiplierNumber = [NSDecimalNumber decimalNumberWithString:multiplierValue];
    NSDecimalNumber *multiplicandNumber = [NSDecimalNumber decimalNumberWithString:multiplicandValue];
    NSDecimalNumber *product = [multiplicandNumber decimalNumberByMultiplyingBy:multiplierNumber];
    return [product stringValue];
}

NSLog(@"% @",decimalNumberMutiplyWithString([NSString stringWithFormat:@"%f",a], [NSString stringWithFormat:@"%d",b])); // The output is 999999.99Copy the code

By counting each digit, the string is displayed.

- (NSString *)convertStringFromFloatNum:(NSNumber *)floatNum
{
    NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
    [numberFormatter setPositiveFormat:@"0.00"];
    NSString *tempFloatStr = [numberFormatter stringFromNumber:[NSNumber numberWithDouble:([floatNum floatValue] * 100)]];  // yuan to fen
    
    NSInteger tempInt = [tempFloatStr integerValue];
    
    NSInteger result = tempInt % 100;
    if (0 == result) {
        NSString *str = [NSString stringWithFormat:@"%zd", tempInt/100];
        
        return str;
    }
    
    result = tempInt % 10;
    if (0 == result) {
        NSString *str = [NSString stringWithFormat:@"%zd.%zd", tempInt/100, (tempInt % 100)/10];
        
        return str;
    }
    
    NSString *str = [NSString stringWithFormat:@"%zd.%zd%zd", tempInt/100, (tempInt % 100)/10, (tempInt % 100)%10];
    
    return str;
}
Copy the code

Thirty, push iOS10 changes

In iOS 10, the priority of the “loc-key” and “body” fields has changed. In iOS 10, the priority of “body” is higher than that of “loc-key”. In iOS 10, the priority of “loc-key” is higher than that of “body”. Using “body” to pass data is not recommended

If you put the data in Message (body) in payload, and the data in loc-key in Message (body), you don’t have any display code in iOS 10

31. The default frame in iOS10

<UIImageView: 0x7f9b91560f50; frame = (0 0; 1000, 1000); clipsToBounds = YES; autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0x6000000366e0>

32, Tencent mobile phone butler harassment interception database update failure

Harassment interception function, database update, if the English environment, will always appear database update failure, switch to the Chinese environment, a one-time success.

// How quickly TODO finds the knowledge obsolete!