Basic knowledge of IOS development-fragment 11, basic knowledge of ios-Fragment

Source: Internet
Author: User

Basic knowledge of IOS development-fragment 11, basic knowledge of ios-Fragment

1: AFNetwork determines the network status

# Import "AFNetworkActivityIndicatorManager. h "-(BOOL) application :( UIApplication *) application syntax :( NSDictionary *) launchOptions {// network [[sharesharedmanager] setEnabled: YES]; [[AFNetworkReachabilityManager sharedManager] startMonitoring]; // network status judgment [[AFNetworkReachabilityManager sharedManager] statuses: ^ (AFNetworkReachabilityStatus status) {switch (status) {case when: {[self showMBPHudTipStr: @ "No network connection currently"]; break;} case AFNetworkReachabilityStatusReachableViaWiFi: {[LogUtil logUtilstring: @ "WiFi network"]; break;} case when: {[self showMBPHudTipStr: @ "wireless network"]; break ;} default: break ;}}]; return YES ;}

2: UIButton countdown

When the countdown uibutton cannot be responded to the event;-(void) startTime {_ block int timeout = 60; // The countdown time dispatch_queue_t queue = dispatch_get_global_queue (expiration, 0 ); dispatch_source_t _ timer = dispatch_source_create (hour, 0, 0, queue); hour (_ timer, dispatch_walltime (NULL, 0), 1.0 * NSEC_PER_SEC, 0 ); // execute dispatch_source_set_event_handler (_ timer, ^ {if (timeout <= 0 ){/ /When the countdown ends, disable dispatch_source_cancel (_ timer); dispatch_async (dispatch_get_main_queue (); ^ {// you can set self according to your needs. againBtn setTitle: @ "resend verification code" forState: UIControlStateNormal]; self. againBtn. userInteractionEnabled = YES; self. labNoMessage. text = @ "didn't you receive the verification code? "; Self. labNoMessage. textColor = [UIColor redColor] ;}) ;}else {int seconds = timeout % 60; NSString * strTime = [NSString stringWithFormat: @ "%. 2d ", seconds]; dispatch_async (dispatch_get_main_queue (), ^ {// set the interface button to set [self. againBtn setTitle: [NSString stringWithFormat: @ "resend activation email (% @)", strTime] forState: UIControlStateNormal]; self. againBtn. userInteractionEnabled = NO; self. labNoMessage. text = @ "successful email activation"; self. labNoMessage. textColor = [UIColor colorWithHexString: @ "84BF20"] ;}); timeout -- ;}}); dispatch_resume (_ timer );}

3: Determine 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, while IOS8 works normally.

The APP will be suspended. BUG content: 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 {// The automatically layout content is placed before super layoutSubviews [self _ updateConstraints]; [super layoutSubviews];}

5: interact with JS and make JS Code compatible with android and IOS

JS Code: $ (function () {var u = navigator. userAgent, app = navigator. appVersion; var isAndroid = u. indexOf ('android')>-1 | u. indexOf ('linux ')>-1; // android terminal or uc browser var isiOS = !! U. match (/\ (I [^;] +; (U ;)? CPU. + Mac OS X/); // ios terminal if (isAndroid) {$ ('# btn_Success '). attr ('href ', 'javascript: mailActive. backHome () ');} else if (isiOS) {$ (' # btn_Success '). attr ('href ', 'protoclo: // backhome') ;}}); While IOS is 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] isdomaintostring: @ "backHome"]) {[self webJavascriptBackHome] ;}} return YES;} note: it is better to use WebViewJavascriptBridge, a third-party plug-in for JS interaction in IOS. You can use Safari to debug embedded webView during IOS development and debugging. It can set the development mode menu, developers-> ios simulator can view the running details of web pages (Safari-> preference settings-advanced-show "development" in the menu ");

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.