是否可以知道应用程序是否通过推送通知启动/打开?
我猜这个发布活动可以在这里找到:
- (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
我已经创建了一个函数,它假设处理具有位置的权限,因此如果应用程序没有位置权限,它将关闭.但是,当您按下打开设置并在状态栏中按"返回应用程序"时,该determeinePermission方法不会再次执行.我试过把它添加到viewDidLoad,viewDidAppear和viewWillAppear.我能做什么?
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) 我的iOS 4/5/6应用程序可以简单使用.我希望用户点击"完成,现在离开"按钮,将其带回他们使用的应用程序,然后我才能进入前端.
有没有办法让我的iOS将自己置于后台,同时将之前的应用程序返回到前端?
在iPad上,用户可以通过在屏幕上水平四指滑动来获得该效果.但是这种姿势并不是一个完整的解决方案,因为(a)该手势在手持设备上不起作用,并且(2)没有多少用户知道该手势.我想以编程方式将之前的应用程序返回到前端.
我已将我的代码转换为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)
我的崩溃日志就在这里.