1. 程式人生 > >遠端通知中app更新提示。

遠端通知中app更新提示。

//
//  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更新提示

// // AppDelegate.m // SDJK // // Created by Jobs on 6/13/16. // Copyright (c) 2016 com.FlintInfo.dEMO. All rights reserved. // #import "App

Android APP 調試過程遇到的問題

state 答案 sta 問題 net rep www 原因 啟動 調試過過程中APP安裝完啟動後有的時候會異常退出,報這個錯誤。有的時候可以直接啟動。查找不到原因。網上說把commit方法替換成commitAllowingStateLoss() 也無效。

web.xml<web-app>提示The content of element type "web-app" must match "(icon?,display- name?,description?,distributable?,

session span text .com ble splay 錯誤 esc gin 錯誤:配置web.xml時,出現紅色叉叉,提示 The content of element type "web-app" must match "(icon?,display-

在Windows Server 2008 R2 Server,連接其他服務器的數據庫遇到“未啟用當前數據庫的 SQL Server Service Broker,因此查詢通知不受支持如果希望使用通知,請為此數據庫啟用 Service Broker ”

lba pos 數據庫名 nbsp bsp enable 輸入 images logs 項目代碼和數據庫部署在不同的Windows Server 2008 R2 Server中,錯誤日誌顯示如下: "未啟用當前數據庫的 SQL Server Service Broker,因

WebStorm2017專案更新,智慧程式碼提示不顯示的解決方法

出現這個問題的時候,我百度了網上各種解決方法,都沒有用,後來就莫名其妙的好了。寫一個部落格記錄一下,以後再遇到同樣的問題的時候,給自己提供一個解決方法,雖然不能確保是不是有效,但多一種方法也沒有任何問題。對解決方法進行了一個總結,總結如下: 1.File-Power Save Mode,檢視該

h5 app 開發版本更新提示

var wgtVer=null; function plusReady(){ // 獲取本地應用資源版本號 plus.runtime.getProperty(plus.runtime.appid,function(inf){ wgtVer=inf.version; }

如何在Sublime Test註冊並去掉煩人的更新提示

sublime test 3 關於如何去電煩人的更新提示 1:Linux: 第一 我們需要註冊 Enter license 下邊是兩個註冊碼(Begin 和 End 也算在內) —– BEGIN LICENSE SJOLZY.CN —– Anthony Sansone Single User

eclipse使用svn提交,更新程式碼

在新公司工作,版本管理工具變成了svn,之前一直用git作為版本管理,用的編輯IDE是IntelliJIDEA,在這個編輯器下工作,還是很方便的,但是現在使用eclipse和svn。有點不習慣,但還是將他們記下來。 這篇文章介紹的是在eclipse上使用svn 首先在提交程式碼的時候,會看到有的檔案前會有

android開發時,xml檔案總是提示某一個錯誤,修改後仍然提示

       哎,剛開始學android開發,開發環境好不容易搭建好,自己寫程式碼的時候難免犯錯,特別是xml編寫時如果出現了程式碼錯誤,錯誤提示會一直存在,即使修改了也存在,關掉專案重新開啟也存在,關掉Eclipse 重新啟動還存在。。。。糾結了 有沒有

【strongerHuang的專欄】文章關於360雲盤下載連結都已失效,請微信公眾號“下載區”獲取更新連結

我的個人微信公眾號 微信公眾號ID:strongerHuang. 有許多重要的內容和資訊都會在公眾號中分享,相信你關注公眾號一定會喜歡那裡。(PS:1.許多失效網盤連結可以在公眾號底部選單找到; 2.該公號只有我一個人在管理和維護)

js倒計時60秒vue 更新陣列vue jshtml 返回上一頁vue h3 顯示不出來vue 標籤內容顯示不出來

js倒計時60秒==html 返回上一頁onclick=”javascript:history.back(-1);javascript :history.go(-1)==vue h3 顯示不出來vue 標籤內容顯示不出來檢視css樣式,尤其是全域性的, 應該設定了字型大小0,

Eclipse配置HTML/JS/CSS/JSP頁面的自動提示

Eclipse中配置HTML/JS/CSS/JSP頁面的自動提示。 eclipse開發智慧提示效果不太理想,使用eclipse自帶的外掛,無需另外安裝外掛,也可以實現智慧化的提示 步驟 1.>>>開啟eclipse→Windows→Preferences→Java→Ed

android studio JAVA檔案提示android.support.v7.app.actionbaractivity is deprecated怎樣處理?

出這個提示的地方有寫解決辦法呀. android.support.v7.app.ActionBarActivity is deprecated; use AppCompatActivity instead   意思是 ActionBarActivity 在最

Eclipse 開啟提示could not open jvm.cfg檔案的錯誤的解決方法最近安裝java的過程遇到這個問題

一.首先開啟提示的目錄位置,查詢是否存在這個檔案和資料夾。如果不存在的話,表示java安裝過程中出錯,相應的檔案沒有安裝。需要在控制面板中解除安裝java再重新安裝。我遇到的就是這種情況。解除安裝後,重新安裝之前訪問登錄檔,刪除如下資訊在點選開始--》執行-》輸入regedi

linux ssh 到遠端伺服器執行命令和crontab執行命令提示命令找不到的問題

使用ssh ip "hadoop" 命令時,提示找不到hadoop命令。 因為hadoop是在/etc/profile配置的,ssh到一臺伺服器上時,會執行使用者環境。 而ssh到一臺伺服器上,帶著命

intelliJ IDEA 版本更新後,如何關閉引數提示

在 IntelliJ IDEA 2016.3.4(64) 這個版本更新之後,發現在程式碼中,方法呼叫的地方,會顯示一些方法引數的提示,點不到,也不是一下就能看懂, 對於閱讀程式碼,很是不得勁。所以

Android APP更新下載,實現Notification通知欄進度通知,下載完成後點選安裝

    簡單做一個APP檢測更新的小工具,有點粗糙。不能斷點續傳,只用為個人覺得沒有必要,自己可根據大家的想法新增更多的功能,這裡只是為了想我一樣的初學者和比較簡約的人所提供。   效果如下:        基本思路先理一理,以我的實際開發為例:首先當然要一個網路去請求我們的

Android檢查更新APK,以及下載APK安裝

import android.Manifest; import android.app.Activity; import android.content.Context; import android.content.pm.PackageInfo; import android.content.pm.Pack

配置Eclipse編寫HTML/JS/CSS/JSP頁面的自動提示

script png for 提示 trigger clip wid height images 1.打開eclipse→Windows→Preferences→Java→Editor→Content Assist 修改Auto Activation triggers fo

突然斷電,怎麽找回編輯的文檔

關閉 exc xls tin 一份 編輯 用戶名 顯示 文件夾 相信很多朋友都會遇到,在寫材料或者在處理數據時,突然間斷電或者電腦死機重啟,碼了半天的字、整理了半天的數據也許就這麽沒了,有時候電腦重啟的時候再打開word或者excel或者可以看到恢復的提示,但是有的時候沒有