//
// AppDelegate.m
// SDJK
//
// Created by Jobs on 6/13/16.
// Copyright (c) 2016 com.FlintInfo.dEMO. All rights reserved.
// #import "AppDelegate.h"
#import <SMS_SDK/SMSSDK.h>
#import "YTKNetworkConfig.h"
#import "YTKUrlArgumentsFilter.h"
#import <BaiduMapAPI/BMKMapManager.h>
#import <BaiduMapAPI/BMKLocationService.h>
#import <BaiduMapAPI/BMapKit.h>
#import "MessageBox.h"
#import "AudioPlayerController.h"
#import "JPUSHService.h" #define smsAppKey @"14de71d0c204e"
#define smsAppSecret @"3b28f08695e5241779e274a9c05970e1" @interface AppDelegate () <BMKGeneralDelegate, BMKLocationServiceDelegate, JPUSHRegisterDelegate>
{
BMKMapManager *_mapManager;
BMKLocationService *_locService;
}
@end @implementation AppDelegate #pragma mark - BMKGeneralDelegate /**
*返回网络错误
*@param iError 错误号
*/
- (void)onGetNetworkState:(int)iError
{ } /**
*返回授权验证错误
*@param iError 错误号 : 为0时验证通过,具体参加BMKPermissionCheckResultCode
*/
- (void)onGetPermissionState:(int)iError
{ } #pragma mark - BMKLocationServiceDelegate
/**
*在将要启动定位时,会调用此函数
*/
- (void)willStartLocatingUser
{ } /**
*在停止定位后,会调用此函数
*/
- (void)didStopLocatingUser
{ } /**
*用户方向更新后,会调用此函数
*@param userLocation 新的用户位置
*/
- (void)didUpdateUserHeading:(BMKUserLocation *)userLocation
{ } /**
*用户位置更新后,会调用此函数
*@param userLocation 新的用户位置
*/
- (void)didUpdateBMKUserLocation:(BMKUserLocation *)userLocation
{
self.locationCoordinate = userLocation.location.coordinate;
if(CLLocationCoordinate2DIsValid(self.locationCoordinate) == YES)
{
NSLog(@"didUpdateUserLocation lat %f,long %f",userLocation.location.coordinate.latitude,userLocation.location.coordinate.longitude);
[_locService stopUserLocationService];
}
} - (CLLocationDistance) getCLLocationDistance:(CLLocationCoordinate2D)coordinateA TheTowCoordinate:(CLLocationCoordinate2D )coordinateB
{
CLLocationDistance dis;
dis = BMKMetersBetweenMapPoints(BMKMapPointForCoordinate(coordinateA), BMKMapPointForCoordinate(coordinateB)) ;
return dis;
} /**
*定位失败后,会调用此函数
*@param error 错误号
*/
- (void)didFailToLocateUserWithError:(NSError *)error
{ } #pragma mark - viewcontroller - (void)setupRequestFilters
{
NSString *appVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
YTKNetworkConfig *config = [YTKNetworkConfig sharedInstance];
#if !defined (TestApi) config.baseUrl = @"https://121.42.156.51/";
config.serverIP = @"https://121.42.156.51";
config.serverPort = nil; #else config.baseUrl = @"https://121.42.156.51:10443/";
config.serverIP = @"https://121.42.156.51";
config.serverPort = @"10443"; #endif YTKUrlArgumentsFilter *urlFilter = [YTKUrlArgumentsFilter filterWithArguments:@{@"version": appVersion,
@"UIID":[UIDevice currentDevice].identifierForVendor.UUIDString,
@"name":[UIDevice currentDevice].name,
@"model":[UIDevice currentDevice].model,
@"appkey":@"297FF4A97FCDA4BC0ECF0BB18168034A"
}];
[config addUrlFilter:urlFilter];
} -(void)initJPush:(NSDictionary*)launchOPtions
{
//NSString *advertisingId = [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];
//Required
// if ([[UIDevice currentDevice].systemVersion floatValue] >= 10.0)
// {
//// JPUSHRegisterEntity * entity = [[JPUSHRegisterEntity alloc] init];
//// entity.types = UNAuthorizationOptionAlert|UNAuthorizationOptionBadge|UNAuthorizationOptionSound;
//// [JPUSHService registerForRemoteNotificationConfig:entity delegate:self];
// }
// else
if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
//可以添加自定义categories
[JPUSHService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |
UIUserNotificationTypeSound |
UIUserNotificationTypeAlert)
categories:nil];
}
else {
//categories 必须为nil
[JPUSHService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound |
UIRemoteNotificationTypeAlert)
categories:nil];
} //Required
// init Push(2.1.5版本的SDK新增的注册方法,改成可上报IDFA,如果没有使用IDFA直接传nil )
// 如需继续使用pushConfig.plist文件声明appKey等配置内容,请依旧使用[JPUSHService setupWithOption:launchOptions]方式初始化。
static NSString *channel = @"Publish channel";
static BOOL isProduction = FALSE;
#ifdef DEBUG
isProduction = NO;
#else
isProduction = YES;
#endif
[JPUSHService setupWithOption:launchOPtions
appKey:@"5b40040d828351e75003d2cb"
channel:channel
apsForProduction:isProduction
advertisingIdentifier:nil];
} - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
NSDictionary *userInfo = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if(userInfo != nil)
{
self.hasNotification = YES;
self.notificationUserInfo = userInfo;
if([userInfo objectForKey:@"update"])
{
//[self alertUpdateApp];
}
//NSLog(@"launching userInfo:%@", userInfo);
//[MessageBox showMsg:[[userInfo description] stringByAppendingString:@"launch"]];
} [SMSSDK registerApp:smsAppKey
withSecret:smsAppSecret];
[self setupRequestFilters]; // 注册百度地图
_mapManager = [[BMKMapManager alloc]init];
BOOL ret = [_mapManager start:@"wCjpTyCmWpARGmybaEkoHAs8flZOWAvR"
generalDelegate:self];
if (!ret)
{
NSLog(@"manager start failed!");
}
self.locationCoordinate = kCLLocationCoordinate2DInvalid;
_locService = [[BMKLocationService alloc]init];
_locService.delegate = self;
[_locService startUserLocationService]; [self basicSetup]; [self initJPush:launchOptions]; return YES;
} -(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
application.applicationIconBadgeNumber = 0;
NSLog(@"==left notifi:%@", [[UIApplication sharedApplication] scheduledLocalNotifications]);
} -(void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{ } #pragma mark- JPUSHRegisterDelegate //// iOS 10 Support
//- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center
// willPresentNotification:(UNNotification *)notification
// withCompletionHandler:(void (^)(NSInteger))completionHandler
//{
// // Required
//// NSDictionary * userInfo = notification.request.content.userInfo;
//// if([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]])
//// {
//// [JPUSHService handleRemoteNotification:userInfo];
//// }
//// completionHandler(UNNotificationPresentationOptionAlert); // 需要执行这个方法,选择是否提醒用户,有Badge、Sound、Alert三种类型可以选择设置
//}
//
//// iOS 10 Support
//- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center
// didReceiveNotificationResponse:(UNNotificationResponse *)response
// withCompletionHandler:(void (^)())completionHandler
//{
// // Required
//// NSDictionary * userInfo = response.notification.request.content.userInfo;
//// if([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
//// [JPUSHService handleRemoteNotification:userInfo];
//// }
//// completionHandler(); // 系统要求执行这个方法
//} -(void)alertUpdateApp
{
__weak typeof(self) ws = self;
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"当前app有新版本,是否马上更新?"
message:nil
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *ok = [UIAlertAction actionWithTitle:@"确定"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action)
{
NSURL *url = [NSURL URLWithString:[ws.notificationUserInfo objectForKey:@"update"]];
[[UIApplication sharedApplication] openURL:url];
}];
UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action) {
;
}];
[alert addAction:ok];
[alert addAction:cancel];
alert.view.backgroundColor = [UIColor whiteColor];
UIViewController *rootVC = [UIApplication sharedApplication].keyWindow.rootViewController;
UIViewController *tempVC;
while ((tempVC = rootVC.presentedViewController))
{
rootVC = tempVC;
}
[rootVC presentViewController:alert animated:YES completion:^{ }];
} - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{ // Required, iOS 7 Support
[JPUSHService handleRemoteNotification:userInfo];
completionHandler(UIBackgroundFetchResultNewData);
NSLog(@"iOS7及以上系统,收到通知:%@", [self logDic:userInfo]);
self.notificationUserInfo = userInfo;
//[MessageBox showMsg:[[userInfo description] stringByAppendingString:@"ios7"]];
if([userInfo objectForKey:@"update"])
{
[self alertUpdateApp];
}
else
{
[[NSNotificationCenter defaultCenter] postNotificationName:receiveRemoteNotification object:self userInfo:userInfo];
}
} - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{ // Required,For systems with less than or equal to iOS6
[JPUSHService handleRemoteNotification:userInfo];
NSLog(@"iOS6及以下系统,收到通知:%@", [self logDic:userInfo]);
//[MessageBox showMsg:[[userInfo description] stringByAppendingString:@"ios6"]];
self.notificationUserInfo = userInfo;
if([userInfo objectForKey:@"update"])
{
[self alertUpdateApp];
}
else
{
[[NSNotificationCenter defaultCenter] postNotificationName:receiveRemoteNotification object:self userInfo:userInfo];
}
}
// log NSSet with UTF8
// if not ,log will be \Uxxx
- (NSString *)logDic:(NSDictionary *)dic {
if (![dic count]) {
return nil;
}
NSString *tempStr1 =
[[dic description] stringByReplacingOccurrencesOfString:@"\\u"
withString:@"\\U"];
NSString *tempStr2 =
[tempStr1 stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""];
NSString *tempStr3 =
[[@"\"" stringByAppendingString:tempStr2] stringByAppendingString:@"\""];
NSData *tempData = [tempStr3 dataUsingEncoding:NSUTF8StringEncoding];
NSString *str =
[NSPropertyListSerialization propertyListFromData:tempData
mutabilityOption:NSPropertyListImmutable
format:NULL
errorDescription:NULL];
return str;
} - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
/// Required - 注册 DeviceToken
[JPUSHService registerDeviceToken:deviceToken];
//[MessageBox showMsg:[deviceToken description]];
} - (void)applicationWillResignActive:(UIApplication *)application {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
} - (void)applicationDidEnterBackground:(UIApplication *)application {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
} - (void)applicationWillEnterForeground:(UIApplication *)application {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
} - (void)applicationDidBecomeActive:(UIApplication *)application {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
application.applicationIconBadgeNumber = 0;
} - (void)applicationWillTerminate:(UIApplication *)application {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
} #pragma mark -download backgroundSessionHandle- -(void)application:(UIApplication *)application handleEventsForBackgroundURLSession:(NSString *)identifier completionHandler:(void (^)())completionHandler
{
self.backgroundSessionCompletionHandler = completionHandler;
} # pragma mark - Remote control - (void)basicSetup
{
// Remove control
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self becomeFirstResponder];
} - (BOOL)canBecomeFirstResponder
{
return YES;
} - (void)remoteControlReceivedWithEvent:(UIEvent *)receivedEvent
{
if (receivedEvent.type == UIEventTypeRemoteControl)
{
switch (receivedEvent.subtype)
{
case UIEventSubtypeRemoteControlPause:
[[AudioPlayerController audioPlayerController] stop];
break;
case UIEventSubtypeRemoteControlStop:
[[AudioPlayerController audioPlayerController] stop];
break;
case UIEventSubtypeRemoteControlPlay:
[[AudioPlayerController audioPlayerController] play];
break;
case UIEventSubtypeRemoteControlTogglePlayPause:
[[AudioPlayerController audioPlayerController] playerStatus];
break;
case UIEventSubtypeRemoteControlNextTrack:
[[AudioPlayerController audioPlayerController] theNextSong];
break;
case UIEventSubtypeRemoteControlPreviousTrack:
[[AudioPlayerController audioPlayerController] inASong];
break;
default:
break;
}
}
} @end

  

远程通知中app更新提示。的更多相关文章

  1. wordpress 中禁止更新提示

    前言: 在此之前每每打开blog的时候总是有那么个数字在那边显示,如果是很重要的更新显示在那也就算了,有时候就算一个破主题他还一直在那边,很是让小猪纠结.最关键的是要是更新了主题,那么之前所有自定义的 ...

  2. 使用sqlite3解决IDEA中SVN更新提示cleanup却无法cleanup的问题

    用idea开发项目,更新svn有时莫名其妙的出现 Error:Error performing cleanup for 'D:\SourceProject\XXXX': svn: E155004: T ...

  3. uniapp中IOS安卓热更新和整包更新app更新

    在App.vue中 onLaunch: function() { console.log('App Launch'); // #ifdef APP-PLUS this.getVersion(); // ...

  4. Android中使用AsyncTask实现文件下载以及进度更新提示

    Android提供了一个工具类:AsyncTask,它使创建需要与用户界面交互的长时间运行的任务变得更简单.相对Handler来说AsyncTask更轻量级一些,适用于简单的异步处理,不需要借助线程和 ...

  5. iOS9中如何注册远程通知

    大熊猫猪·侯佩原创或翻译作品.欢迎转载,转载请注明出处. 如果觉得写的不好请多提意见,如果觉得不错请多多支持点赞.谢谢! hopy ;) 在以往的版本中,我们可以通过: [[UIApplication ...

  6. iOS9中怎样注冊远程通知

    大熊猫猪·侯佩原创或翻译作品.欢迎转载,转载请注明出处. 假设认为写的不好请多提意见,假设认为不错请多多支持点赞.谢谢! hopy ;) 在以往的版本号中,我们能够通过: [[UIApplicatio ...

  7. Android应用中-更新提示显示红点的方案

    什么是红点更新提示? 红点更新提示类似微信朋友圈有新的朋友消息 时会在“发现”tab上显示红点,表示有新的消息. 目前三种显示方式: 1.显示具体数字 2.只显示红点 3.显示省略,表示数量很多 方案 ...

  8. git从远程仓库中更新代码到本地仓库

    git从远程仓库中更新代码到本地仓库 有时候在使用git pull的时候,会莫名才报错.查了很多资料,尝试过git的很多命令.包括git fetch命令,都会报同样的错.最后终于发现了一条捷径,由网友 ...

  9. wordpress中如何禁止或者屏蔽更新提示

    WordPress禁止,插件更新,主题更新,wordpress本身更新提示的方法 禁止wp更新 : open file "wordpress\wp-includes\update.php&q ...

随机推荐

  1. Java开发工具安装步骤内容如下

    Java开发工具安装步骤内容如下 安装 开发工具 STS 链接下载网址 eclipse 链接下载网址 JDK安装 jdk链接下载地址 Marven环境 marven链接下载地址 Tomcat tomc ...

  2. guava学习--ComparisonChain

    转载:https://my.oschina.net/realfighter/blog/349824 在日常的工作中,我们经常需要对两个对象进行比较,以找出其中的异同, Java中提供了compare/ ...

  3. RMAN 前期准备工作和实例

    理解恢复目录,RMAN可以在没有恢复目录(NOCATALOG)下运行,这个时候备份信息保存在控制文件.保存在控制文件的备份信息是很危险的,如果控制文件的破坏将导致备份信息的丢失与恢复的失败,而且,没有 ...

  4. CentOS6.5 下安装 texlive2015 并设置 ctex 中文套装

    0 卸载旧版本的 texlive 0.1 卸载 texlive2007 如果系统没有安装过texlive,则跳过第0步. 可以在终端中使用如下命令查询本机已经安装的tex和latex版本: [She@ ...

  5. cron表达式使用详解

    Cron表达式是一个字符串,字符串以5或6个空格隔开,分为6或7个域,每一个域代表一个含义,Cron有如下两种语法格式: Seconds Minutes Hours DayofMonth Month ...

  6. 繁星——jquery的data()方法

    今天在看JQuery文档的时候偶然看到了data()方法,觉得挺好用的,这里做个记录. 这个方法用于在元素上存放数据,返回jQuery对象.在文档中提到V1.4.3 新增用法NEW data(obj) ...

  7. running programmer——spring-01(初谈spring)

    今天主要是通过一个简单的登录程序学习一些spring做基础的配置和功能. I.spring的核心配置applicationContext.xml 关于bean的配置官方给出的最基础的配置文件如下: & ...

  8. USACO Milking Cows

    思路: 脑抽了,一看题目,这不就是线段树么,离散化区间合并..最终发现我并不会写...于是看了下题目范围10^6...模拟水之..每个区间左端点+1,右端点-1,从左到右扫一下就行了... 代码: / ...

  9. 博客迁移到GitCafe

    博客以前是放在github上,但github在国内的访问速度确实有些慢,所以就想着换个git环境,本来想迁移到oschina中,后来看到以为博友介绍的迁移到gitcafe中,索性我也就照搬迁过来了. ...

  10. D2.Reactjs 操作事件、状态改变、路由

    下面内容代码使用ES6语法 一.组件的操作事件: 1.先要在组件类定义内定义操作事件的方法,如同event handler.若我需要监听在组件内的Button的点击事件onClick,首先定义监听方法 ...