IOS Development Basics - Fragment 11

12502 단어 ios development
1: AFNetwork judges the network status

#import “AFNetworkActivityIndicatorManager.h"

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // 
    [[AFNetworkActivityIndicatorManager sharedManager] setEnabled:YES];
    [[AFNetworkReachabilityManager sharedManager] startMonitoring];
    // 
    [[AFNetworkReachabilityManager sharedManager] setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        switch (status) {
            case AFNetworkReachabilityStatusNotReachable:{
                [self showMBPHudTipStr:@" "];
                break;
            }
            case AFNetworkReachabilityStatusReachableViaWiFi:{
                [LogUtil logUtilstring:@"WiFi "];
                break;
            }
            case AFNetworkReachabilityStatusReachableViaWWAN:{
                [self showMBPHudTipStr:@" "];
                break;
            }
            default:
                break;
        }
    }];

   
    return YES;
}
2: UIButton countdown

 uibutton ;

-(void)startTime{
    __block int timeout=60; // 
    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    dispatch_source_t _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,queue);
    dispatch_source_set_timer(_timer,dispatch_walltime(NULL, 0),1.0*NSEC_PER_SEC, 0); // 
    dispatch_source_set_event_handler(_timer, ^{
        if(timeout<=0){ //
            dispatch_source_cancel(_timer);
            dispatch_async(dispatch_get_main_queue(), ^{
                //   
                [self.againBtn setTitle:@" " forState:UIControlStateNormal];
                self.againBtn.userInteractionEnabled = YES;
                self.labNoMessage.text=@"";
                self.labNoMessage.textColor=[UIColor redColor];
            });
        }else{
            int seconds = timeout % 60;
            NSString *strTime = [NSString stringWithFormat:@"%.2d", seconds];
            dispatch_async(dispatch_get_main_queue(), ^{
                //   
                [self.againBtn setTitle:[NSString stringWithFormat:@" (%@)",strTime] forState:UIControlStateNormal];
                self.againBtn.userInteractionEnabled = NO;
                self.labNoMessage.text=@" ";
                self.labNoMessage.textColor=[UIColor colorWithHexString:@"84BF20"];
                
            });
            timeout--;
            
        }
    });
    dispatch_resume(_timer);
    
}
3: Judge the iphone device

#define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define IS_RETINA ([[UIScreen mainScreen] scale] >= 2.0)

#define SCREEN_WIDTH ([[UIScreen mainScreen] bounds].size.width)
#define SCREEN_HEIGHT ([[UIScreen mainScreen] bounds].size.height)
#define SCREEN_MAX_LENGTH (MAX(SCREEN_WIDTH, SCREEN_HEIGHT))
#define SCREEN_MIN_LENGTH (MIN(SCREEN_WIDTH, SCREEN_HEIGHT))

#define IS_IPHONE_4_OR_LESS (IS_IPHONE && SCREEN_MAX_LENGTH < 568.0)
#define IS_IPHONE_5 (IS_IPHONE && SCREEN_MAX_LENGTH == 568.0)
#define IS_IPHONE_6 (IS_IPHONE && SCREEN_MAX_LENGTH == 667.0)
#define IS_IPHONE_6P (IS_IPHONE && SCREEN_MAX_LENGTH == 736.0)
4: An automatic layout bug is reported below IOS8, but it can run normally in IOS8

 APP ,BUG :
Terminating app due to uncaught exception ‘NSInternalInconsistencyException’, reason: ‘Auto Layout still required after executing -layoutSubviews.
UITableView’s implementation of -layoutSubviews needs to call super.’ - (void)layoutSubviews { // super layoutSubviews [self _updateConstraints]; [super layoutSubviews]; }
5: Interact with JS, and make the JS code compatible with android and IOS

JS :

$(function () {
    var u = navigator.userAgent, app = navigator.appVersion;
    var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1; //android uc 
    var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios 

    if (isAndroid) {
        $('#btn_Success').attr('href', 'javascript:mailActive.backHome()');
    }
    else if (isiOS) {
        $('#btn_Success').attr('href', 'protoclo://backHome');
    }
});

 IOS shouldStartLoadWithRequest:

-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    NSString *newURL=[[request URL] absoluteString];
    if([newURL hasPrefix:@"protoclo://"])
    {
        NSArray *stringArray=[newURL componentsSeparatedByString:@"//"];
        if (stringArray.count>1&&[[stringArray objectAtIndex:1] isEqualToString:@"backHome"]) {
            [self webJavascriptBackHome];
        }
    }
    return YES;
}

 : IOS JS WebViewJavascriptBridge; IOS webView Safari , , ->ios simulator  (Safari-> - - “ ”);

좋은 웹페이지 즐겨찾기