-

- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {

// Override point for customization after application launch.

_window= [[UIWindowalloc]initWithFrame:[UIScreenmainScreen].bounds];

_window.backgroundColor= [UIColorwhiteColor];

[_windowmakeKeyAndVisible];

ScrollContentViewController* scrollcontentView = [[ScrollContentViewControlleralloc]init];

UINavigationController* navigationController = [[UINavigationControlleralloc]initWithRootViewController:scrollcontentView];

_window.rootViewController= navigationController;

UIView* statusBarView = [[UIViewalloc]initWithFrame:CGRectMake(0, -20,320,64)];

statusBarView.backgroundColor= [UIColorcolorWithRed:0green:122/255.0fblue:247/255.0falpha:1];

[navigationController.navigationBaraddSubview:statusBarView];


[applicationsetStatusBarHidden:NO];

[applicationsetStatusBarStyle:UIStatusBarStyleLightContent];

//注册推送(ios 8)

if([UIApplicationinstancesRespondToSelector:@selector(registerUserNotificationSettings:)])

{

[[UIApplicationsharedApplication]registerUserNotificationSettings:[UIUserNotificationSettingssettingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSoundcategories:nil]];

}


returnYES;


}

-(void)application:(UIApplication*)application didReceiveLocalNotification:(UILocalNotification*)notification

{

//接受本地推送

NSLog(@"%@",notification);

UIAlertView*alert = [[UIAlertViewalloc]initWithTitle:@"iWeibo"message:notification.alertBodydelegate:nilcancelButtonTitle:@"确定"otherButtonTitles:nil];

[alertshow];

//图标上的数字减1

application.applicationIconBadgeNumber-=1;

//解除本地推送

//获得uiapplication

UIApplication* app = [UIApplicationsharedApplication];

//获取本地推送数组

NSArray* localArray = [appscheduledLocalNotifications];

//声明本体通知对象

UILocalNotification* localNotification;

if(localArray)

{

for(UILocalNotification* notiin localArray)

{

NSDictionary* dict = noti.userInfo;

if(dict)

{

NSString* inKey = [dictobjectForKey:@"key"];

if([inKeyisEqualToString:@"对应的key值"])

{

if(localNotification)

{

localNotification =nil;

}

break;

}

}

}

//判断是否找到已经存在的相同key的推送

if(!localNotification)

{

//不存在初始化

localNotification = [[UILocalNotificationalloc]init];

}

if(localNotification)

{

//不推送 取消推送

[appcancelLocalNotification:localNotification];

return;

}

}


}


.....

- (void)viewDidLoad{.....}

-(void)SendNotification:(UIButton*)sender

{//创建本地推送

NSDate* now = [NSDatedate];

UILocalNotification* reminderNotification = [[UILocalNotificationalloc]init];

//设置推送时间

[reminderNotificationsetFireDate:[nowdateByAddingTimeInterval:10]];

//设置时区

[reminderNotificationsetTimeZone:[NSTimeZonedefaultTimeZone]];

//设置userinfo 方便在之后需要撤销的时候使用

reminderNotification.userInfo= [NSDictionarydictionaryWithObject:@"name"forKey:@"key"];

//设置推送内容

[reminderNotificationsetAlertBody:@"Don't forget to Show Out !"];

[reminderNotificationsetAlertAction:@"Show Out"];

[reminderNotificationsetCategory:@"alert"];

//设置推送声音

[reminderNotificationsetSoundName:UILocalNotificationDefaultSoundName];

//显示在icon上的红色圈子的数子

[reminderNotificationsetApplicationIconBadgeNumber:1];

//添加推送到UIApplication

[[UIApplicationsharedApplication]scheduleLocalNotification:reminderNotification];

NSLog(@"currentUserNotificationSettings = %@",[[UIApplicationsharedApplication]currentUserNotificationSettings]);

[[UIApplicationsharedApplication]isRegisteredForRemoteNotifications];

UIAlertView* successAlert = [[UIAlertViewalloc]initWithTitle:@"Reminder"message:@"Your Reminder has been Scheduled"delegate:nilcancelButtonTitle:@"OK Thanks ! "otherButtonTitles:nil];

[successAlertshow];




}

IOS8定位问题


/**

*1:先在info.plist中添加NSLocationAlwaysUsageDescription设置为字符串类型,为YES;

*2:在info.plist中添加NSLocationWhenInUseUsageDescription设置为字符串类型,为YES;

*3:创建CLLocationManager对象

*4: //创建对象

* self.locationManager=[[CLLocationManager alloc]init];

* //设置代理

* self.locationManager.delegate=self;

* //请求

* [self.locationManager requestWhenInUseAuthorization];

* //类型

* self.locationManager.desiredAccuracy=kCLDistanceFilterNone;

* //开始

* [self.locationManager startUpdatingLocation];

*5:写代理方法-(void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status

*/

//创建对象

self.locationManager=[[CLLocationManageralloc]init];

//设置代理

self.locationManager.delegate=self;

//请求

[self.locationManagerrequestAlwaysAuthorization];

//类型

self.locationManager.desiredAccuracy=kCLDistanceFilterNone;

//开始定位

[self.locationManagerstartUpdatingLocation];


#pragma mark代理方法

//此方法会在用户授权状态改变时调用

-(void)locationManager:(CLLocationManager*)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status

{

switch(status)

{

casekCLAuthorizationStatusNotDetermined:

if([self.locationManagerrespondsToSelector:@selector(requestWhenInUseAuthorization)])

{

[self.locationManagerrequestAlwaysAuthorization];

}

break;

default:

break;

}

}




//更新位置的代理方法

-(void)locationManager:(CLLocationManager*)manager didUpdateLocations:(NSArray*)locations

{ //use locations

NSLog(@"=========%@",locations);

//根据经纬度解析成位置

CLGeocoder*geocoder=[[CLGeocoderalloc]init];

[geocoderreverseGeocodeLocation:locations[0]completionHandler:^(NSArray*placemark,NSError*error)

{

CLPlacemark*mark=[placemarkobjectAtIndex:0];

NSString* title=[NSStringstringWithFormat:@"%@%@%@",mark.subLocality,mark.thoroughfare,mark.subThoroughfare];

NSString * subTitle=[NSStringstringWithFormat:@"%@",mark.name];//获取subtitle的信息

NSLog(@"``````%@~~~~~~~%@_______",title,subTitle);

} ];

}

//定位失败信息

-(void)locationManager:(CLLocationManager*)manager didFailWithError:(NSError*)error

{

NSLog(@"--------%@---------",error);

}