标签: appdelegate

从app delegate获取当前视图控制器(可以使用模态)

我知道要从app delegate获取当前视图控制器,我可以使用navigationController我为我的应用程序设置的属性.但是,在我的应用程序的许多地方都可以提供模态导航控制器.有没有办法从app委托中检测到这个,因为当前导航控制器将与app委托持有引用的导航控制器不同?

delegates objective-c ios appdelegate

7
推荐指数
3
解决办法
3万
查看次数

无法在iOS8上设置交互式推送通知

我已经能够设置Interactive LOCAL通知,但远程通知不起作用.我正在使用Parse.com发送JSON

我的AppDelegate.Swift看起来像这样:

//
//  AppDelegate.swift
//  SwifferApp
//
//  Created by Training on 29/06/14.
//  Copyright (c) 2014 Training. All rights reserved.
//

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?


    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {
        UINavigationBar.appearance().barTintColor = UIColor.orangeColor()
        UINavigationBar.appearance().tintColor = UIColor.whiteColor()


        Parse.setApplicationId("eUEC7O4Jad0Kt3orqRouU0OJhkGuE20n4uSfrLYE", clientKey: "WypmaQ8XyqH26AeWIANttqwUjRJR4CIM55ioXvez")

        let notificationTypes:UIUserNotificationType = UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound
        let notificationSettings:UIUserNotificationSettings = UIUserNotificationSettings(forTypes: notificationTypes, categories: nil)

        UIApplication.sharedApplication().registerUserNotificationSettings(notificationSettings)

        return true
    }

    func application(application: UIApplication!, didRegisterUserNotificationSettings notificationSettings: UIUserNotificationSettings!) {
        UIApplication.sharedApplication().registerForRemoteNotifications() …
Run Code Online (Sandbox Code Playgroud)

apple-push-notifications parse-platform appdelegate swift ios8

7
推荐指数
1
解决办法
5200
查看次数

searchController和searchResultsController问题中的StatusBar:iOS 8

嗨,这是我的问题:

在我的AppDeleagate的 didFinishLaunchingWithOptions:方法我有一个方法[self configureUINavigationControllerStlyle]; 它配置状态栏和我的应用程序的所有导航栏外观(我的UINavigationController和UITabbarController在我的应用程序中一起工作).

-(void) configureUINavigationControllerStlyle {

UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;

UINavigationController *navigationController = (UINavigationController *)[tabBarController.viewControllers objectAtIndex:0];

navigationController.navigationBar.translucent = NO;

[[UINavigationBar appearance] setBarTintColor: [CustomColor getAwesomeColor:@"colorBlue3_1"]];

[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];

[[UINavigationBar appearance]  setTitleTextAttributes:@{
NSForegroundColorAttributeName : [UIColor whiteColor],
NSFontAttributeName: [UIFont fontWithName:@"AvenirNext-DemiBold" size:17.0]
 }];

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];

}
Run Code Online (Sandbox Code Playgroud)

另外在我的info.plist中我设置:查看基于控制器的状态栏外观为"NO"

一切都很好,我的应用程序中的所有控制器都有蓝色背景和白色文本颜色的状态栏.但不是uisearchcontroller和uisearchresultscontroller.

我的根TableViewController看起来像这样:

https://www.dropbox.com/s/oqcozos89x9yqhg/Screen%20Shot%202014-12-11%20at%2016.21.06.jpg?dl=0

我在我的应用程序中集成了searchController和searchResultsController.逻辑运行良好,但我不明白如何处理searchController和searchResultController中的状态栏外观.他们不使用我在AppDelegate.m文件中创建的状态栏的样式.

我的searchController和searchResultsController看起来像这样(状态栏变为白色,状态栏的文本颜色也变为白色,但我需要我的状态栏与我的主视图控制器中的颜色相同(蓝色背景和白色文本颜色).

https://www.dropbox.com/s/26skdz7gvehmwl4/Screen%20Shot%202014-12-11%20at%2016.21.16.png?dl=0

另一个错误:当我使用时

navigationController.navigationBar.translucent = NO;
Run Code Online (Sandbox Code Playgroud)

在我的AppDelegate中 - 在使用搜索控制器后从详细视图控制器返回时,它会导致我的家庭桌面视图"跳跃或拉伸".当我没有设置半透明属性时 - 没有"跳跃".

也许有人知道如何在iOS 8中使用searchController时修复状态栏颜色问题.

如果我使用默认颜色(不要对我的AppDelegate添加任何更改),一切正常,但我需要在我的应用程序中自定义状态栏颜色.

uistatusbar uisearchresultscontroller appdelegate ios8 uisearchcontroller

7
推荐指数
2
解决办法
1439
查看次数

获取iOS应用在后台甚至被杀的位置

我的应用程序需要在应用程序处于活动状态以及何时处于非活动状态并被杀死时获取用户的位置.当用户的位置靠近商店时,应用程序必须发送本地通知.

我不确定到底发生了什么,但是我无法让我的应用程序在后台获取位置并在被杀时将其唤醒.

我有一个位置管理器(单例,用于"使用"和"始终"时的两种情况),我在.plist中定义了NSLocationAlwaysUsageDescription和NSLocationWhenInUseUsageDescription

我在做的是:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    //The app has been killed/terminated (not in background) by iOS or the user.
    if ([launchOptions objectForKey:UIApplicationLaunchOptionsLocationKey]){

        _locationManager = [CoreLocationManager sharedInstance];
        _locationManager.isAppActive = NO;
        _locationManager.locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
        _locationManager.locationManager.activityType = CLActivityTypeOtherNavigation;

        if ([_locationManager.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) {
            [_locationManager.locationManager requestAlwaysAuthorization];
        }

        [_locationManager addLocationManagerDelegate:self];
    }
}


- (void)applicationDidBecomeActive:(UIApplication *)application
{
    if (_locationManager.locationManager){
        _locationManager.isAppActive = YES;
        [_locationManager.locationManager stopMonitoringSignificantLocationChanges];
    }

    _locationManager = [CoreLocationManager sharedInstance];

    if ([_locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) {
        [_locationManager.locationManager requestAlwaysAuthorization];
    }

    if ([_locationManager.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
        [_locationManager.locationManager requestWhenInUseAuthorization];
    } …
Run Code Online (Sandbox Code Playgroud)

objective-c core-location ios appdelegate

7
推荐指数
1
解决办法
3053
查看次数

提示动作和健身数据的权限

我希望在应用程序启动后立即提示用户访问Motion&Fitness数据(CoreMotion)的权限.

现在我正在尝试对数据执行"虚拟"查询以提示对a的权限 application:didFinishLaunchingWithOptions

CMMotionActivityManager *motionActivityManager=[[CMMotionActivityManager alloc]init];
    [motionActivityManager startActivityUpdatesToQueue:[NSOperationQueue mainQueue] withHandler:^(CMMotionActivity *activity) {
        NSLog(@"Dummy query to prompt permission from user");

    }];
Run Code Online (Sandbox Code Playgroud)

但是发生的事情是应用程序启动并且它挂在启动画面上 - 如果我按下主页按钮然后应用程序尝试关闭,然后弹出权限提示.

有谁想过如何做到这一点?

objective-c ios core-motion appdelegate

7
推荐指数
2
解决办法
3147
查看次数

由于spash屏幕或错误的控制器处于活动状态,避免丢失小部件发送的通知

我有一个小部件,通过NSURL和extensionContext调用其相应的应用程序来激活应用程序中的特定操作.

在AppDelegate的application:openURL:options:方法中,我有:

func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool {
    if let path = url.path{
        if path.containsString("action"){
          NSNotificationCenter.defaultCenter().postNotificationName(MyViewController.purchasmyActionKey, object: nil)
        }
    }
    return true
}
Run Code Online (Sandbox Code Playgroud)

当应用程序MyViewController处于打开状态且处于活动状态时,操作将完美执行.但是,如果我在应用程序中的另一个视图控制器上或应用程序已关闭,则不会执行该操作.

有人能让我走上正轨吗?

注意:我的主控制器是一个UITabBarController带有各种子视图控制器.有些是UINavigationControllers(包含网格控制器),另一个是ListViewController.

uiviewcontroller nsnotificationcenter uilocalnotification appdelegate swift

7
推荐指数
1
解决办法
71
查看次数

当应用程序在前台时,如何处理ios推送通知?

如何设置我的AppDelegate来处理应用程序在前台和后台使用swift 3和ios 10时发生的推送通知?如果我收到通知,包括如何让手机在前台振动.

apple-push-notifications appdelegate swift ios10

7
推荐指数
1
解决办法
4668
查看次数

当用户终止应用程序时,我可以进行 api 调用吗?

当用户终止应用程序(强制关闭)时,我需要进行 API 调用。我所做的直接实现如下。

在应用程序委托中,我添加了以下代码。

func applicationWillTerminate(_ application: UIApplication) {
    print("________TERMINATED___________")
    testAPICall()
}

func testAPICall(){
    let url = getURL()
    let contentHeader = ["Content-Type": "application/json"]
    Alamofire.request(url,
                  method: .put,
                  parameters: ["username": "abc@xyz.com"],
                  encoding: JSONEncoding.default,
                  headers: contentHeader).responseJSON { (response) -> Void in
                    print("-----")
                  }
}
Run Code Online (Sandbox Code Playgroud)

但是,没有拨打电话。在查看文档时,我发现在此方法中完成任务只需要 5 秒钟,最重要的是,进行 api 调用不是在这里完成的任务。所以我想知道,有什么方法可以做到这一点。

ios appdelegate swift applicationwillterminate

7
推荐指数
1
解决办法
4848
查看次数

如何使用@EnvironmentObject 在 SwiftUI 中的 AppDelegate 和 SceneDelegate/Views 之间共享数据

在 SwiftUI 5.1 中,我想使用 AppDelegate 创建一个 userData 对象。userData 还将包含 BLE 广告数据,这些数据也将从 AppDelegate 更新。这些数据应该可供 UI 使用以显示这些值。

在 AppDelegate 我使用

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    private var centralManager : CBCentralManager!
    var userData: UserData!

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        userData = UserData()

        return true
    }
Run Code Online (Sandbox Code Playgroud)

在 SceneDelegate 我想传递给视图使用

class SceneDelegate: UIResponder, UIWindowSceneDelegate {
    @EnvironmentObject var userData: UserData

    var window: UIWindow?

    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options …
Run Code Online (Sandbox Code Playgroud)

appdelegate swiftui

7
推荐指数
1
解决办法
1809
查看次数

当我的应用程序进入前台时运行的请求失败,并显示“网络连接丢失”。

当我从后台转换到前台时开始发出请求后,我的应用程序出现了相当多的网络错误。

\n

错误看起来像这样:

\n
Error Domain=NSURLErrorDomain Code=-1005 "The network connection was lost." UserInfo={NSUnderlyingError=0x2808e85a0 {Error Domain=kCFErrorDomainCFNetwork Code=-1005 "(null)" UserInfo={NSErrorPeerAddressKey=<CFData 0x282550410 [0x1f80cb728]>{length = 16, capacity = 16, bytes = 0x10021068c0a8010a0000000000000000}, _kCFStreamErrorCodeKey=-4, _kCFStreamErrorDomainKey=4}}, NSErrorFailingURLStringKey=http://192.168.1.10:4200/api/users/sessions, NSErrorFailingURLKey=http://192.168.1.10:4200/api/users/sessions, _kCFStreamErrorDomainKey=4, _kCFStreamErrorCodeKey=-4, NSLocalizedDescription=The network connection was lost.}\n
Run Code Online (Sandbox Code Playgroud)\n

该代码是从我的应用程序的委托触发的:

\n
    func applicationWillEnterForeground(_: UIApplication) {\n        coordinator?.handleWillEnterForeground()\n    }\n
Run Code Online (Sandbox Code Playgroud)\n

本文档来看,现阶段应允许网络请求:

\n
\n

在启动时,系统会在非活动状态下启动您的应用程序,然后将其转换到前台。使用您的 app\xe2\x80\x99s 启动时方法来执行当时所需的任何工作。对于位于后台的应用程序,UIKit 通过调用以下方法之一将您的应用程序移至非活动状态:

\n
    \n
  • 对于支持场景的应用程序 \xe2\x80\x94 相应场景委托对象的 sceneWillEnterForeground(_:) 方法。
  • \n
  • 对于所有其他应用程序 \xe2\x80\x94 applicationWillEnterForeground(_:) 方法。
  • \n
\n

从后台过渡到前台时,使用这些方法从磁盘加载资源和从网络获取数据

\n
\n

而且:

\n
    \n …

ios appdelegate swift

7
推荐指数
1
解决办法
2321
查看次数