-
Notifications
You must be signed in to change notification settings - Fork 375
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
kasem
committed
Apr 9, 2024
1 parent
f564902
commit 863f657
Showing
16 changed files
with
751 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// | ||
// ActionViewController.swift | ||
// ActionExtension | ||
// | ||
// Created by Kasem Mohamed on 2024-02-05. | ||
// Copyright © 2024 The Chromium Authors. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
import MobileCoreServices | ||
import UniformTypeIdentifiers | ||
|
||
class ActionViewController: UIViewController { | ||
|
||
@IBOutlet weak var imageView: UIImageView! | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
|
||
// Get the item[s] we're handling from the extension context. | ||
|
||
// For example, look for an image and place it into an image view. | ||
// Replace this with something appropriate for the type[s] your extension supports. | ||
var imageFound = false | ||
for item in self.extensionContext!.inputItems as! [NSExtensionItem] { | ||
for provider in item.attachments! { | ||
if provider.hasItemConformingToTypeIdentifier(UTType.image.identifier) { | ||
// This is an image. We'll load it, then place it in our image view. | ||
weak var weakImageView = self.imageView | ||
provider.loadItem(forTypeIdentifier: UTType.image.identifier, options: nil, completionHandler: { (imageURL, error) in | ||
OperationQueue.main.addOperation { | ||
if let strongImageView = weakImageView { | ||
if let imageURL = imageURL as? URL { | ||
strongImageView.image = UIImage(data: try! Data(contentsOf: imageURL)) | ||
} | ||
} | ||
} | ||
}) | ||
|
||
imageFound = true | ||
break | ||
} | ||
} | ||
|
||
if (imageFound) { | ||
// We only handle one image, so stop looking for more. | ||
break | ||
} | ||
} | ||
} | ||
|
||
@IBAction func done() { | ||
// Return any edited content to the host app. | ||
// This template doesn't do anything, so we just echo the passed in items. | ||
self.extensionContext!.completeRequest(returningItems: self.extensionContext!.inputItems, completionHandler: nil) | ||
} | ||
|
||
} |
53 changes: 53 additions & 0 deletions
53
example/ios/ActionExtension/Base.lproj/MainInterface.storyboard
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13122.16" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="ObA-dk-sSI"> | ||
<dependencies> | ||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13104.12"/> | ||
<capability name="Safe area layout guides" minToolsVersion="9.0"/> | ||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> | ||
</dependencies> | ||
<scenes> | ||
<!--Image--> | ||
<scene sceneID="7MM-of-jgj"> | ||
<objects> | ||
<viewController title="Image" id="ObA-dk-sSI" customClass="ActionViewController" customModuleProvider="target" sceneMemberID="viewController"> | ||
<view key="view" contentMode="scaleToFill" id="zMn-AG-sqS"> | ||
<rect key="frame" x="0.0" y="0.0" width="320" height="528"/> | ||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> | ||
<subviews> | ||
<navigationBar contentMode="scaleToFill" horizontalCompressionResistancePriority="751" verticalCompressionResistancePriority="751" translatesAutoresizingMaskIntoConstraints="NO" id="NOA-Dm-cuz"> | ||
<items> | ||
<navigationItem id="3HJ-uW-3hn"> | ||
<barButtonItem key="leftBarButtonItem" title="Done" style="done" id="WYi-yp-eM6"> | ||
<connections> | ||
<action selector="done" destination="ObA-dk-sSI" id="Qdu-qn-U6V"/> | ||
</connections> | ||
</barButtonItem> | ||
</navigationItem> | ||
</items> | ||
</navigationBar> | ||
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="9ga-4F-77Z"/> | ||
</subviews> | ||
<color key="backgroundColor" xcode11CocoaTouchSystemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/> | ||
<constraints> | ||
<constraint firstItem="VVe-Uw-JpX" firstAttribute="trailing" secondItem="NOA-Dm-cuz" secondAttribute="trailing" id="A05-Pj-hrr"/> | ||
<constraint firstItem="9ga-4F-77Z" firstAttribute="top" secondItem="NOA-Dm-cuz" secondAttribute="bottom" id="Fps-3D-QQW"/> | ||
<constraint firstItem="NOA-Dm-cuz" firstAttribute="leading" secondItem="VVe-Uw-JpX" secondAttribute="leading" id="HxO-8t-aoh"/> | ||
<constraint firstItem="VVe-Uw-JpX" firstAttribute="trailing" secondItem="9ga-4F-77Z" secondAttribute="trailing" id="Ozw-Hg-0yh"/> | ||
<constraint firstItem="9ga-4F-77Z" firstAttribute="leading" secondItem="VVe-Uw-JpX" secondAttribute="leading" id="XH5-ld-ONA"/> | ||
<constraint firstItem="VVe-Uw-JpX" firstAttribute="bottom" secondItem="9ga-4F-77Z" secondAttribute="bottom" id="eQg-nn-Zy4"/> | ||
<constraint firstItem="NOA-Dm-cuz" firstAttribute="top" secondItem="VVe-Uw-JpX" secondAttribute="top" id="we0-1t-bgp"/> | ||
</constraints> | ||
<viewLayoutGuide key="safeArea" id="VVe-Uw-JpX"/> | ||
</view> | ||
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/> | ||
<size key="freeformSize" width="320" height="528"/> | ||
<connections> | ||
<outlet property="imageView" destination="9ga-4F-77Z" id="5y6-5w-9QO"/> | ||
<outlet property="view" destination="zMn-AG-sqS" id="Qma-de-2ek"/> | ||
</connections> | ||
</viewController> | ||
<placeholder placeholderIdentifier="IBFirstResponder" id="X47-rx-isc" userLabel="First Responder" sceneMemberID="firstResponder"/> | ||
</objects> | ||
</scene> | ||
</scenes> | ||
</document> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>NSExtension</key> | ||
<dict> | ||
<key>NSExtensionAttributes</key> | ||
<dict> | ||
<key>NSExtensionActivationRule</key> | ||
<string>TRUEPREDICATE</string> | ||
<key>NSExtensionServiceAllowsFinderPreviewItem</key> | ||
<true/> | ||
<key>NSExtensionServiceAllowsTouchBarItem</key> | ||
<true/> | ||
<key>NSExtensionServiceFinderPreviewIconName</key> | ||
<string>NSActionTemplate</string> | ||
<key>NSExtensionServiceTouchBarBezelColorName</key> | ||
<string>TouchBarBezel</string> | ||
<key>NSExtensionServiceTouchBarIconName</key> | ||
<string>NSActionTemplate</string> | ||
</dict> | ||
<key>NSExtensionMainStoryboard</key> | ||
<string>MainInterface</string> | ||
<key>NSExtensionPointIdentifier</key> | ||
<string>com.apple.ui-services</string> | ||
</dict> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
example/ios/ActionExtension/Media.xcassets/TouchBarBezel.colorset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"info" : { | ||
"version" : 1, | ||
"author" : "xcode" | ||
}, | ||
"colors" : [ | ||
{ | ||
"idiom" : "mac", | ||
"color" : { | ||
"reference" : "systemPurpleColor" | ||
} | ||
} | ||
] | ||
} |
Oops, something went wrong.