Hi i have a problem with my App i have added 3D Touch Quick actions and my problem is when my app is not in multitasking then not open the Share sheet in my app have anyone a idea how can i fix the problem thats my code the problem is only in the share quick action on the info view and the problem quick action work it fine.
// AppDelegate.swift
import UIKit import MessageUI
@UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate, MFMailComposeViewControllerDelegate {
var window: UIWindow?
enum QuickActionType : String {
case viewControllerInfo = "com.example.infoView"
case share = "com.example.share"
case problem = "com.example.problem"
}
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
var QuickAction = false
if let shortcutItem = launchOptions?[UIApplicationLaunchOptionsShortcutItemKey] as? UIApplicationShortcutItem{
QuickAction = true
handleQuickAction(shortcutItem)
}
return !QuickAction
}
func application(application: UIApplication, performActionForShortcutItem shortcutItem: UIApplicationShortcutItem, completionHandler: (Bool) -> Void) {
let handledQuickAction = handleQuickAction(shortcutItem)
completionHandler(handledQuickAction)
}
func mailComposeController(controller: MFMailComposeViewController, didFinishWithResult result: MFMailComposeResult, error: NSError?) {
if error != nil {
print(error?.localizedDescription)
}
self.window?.rootViewController?.dismissViewControllerAnimated(true, completion: nil)
}
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.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
func applicationDidEnterBackground(application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
func applicationWillEnterForeground(application: UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}
func applicationDidBecomeActive(application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
func applicationWillTerminate(application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
func handleQuickAction(shortcutItem: UIApplicationShortcutItem) -> Bool {
var handled = false
if let shortCutType = QuickActionType.init(rawValue: shortcutItem.type){
let rootNavigationViewController = window!.rootViewController as? UINavigationController
let rootViewController = rootNavigationViewController?.viewControllers.first as UIViewController?
rootNavigationViewController?.popToRootViewControllerAnimated(false)
switch shortCutType {
// Quick Action Info
case .viewControllerInfo:
handled = true
rootViewController?.performSegueWithIdentifier("infoView", sender: nil)
case .share:
handled = true
let shareItems = ["hello world"]
let activityViewController = UIActivityViewController(activityItems: shareItems, applicationActivities: nil)
self.window?.rootViewController?.presentViewController(activityViewController, animated: true, completion: nil)
// Quick Action Problem
case .problem:
handled = true
let mailController = MFMailComposeViewController()
mailController.mailComposeDelegate = self
mailController.setToRecipients(["example@gmail.com"])
mailController.setSubject("App Bug")
mailController.setMessageBody("(Your Problem)
self.window?.rootViewController?.presentViewController(mailController, animated: true, completion: nil)
}
}
return handled
}
}