由于它写的很糟糕,我的应用程序在它启动后立即崩溃。我真的不知道该怎么做。谢谢你的帮助。这是代码:
#import "ViewController.h"
@import CoreLocation;
@interface ViewController () <CLLocationManagerDelegate>
@property (strong, nonatomic) CLLocationManager *locationManager;
@property (weak, nonatomic) IBOutlet UILabel *location;
@property (weak, nonatomic) IBOutlet UILabel *date;
@end
@implementation ViewController
-(void)viewDidLoad
{
[super viewDidLoad];
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
[self.locationManager requestWhenInUseAuthorization];
}
[self.locationManager startUpdatingLocation];
//date
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"MMMM d, YYYY"];
NSString *dateString = [dateFormatter stringFromDate:[NSDate date]];
NSLog(@"%@", dateString);
self.date.text = (@"%@", dateString);
}
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
NSLog(@"%@", [locations lastObject]);
self.location.text = (@"%@", [locations lastObject]);
}
@end
答案 0 :(得分:0)
您的代码不完整可以查看并再次发布
你有
@selector(requestWhenInUseAuthorization)
并且您尚未设置功能requestWhenInUseAuthorization
在哪种方法中,您将此代码放在下面。您已将其放在viewDidLoad下面,但它不在任何方法内。正确检查您的代码
[self.locationManager startUpdatingLocation];
//date
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"MMMM d, YYYY"];
NSString *dateString = [dateFormatter stringFromDate:[NSDate date]];
NSLog(@"%@", dateString);
self.date.text = (@"%@", dateString);
}
答案 1 :(得分:0)
在您的应用中应用异常断点,然后重试。它会告诉您崩溃的确切位置