#import "ViewController.h"
#import <CoreLocation/CoreLocation.h>
@interface Viewcontroller () <cllocationmanagerdelegate>
@property(nonatomic,strong)Cllocationmanager*manager;
@property (weak, nonatomic) iboutlet uiimageview *imagew;
@end
@implementation Viewcontroller
-(Cllocationmanager*) Manager
{
if (_manager= =Nil) {
_manager=[[cllocationmanager alloc]init];
}
return _manager;
}
-(void) viewdidload {
[Super viewdidload];
self. Manager. Delegate=self;
// judge iOS7 or 8
if([[uidevice currentdevice]. Systemversion doublevalue]>8.0)
{
//[self.manager requestwheninuseauthorization];
[self. Manager requestalwaysauthorization];
}
[self. Manager stopupdatingheading];
}
-(void) Locationmanager: (cllocationmanager *) Manager didupdateheading: (clheading *) Newheading
{
cgfloat angle=newheading. Magneticheading*m_pi/;
// rotate picture
self. Imagew. Transform =cgaffinetransformmakerotation(-angle);
}
@end
Customizing the Compass Implementation