Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve #319: tapping the widget opens the app #334

Merged
merged 3 commits into from
Dec 25, 2016
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion Loop Status Extension/StatusViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,21 @@ class StatusViewController: UIViewController, NCWidgetProviding {
super.viewDidLoad()
subtitleLabel.alpha = 0
subtitleLabel.textColor = UIColor.secondaryLabelColor

let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(openLoopApp(_:)))
view.addGestureRecognizer(tapGestureRecognizer)
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}


@objc private func openLoopApp(_: Any) {
if let url = Bundle.main.mainAppUrl {
self.extensionContext?.open(url)
}
}

func widgetPerformUpdate(completionHandler: (@escaping (NCUpdateResult) -> Void)) {
guard
let context = UserDefaults(suiteName: Bundle.main.appGroupSuiteName)?.statusExtensionContext
Expand Down
8 changes: 8 additions & 0 deletions Loop/Extensions/NSBundle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,12 @@ extension Bundle {
var appGroupSuiteName: String {
return "group.\(mainAppBundleIdentifier!)"
}

var mainAppUrl: URL? {
if let mainAppBundleIdentifier = mainAppBundleIdentifier {
return URL(string: mainAppBundleIdentifier + "://")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"\(mainAppBundleIdentifier)://"

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch. fixed.

} else {
return nil
}
}
}
9 changes: 9 additions & 0 deletions Loop/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>$(MAIN_APP_BUNDLE_IDENTIFIER)</string>
</array>
</dict>
</array>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>ITSAppUsesNonExemptEncryption</key>
Expand Down