您好,登錄后才能下訂單哦!
-
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
_window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
_window.backgroundColor = [UIColor whiteColor];
[_window makeKeyAndVisible];
ScrollContentViewController * scrollcontentView = [[ScrollContentViewController alloc]init];
UINavigationController * navigationController = [[UINavigationController alloc]initWithRootViewController:scrollcontentView];
_window.rootViewController = navigationController;
UIView * statusBarView = [[UIView alloc]initWithFrame:CGRectMake(0, -20, 320, 64)];
statusBarView.backgroundColor = [UIColor colorWithRed:0 green:122/255.0f blue:247/255.0f alpha:1];
[navigationController.navigationBar addSubview:statusBarView];
[application setStatusBarHidden:NO];
[application setStatusBarStyle:UIStatusBarStyleLightContent];
//注冊推送(ios 8)
if ([UIApplication instancesRespondToSelector:@selector(registerUserNotificationSettings:)])
{
[[UIApplication sharedApplication]registerUserNotificationSettings:[UIUserNotificationSettingssettingsForTypes:UIUserNotificationTypeAlert |UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil]];
}
return YES;
}
-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
//接受本地推送
NSLog(@"%@",notification);
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"iWeibo" message:notification.alertBody delegate:nil cancelButtonTitle:@"確定"otherButtonTitles: nil];
[alert show];
//圖標上的數字減1
application.applicationIconBadgeNumber -=1;
//解除本地推送
//獲得uiapplication
UIApplication * app = [UIApplication sharedApplication];
//獲取本地推送數組
NSArray * localArray = [app scheduledLocalNotifications];
//聲明本體通知對象
UILocalNotification * localNotification;
if (localArray)
{
for (UILocalNotification * noti in localArray)
{
NSDictionary * dict = noti.userInfo;
if (dict)
{
NSString * inKey = [dict objectForKey:@"key"];
if ([inKey isEqualToString:@"對應的key值"])
{
if (localNotification)
{
localNotification = nil;
}
break;
}
}
}
//判斷是否找到已經存在的相同key的推送
if (!localNotification)
{
//不存在初始化
localNotification = [[UILocalNotification alloc]init];
}
if (localNotification)
{
//不推送 取消推送
[app cancelLocalNotification:localNotification];
return;
}
}
}
.....
- (void)viewDidLoad {.....}
-(void)SendNotification:(UIButton *)sender
{ //創建本地推送
NSDate * now = [NSDate date];
UILocalNotification * reminderNotification = [[UILocalNotification alloc]init];
//設置推送時間
[reminderNotification setFireDate:[now dateByAddingTimeInterval:10]];
//設置時區
[reminderNotification setTimeZone:[NSTimeZone defaultTimeZone]];
//設置userinfo 方便在之后需要撤銷的時候使用
reminderNotification.userInfo = [NSDictionary dictionaryWithObject:@"name" forKey:@"key"];
//設置推送內容
[reminderNotification setAlertBody:@"Don't forget to Show Out !"];
[reminderNotification setAlertAction:@"Show Out"];
[reminderNotification setCategory:@"alert"];
//設置推送聲音
[reminderNotification setSoundName:UILocalNotificationDefaultSoundName];
//顯示在icon上的紅色圈子的數子
[reminderNotification setApplicationIconBadgeNumber:1];
//添加推送到UIApplication
[[UIApplication sharedApplication]scheduleLocalNotification:reminderNotification];
NSLog(@"currentUserNotificationSettings = %@",[[UIApplication sharedApplication]currentUserNotificationSettings]);
[[UIApplication sharedApplication] isRegisteredForRemoteNotifications ];
UIAlertView * successAlert = [[UIAlertView alloc]initWithTitle:@"Reminder" message:@"Your Reminder has been Scheduled" delegate:nilcancelButtonTitle:@"OK Thanks ! " otherButtonTitles: nil];
[successAlert show];
}
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=[[CLLocationManager alloc]init];
//設置代理
self.locationManager.delegate=self;
//請求
[self.locationManager requestAlwaysAuthorization];
//類型
self.locationManager.desiredAccuracy=kCLDistanceFilterNone;
//開始定位
[self.locationManager startUpdatingLocation];
#pragma mark 代理方法
//此方法會在用戶授權狀態改變時調用
-(void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status
{
switch (status)
{
case kCLAuthorizationStatusNotDetermined:
if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)])
{
[self.locationManager requestAlwaysAuthorization];
}
break;
default:
break;
}
}
//更新位置的代理方法
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray*)locations
{ //use locations
NSLog(@"=========%@",locations);
//根據經緯度解析成位置
CLGeocoder *geocoder=[[CLGeocoder alloc]init];
[geocoder reverseGeocodeLocation:locations[0] completionHandler:^(NSArray*placemark,NSError *error)
{
CLPlacemark *mark=[placemark objectAtIndex:0];
NSString * title=[NSStringstringWithFormat:@"%@%@%@",mark.subLocality,mark.thoroughfare,mark.subThoroughfare];
NSString * subTitle=[NSString stringWithFormat:@"%@",mark.name];//獲取subtitle的信息
NSLog(@"``````%@~~~~~~~%@_______",title,subTitle);
} ];
}
//定位失敗信息
-(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
NSLog(@"--------%@---------",error);
}
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。