新网创想网站建设,新征程启航

为企业提供网站建设、域名注册、服务器等服务

IOS8本地推送补充

-

目前成都创新互联已为近1000家的企业提供了网站建设、域名、网站空间绵阳服务器托管、企业网站设计、竞秀网站维护等服务,公司将坚持客户导向、应用为本的策略,正道将秉承"和谐、参与、激情"的文化,与客户和合作伙伴齐心协力一起成长,共同发展。

- (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);

}



网站名称:IOS8本地推送补充
文章地址:http://wjwzjz.com/article/pijpic.html
在线咨询
服务热线
服务热线:028-86922220
TOP