标签: appdelegate

如何处理launchOptions:[NSObject:AnyObject]?在斯威夫特?

在Swift AppDelegate类中,您将获得以下方法:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    // ...code...
    return true
}
Run Code Online (Sandbox Code Playgroud)

launchOptions: [NSObject: AnyObject]?参数是可选的.在Objective-C中,这是作为一个NSDictionary.我想从中提取UIApplicationLaunchOptionsRemoteNotificationKey它.以下是Objective-C中的完成方式:

NSDictionary *remoteNotification = launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey];

if (remoteNotification)
{
    // ...do stuff...
}
Run Code Online (Sandbox Code Playgroud)

你会如何在Swift中做到这一点?

optional appdelegate swift

8
推荐指数
1
解决办法
6656
查看次数

在使用GIDSignIn处理使用其他Google应用程序登录时,不会获取Google用户

我正在使用谷歌登录iOS和使用模拟器它工作正常,因为没有安装谷歌应用程序和用户获取,但使用我的iPhone 6设备打开youtube(其中有一些注册帐户)的句柄登录.之后,当回到应用程序代码时,请不要输入此功能:

-(void)signIn:(GIDSignIn *) signIn 
    didSignInForUser:(GIDGoogleUser *)
    user withError:(NSError *) error
Run Code Online (Sandbox Code Playgroud)

任何人都可以帮助我,我不能使用其他功能登录我必须打电话[[GIDSignIn sharedIstance] signIn],此功能检测是否安装了另一个谷歌应用程序,并自动打开另一个谷歌应用程序或Webview.

iphone ios appdelegate ios8 google-signin

8
推荐指数
1
解决办法
2097
查看次数

在AppDelegate中检测抖动

如何在Swift中的AppDelegate(整个应用程序)中检测到设备震动?

我找到了解释如何在视图控制器中执行此操作的答案,但希望在我的应用程序中执行此操作.

shake ios appdelegate swift swift3

8
推荐指数
2
解决办法
4044
查看次数

swift 3中的所有6个app委托函数"几乎匹配可选要求" - 这是什么?怎么修?

昨晚下载了xcode 8.2 beta,转换了我的大部分代码,但现在我遇到了关于app delegate的六个函数的黄色警告符号:

var window: UIWindow?


func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    // Override point for customization after application launch.
    return true
}

  func applicationWillResignActive(application: UIApplication) {
    // 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. …
Run Code Online (Sandbox Code Playgroud)

appdelegate swift swift3 xcode8

8
推荐指数
1
解决办法
4386
查看次数

从远程通知打开ViewController

当我的应用程序捕获远程通知时,我尝试打开一个特定的ViewController.

让我展示我的项目架构.这是我的故事板: 在此输入图像描述

当我收到通知时,我想打开一个"SimplePostViewController",所以这是我的appDelegate:

var window: UIWindow?
var navigationVC: UINavigationController?

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    let notificationTypes: UIUserNotificationType = [UIUserNotificationType.Alert, UIUserNotificationType.Badge, UIUserNotificationType.Sound]
    let pushNotificationSettings = UIUserNotificationSettings(forTypes: notificationTypes, categories: nil)
    let storyboard = UIStoryboard(name: "Main", bundle: nil)

    self.navigationVC = storyboard.instantiateViewControllerWithIdentifier("LastestPostsNavigationController") as? UINavigationController
    application.registerUserNotificationSettings(pushNotificationSettings)
    application.registerForRemoteNotifications()
    return true
}

func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
    if let postId = userInfo["postId"] as? String {
        print(postId)

        let api = EVWordPressAPI(wordpressOauth2Settings: Wordpress.wordpressOauth2Settings, site: Wordpress.siteName)

        api.postById(postId) { post in
            if …
Run Code Online (Sandbox Code Playgroud)

push-notification apple-push-notifications appdelegate swift

8
推荐指数
1
解决办法
1万
查看次数

应用程序的返回值如何:openURL:options:used?

阅读文档UIApplicationDelegate - application:openURL:options

返回:

如果委托成功处理了请求,则为YES;如果尝试打开URL资源失败,则为NO.

返回YESvs NO影响是什么?如果您恰好对应用程序委托进行子类化并且可能想要super处理调用,这只是一种方便吗?返回值似乎不会以UIApplication任何obvoius方式影响自身的行为.

ios appdelegate

8
推荐指数
1
解决办法
632
查看次数

应用程序崩溃,出现UIApplicationEndBackgroundTaskError

上下文:我的应用是使用SwiftUI制作的,SwiftUI是使用SpriteKit的游戏。

在设备上按下主屏幕按钮时,我的应用遇到了名为“ UIApplicationEndBackgroundTaskError” 的错误。日志如下所示:

Can't end BackgroundTask: no background task exists with identifier 1 (0x1), or it may have already been ended. Break in UIApplicationEndBackgroundTaskError() to debug.

我已经尝试过创建断点,但是它并没有提供我所了解的任何有用信息。没有日志,仅显示“调试导航器”。

调试导航器

我试图调查问题的出处。我只是添加了一些简单的打印语句。Update在断点暂停应用程序之前,打印会快速重复几次:

struct SceneView: UIViewRepresentable {

    let bounds: CGRect


    // Conformance to UIViewRepresentable
    func makeUIView(context: Context) -> SKView {
        SKView(frame: bounds)
    }
    func updateUIView(_ uiView: SKView, context: Context) {
        print("Update")

        let scene = Scene(size: bounds.size)
        uiView.ignoresSiblingOrder = true
        uiView.showsFPS = true
        uiView.showsDrawCount = true
        uiView.showsNodeCount = true
        uiView.presentScene(scene)
    } …
Run Code Online (Sandbox Code Playgroud)

ios appdelegate sprite-kit swift swiftui

8
推荐指数
1
解决办法
3550
查看次数

设备锁定时后台任务停止?

当设备进入后台时,我有一个计时器正在运行,因为我想检查我服务中的少量数据.我在app delegate中的applicationDidEnterBackground方法中使用以下代码

    UIApplication *app = [UIApplication sharedApplication];

//create new uiBackgroundTask
__block UIBackgroundTaskIdentifier bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
    [app endBackgroundTask:bgTask];
    bgTask = UIBackgroundTaskInvalid;
}];

//and create new timer with async call:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    //run function methodRunAfterBackground
    NSString *server = [variableStore sharedGlobalData].server;
    NSLog(@"%@",server);
    if([server isEqual:@"_DEV"]){
        arrivalsTimer = [NSTimer scheduledTimerWithTimeInterval:30 target:self selector:@selector(getArrivals) userInfo:nil repeats:YES];
    }
    else {
        arrivalsTimer = [NSTimer scheduledTimerWithTimeInterval:300 target:self selector:@selector(getArrivals) userInfo:nil repeats:YES];
    }
    [[NSRunLoop currentRunLoop] addTimer:arrivalsTimer forMode:NSDefaultRunLoopMode];
    [[NSRunLoop currentRunLoop] run];
});
Run Code Online (Sandbox Code Playgroud)

这工作绝对正常,直到设备自动锁定,然后计时器停止滴答.有关如何阻止这种情况发生的任何建议?默认的实时时间是5分钟,因此大多数设备将在此偶数之前锁定一次.

谢谢

nstimer ios appdelegate ios8.3

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

Firebase 谷歌登录身份验证 AppDelegate- 使用未解析的标识符“isMFAEnabled”

我是 iOS 开发的新手。我正在尝试将 google 登录添加到我的应用程序,但我遇到了一些问题。代码显示了一些“使用未解析的标识符‘isMFAEnabled”和“类型‘AppDelegate’的值没有成员‘showTextInputPrompt’”。请帮助我。我正在关注此文档 - https://firebase.google.com/docs/auth/ios/google-signin#swift_9 在此处输入图片说明

import UIKit
import Firebase
import GoogleSignIn

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate,GIDSignInDelegate {
   
    
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        FirebaseApp.configure()
        GIDSignIn.sharedInstance().clientID = FirebaseApp.app()?.options.clientID
        GIDSignIn.sharedInstance().delegate = self
        return true
    }

    func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
        return GIDSignIn.sharedInstance().handle(url)
    }
    func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {
           if let error = error {
            print(error.localizedDescription)
             return
           } …
Run Code Online (Sandbox Code Playgroud)

ios appdelegate firebase-authentication google-signin swift4

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

使用 SwiftUI 的新 iOS 14 生命周期访问 AppDelegate 中的 AppState

我正在使用 iOS 14 中 SwiftUI 的新应用程序生命周期。

但是,我被困在如何在AppDelegate 中访问我的AppState(单一事实来源)对象。我需要的AppDelegate在启动时运行的代码,并注册通知(,,)等等。didFinishLaunchingWithOptionsdidRegisterForRemoteNotificationsWithDeviceTokendidReceiveRemoteNotification

我知道@UIApplicationDelegateAdaptor但是我不能例如通过构造函数将对象传递给AppDelegate。我想反过来(在AppDelegate 中创建AppState然后在MyApp 中访问它)也不起作用。

@main
struct MyApp: App {
    @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
    @State var appState = AppState()
    
    var body: some Scene {
        WindowGroup {
            ContentView().environmentObject(appState)
        }
    }
}
Run Code Online (Sandbox Code Playgroud)
class AppDelegate: NSObject, UIApplicationDelegate {
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
        // access appState here...
        return …
Run Code Online (Sandbox Code Playgroud)

state appdelegate swift swiftui ios14

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