我知道要从app delegate获取当前视图控制器,我可以使用navigationController我为我的应用程序设置的属性.但是,在我的应用程序的许多地方都可以提供模态导航控制器.有没有办法从app委托中检测到这个,因为当前导航控制器将与app委托持有引用的导航控制器不同?
我已经能够设置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
嗨,这是我的问题:
在我的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
我的应用程序需要在应用程序处于活动状态以及何时处于非活动状态并被杀死时获取用户的位置.当用户的位置靠近商店时,应用程序必须发送本地通知.
我不确定到底发生了什么,但是我无法让我的应用程序在后台获取位置并在被杀时将其唤醒.
我有一个位置管理器(单例,用于"使用"和"始终"时的两种情况),我在.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) 我希望在应用程序启动后立即提示用户访问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)
但是发生的事情是应用程序启动并且它挂在启动画面上 - 如果我按下主页按钮然后应用程序尝试关闭,然后弹出权限提示.
有谁想过如何做到这一点?
我有一个小部件,通过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
如何设置我的AppDelegate来处理应用程序在前台和后台使用swift 3和ios 10时发生的推送通知?如果我收到通知,包括如何让手机在前台振动.
当用户终止应用程序(强制关闭)时,我需要进行 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 调用不是在这里完成的任务。所以我想知道,有什么方法可以做到这一点。
在 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) 当我从后台转换到前台时开始发出请求后,我的应用程序出现了相当多的网络错误。
\n错误看起来像这样:
\nError 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.}\nRun Code Online (Sandbox Code Playgroud)\n该代码是从我的应用程序的委托触发的:
\n func applicationWillEnterForeground(_: UIApplication) {\n coordinator?.handleWillEnterForeground()\n }\nRun Code Online (Sandbox Code Playgroud)\n从本文档来看,现阶段应允许网络请求:
\n\n\n在启动时,系统会在非活动状态下启动您的应用程序,然后将其转换到前台。使用您的 app\xe2\x80\x99s 启动时方法来执行当时所需的任何工作。对于位于后台的应用程序,UIKit 通过调用以下方法之一将您的应用程序移至非活动状态:
\n\n
\n- 对于支持场景的应用程序 \xe2\x80\x94 相应场景委托对象的 sceneWillEnterForeground(_:) 方法。
\n- 对于所有其他应用程序 \xe2\x80\x94 applicationWillEnterForeground(_:) 方法。
\n从后台过渡到前台时,使用这些方法从磁盘加载资源和从网络获取数据。
\n
而且:
\nappdelegate ×10
ios ×5
swift ×5
objective-c ×3
ios8 ×2
core-motion ×1
delegates ×1
ios10 ×1
swiftui ×1
uistatusbar ×1