iOS Development Basics-Fragmentation 38

Source: Internet
Author: User

Application of 1:FCUUID Acquisition equipment identification

A: Author Githun address Https://github.com/fabiocaccamo/FCUUID

Because it also uses the author's other class Uickeychainstore address: Https://github.com/kishikawakatsumi/UICKeyChainStore

B: Add security.framework to the project

C: Import header file #import "FCUUID.h"

// each run of the app will change the + (NSString *) uuid; // changes each time (no persistent), but allows to keep in memory more temporary UUIDs+ (NSString *) Uuidforkey: (ID&L T nscopying>) key; // each run of the application will change the + (NSString *) uuidforsession; // re-install will change + (NSString *) uuidforinstallation; // Reload will change after unloading (NSString *) Uuidforvendor; // Erase the iphone will only change, suitable for a unique logo + (NSString *) Uuidfordevice;

2: Add a peripheral white border to the picture

-(uiimage*) Circleimage: (uiimage*) Image withparam: (cgfloat) inset {//Uigraphicsbeginimagecontext (image.size); //solve the problem of distortion bluruigraphicsbeginimagecontextwithoptions (Image.size, NO, [[UIScreen mainscreen] scale]); Cgcontextref Context=Uigraphicsgetcurrentcontext (); //the border width of the circle is 2 and the color is redcgcontextsetlinewidth (Context,2); Cgcontextsetstrokecolorwithcolor (context, [Uicolor Whitecolor].        Cgcolor); CGRect rect= CGRectMake (inset, inset, Image.size.width-inset *2.0f, Image.size.height-inset *2.0f);        Cgcontextaddellipseinrect (context, rect);        Cgcontextclip (context); //draw the image in the circle area[Image Drawinrect:rect];        Cgcontextaddellipseinrect (context, rect);        Cgcontextstrokepath (context); //generate a new imageUIImage*newimg =Uigraphicsgetimagefromcurrentimagecontext ();        Uigraphicsendimagecontext (); returnnewimg; }

Note: If you use Uigraphicsbeginimagecontext (image.size), it can cause the picture to be a bit distorted and blurry, using uigraphicsbeginimagecontextwithoptions ( Image.size, NO, [[UIScreen mainscreen] scale]) and if you draw a circle on a view, you can see it only if the view is not covered by other, such as if there is a background image, then it is not covered;

3: Package A uinavigation in the normal view controller

#pragmaMark adds a navigation bar-(void) addnavigationbar{//Create a navigation barUinavigationbar *navigationbar=[[uinavigationbar Alloc]initwithframe:cgrectmake (0,0, the, -+ -)]; //Navigationbar.tintcolor=[uicolor Whitecolor];[Self.view Addsubview:navigationbar]; //creating navigation control contentUinavigationitem *navigationitem=[[uinavigationitem Alloc]initwithtitle:@"Web Chat"]; //Add Login button to the leftUibarbuttonitem *loginbutton=[[uibarbuttonitem Alloc]initwithtitle:@"Login"Style:uibarbuttonitemstyledone target:self Action: @selector (login)]; Navigationitem.leftbarbuttonitem=Loginbutton; //add content to the navigation bar[Navigationbar Pushnavigationitem:navigationitem animated:no];}

4: The system comes with positioning coordinates to the city name

    //system comes with the positioning[[Mplocationmanager Shareinstance] startsystemlocationwithres:^ (cllocation *loction, NSError *error) {        if(!error) {Clgeocoder*geocoder=[[Clgeocoder alloc]init]; [Geocoder reversegeocodelocation:loction Completionhandler:^ (Nsarray<clplacemark *> * _nullable placemarks, Nserror *_nullable Error) {                if(placemarks.count>0) {Clplacemark*placemark=[placemarks Objectatindex:0]; //get the cityNSString *city =placemark.locality; if(!City ) {                        //the city information of the four municipalities can not be obtained by locality, but only by obtaining the province's method (if it is empty, it is known as the municipality)City =Placemark.administrativearea; }                    //there are differences before they change .                    if(![bbuserdefault.locationcity isequaltostring:city]) {bbuserdefault.locationcity=City ; } NSLog (@"current City: [%@]", city);        }            }]; } bbuserdefault.latiude=[nsstring stringWithFormat:@"%f", Loction.coordinate.latitude]; Bbuserdefault.longitude=[nsstring stringWithFormat:@"%f", Loction.coordinate.longitude]; NSLog (@"positioning information: [%f,%f]", Loction.coordinate.latitude,loction.coordinate.longitude); }];

Note:the code for the MPLocationManager.h class is as follows:

#import <Foundation/Foundation.h>void(^ksystemlocationblock) (Cllocation *loction, Nserror *error); @interface mplocationmanager:nsobject+ (id) shareinstance; /* * *   Start System location * *  /-(void) Startsystemlocationwithres: (Ksystemlocationblock) Systemlocationblock; @end
////MPLOCATIONMANAGER.M//Mobileproject////Created by Wujunyang on 16/1/15.//copyright©2016 year Wujunyang. All rights reserved.//#import"MPLocationManager.h"@interface Mplocationmanager ()<CLLocationManagerDelegate>@property (nonatomic, ReadWrite, strong) Cllocationmanager*Locationmanager, @property (nonatomic, ReadWrite, copy) Ksystemlocationblock ksystemlocationblock;@ End@implementation Mplocationmanager+(ID) shareinstance{StaticID helper =Nil; Staticdispatch_once_t Oncetoken; Dispatch_once (&oncetoken, ^{Helper=[[Mplocationmanager alloc] init];    }); returnHelper;}#pragmaMark-Apple/** * Apple system comes with map positioning*/- (void) Startsystemlocationwithres: (ksystemlocationblock) systemlocationblock{Self.ksystemlocationblock=Systemlocationblock; if(!Self.locationmanager) {Self.locationmanager=[[Cllocationmanager alloc] init]; Self.locationManager.desiredAccuracy=kcllocationaccuracybest; //self.locationmanager.distancefilter=10;        if([Uidevice Currentdevice].systemversion.floatvalue >=8) {[Self.locationmanager requestwheninuseauthorization];//allow access to location data in the course of the program (iOS8 positioning required)}} self.locationmanager.Delegate=Self ; [Self.locationmanager startupdatinglocation];//Turn on positioning}-(void) Locationmanager: (Cllocationmanager *) Manager didupdatelocations: (Nsarray *) locations{cllocation*currlocation=[Locations Lastobject]; Self.locationmanager.Delegate=Nil;        [Self.locationmanager stopupdatinglocation]; Self.ksystemlocationblock (currlocation, nil);}/** * location failed, callback this method*/-(void) Locationmanager: (Cllocationmanager *) Manager didfailwitherror: (Nserror *) error{if([Error code]==kclerrordenied) {NSLog (@"access is denied"); }    if([Error code]==Kclerrorlocationunknown) {NSLog (@"Unable to get location information"); } self.locationmanager.Delegate=Nil;        [Self.locationmanager stopupdatinglocation]; Self.ksystemlocationblock (nil, error);} @end

5: Initialization of some examples of init parameters

@implementation zocevent-(Instancetype) Initwithtitle: (NSString *) Title Date: (NSDate*) Date Location: (Cllocation*) location{ Self=[Super Init]; if(self) {_title=title; _date=date; _location=Location ; }    returnSelf ;}-(Instancetype) Initwithtitle: (NSString *) Title Date: (NSDate*) date{return[self initwithtitle:title date:date location:nil];}-(Instancetype) Initwithtitle: (NSString *) title{return[self initwithtitle:title date:[nsdate Date] location:nil];} @end

iOS Development Basics-Fragmentation 38

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.