发生本地区域事件时启动的ios应用

时间:2018-07-30 16:04:49

标签: ios swift geolocation location core-location

我正在尝试开发一个应用程序,当我输入之前创建的“本地区域”时,通知此事件。我已经阅读了很多讨论,但是我仍然感到困惑。我正在这个社区的帮助下开发这个应用程序,因为我也很新。开发的应用程序在处于活动状态或在后台运行时均能很好地运行,但在关闭时则无法运行。实际上,我要那个。当iphone进入之前创建的本地区域时,唤醒我的应用程序(用于执行某些操作,例如通知)。阅读苹果的文档后,我发现lauchOptions与我的问题有关。因此,在上面,我在AppDelegate类中发布了应用程序功能的代码。

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

    registerForPushNotifications()

    if launchOptions?[UIApplicationLaunchOptionsKey.location] != nil {
        if locationManager == nil {
            locationManager = CLLocationManager()
            locationManager?.delegate = self
            locationManager?.distanceFilter = 10
            locationManager?.desiredAccuracy = kCLLocationAccuracyBest
            locationManager?.allowsBackgroundLocationUpdates = true
            locationManager?.startUpdatingLocation()
            Logger.write(text: "app opened by s.o.", to: logFile)
        }
    } else {
        locationManager?.delegate = self
        locationManager?.distanceFilter = 10
        locationManager?.desiredAccuracy = kCLLocationAccuracyBest
        locationManager?.allowsBackgroundLocationUpdates = true
        locationManager?.startUpdatingLocation()

        if CLLocationManager.authorizationStatus() == .notDetermined {
            locationManager?.requestAlwaysAuthorization()
        }
        else if CLLocationManager.authorizationStatus() == .denied {
        }
        else if CLLocationManager.authorizationStatus() == .authorizedAlways {
            locationManager?.requestAlwaysAuthorization()
        }
    }

    return true
}

根据发现的其他讨论,我已经实现了此代码,但正如字符串“由s.o打开的应用程序”所述。永远不会写在我的logFile上。我怎么解决这个问题?谢谢大家!

1 个答案:

答案 0 :(得分:0)

那么只需打印调试代码即可。

import java.util.Scanner;
public class Issue {
    public static Scanner scan = new Scanner(System.in);
    int n;
    int ID[]=new int[n];
    String [] Name=new String[n];
    public void get()
    {

        int ID[] = new int[n];
        for (int i = 0; i < n; i++) {
            System.out.println("Enter " + (i+1) + "st Employe ID :");
            ID[i] = scan.nextInt();
            System.out.println("Enter Employe Name:");
            Name[i]=scan.nextLine();

        }
    }
    public static void main(String[] args) {
        Issue obj=new Issue();
        System.out.println("Enter no.of Employes:");
        obj.n=scan.nextInt();
        obj.get();

    }
}

您应该看到“已注册推送通知”,然后无论locationManager是什么。也许不是零,所以记录器甚至没有执行