相关疑难解决方法(0)

检测是否通过推送通知启动/打开了应用程序

是否可以知道应用程序是否通过推送通知启动/打开?

我猜这个发布活动可以在这里找到:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    if (launchOptions != nil) {
         // Launched from push notification
         NSDictionary *notification = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];

    }
}
Run Code Online (Sandbox Code Playgroud)

但是,当应用程序处于后台时,如何检测到它是从推送通知中打开的?

push-notification apple-push-notifications uiapplicationdelegate ios ios6

162
推荐指数
10
解决办法
11万
查看次数

检测何时按下"返回应用程序"

我已经创建了一个函数,它假设处理具有位置的权限,因此如果应用程序没有位置权限,它将关闭.但是,当您按下打开设置并在状态栏中按"返回应用程序"时,该determeinePermission方法不会再次执行.我试过把它添加到viewDidLoad,viewDidAppearviewWillAppear.我能做什么?

func determinePermission() {
    switch CLLocationManager.authorizationStatus() {

    case .Authorized:
        if CLLocationManager.locationServicesEnabled() {
            manager.delegate = self
            manager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters
            manager.startUpdatingLocation()
        }


    case .NotDetermined:
        manager.requestWhenInUseAuthorization()
    case .AuthorizedWhenInUse, .Restricted, .Denied:
        let alertController = UIAlertController(
            title: "Background Location Access Disabled",
            message: "In order to be notified about adorable kittens near you, please open this app's settings and set location access to 'Always'.",
            preferredStyle: .Alert)

        let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel) { (action) in
            exit(0)
        } …
Run Code Online (Sandbox Code Playgroud)

permissions core-location ios swift

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

当用户完成我的iOS应用程序时,将之前的应用程序带回到前面

我的iOS 4/5/6应用程序可以简单使用.我希望用户点击"完成,现在离开"按钮,将其带回他们使用的应用程序,然后我才能进入前端.

有没有办法让我的iOS将自己置于后台,同时将之前的应用程序返回到前端?

在iPad上,用户可以通过在屏幕上水平四指滑动来获得该效果.但是这种姿势并不是一个完整的解决方案,因为(a)该手势在手持设备上不起作用,并且(2)没有多少用户知道该手势.我想以编程方式将之前的应用程序返回到前端.

ios

3
推荐指数
1
解决办法
3077
查看次数

在Swift 3中检查launchOptions

我已将我的代码转换为swift 3并且已提交到app store.当他们打开应用程序时,它会在第一时间崩溃.结果,我检查了我的崩溃日志,它在这一行崩溃了.

    if let myLaunchOptions: NSDictionary = launchOptions as NSDictionary? {
Run Code Online (Sandbox Code Playgroud)

我的整体代码是这样的.我知道launchOptions可能是零,甚至可能不是NSDictionary.这就是为什么我这样检查它并且它在那条线上失败了.我可以知道用swift 3检查/预防的其他方法吗?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

    if let myLaunchOptions: NSDictionary = launchOptions as NSDictionary? {
        let test = myLaunchOptions[UIApplicationLaunchOptionsKey.userActivityDictionary] as! NSDictionary
        let userActivity = test["UIApplicationLaunchOptionsUserActivityKey"] as! NSUserActivity
        NSLog("test1:" + String(describing: userActivity))
        continueUserActivity(userActivity)
        }
Run Code Online (Sandbox Code Playgroud)

我的崩溃日志就在这里.

在此输入图像描述

ios swift3

3
推荐指数
2
解决办法
2209
查看次数