当我在 iPhone 中运行我的应用程序进行测试时,SIM和WiFi网络一次又一次地连接和断开连接。
但是在正常情况下并运行其他应用程序它工作正常吗?
我在我的应用程序中使用 GPS 和地图服务。
1)代码问题?
2) iPhone 有问题?
3)其他?
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
#import <MapKit/MapKit.h>
@interface MainViewController : UIViewController<CLLocationManagerDelegate,
MKMapViewDelegate>
@property (strong, nonatomic) IBOutlet UIView *mapView;
@property (strong, nonatomic) CLLocationManager *locationManager;
@property (strong, nonatomic) IBOutlet MKMapView *mkMap;
@property (strong, nonatomic) CLLocation *myCurrentLocation;
- (IBAction)mapView:(id)sender;
- (IBAction)mapToMain:(id)sender;
@end
#import "MainViewController.h"
#import <MapKit/MapKit.h>
@interface MainViewController ()
@end
@implementation MainViewController
@synthesize mapView;
@synthesize mkMap;
@synthesize myCurrentLocation;
@synthesize locationManager;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
//start core location services
if(self.locationManager == nil)
{
locationManager=[[CLLocationManager alloc] init];
}
locationManager.delegate=self;
locationManager.desiredAccuracy=kCLLocationAccuracyBestForNavigation;
[locationManager startUpdatingLocation];
mkMap.showsUserLocation=YES;
myCurrentLocation=mkMap.userLocation.location;
}
#pragma mark- core location delgate method
-(void) locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
NSLog(@"locationUpdated");
NSLog(@"%@",[locations lastObject]);
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)mapView:(id)sender {
[self.view addSubview:mapView];
}
- (IBAction)mapToMain:(id)sender {
[mapView removeFromSuperview];
}
@end