Skip to content

Commit

Permalink
- Example update
Browse files Browse the repository at this point in the history
- iOS fix
  • Loading branch information
carsten-klaffke committed Sep 6, 2024
1 parent 65e80fc commit 3a0a605
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ include ':capacitor-status-bar'
project(':capacitor-status-bar').projectDir = new File('../node_modules/@capacitor/status-bar/android')

include ':send-intent'
project(':send-intent').projectDir = new File('../node_modules/send-intent/android')
project(':send-intent').projectDir = new File('../../../android')
37 changes: 16 additions & 21 deletions Example/SendIntentExample/ios/App/App.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
2FAD9763203C412B000D30F8 /* config.xml in Resources */ = {isa = PBXBuildFile; fileRef = 2FAD9762203C412B000D30F8 /* config.xml */; };
50379B232058CBB4000EE86E /* capacitor.config.json in Resources */ = {isa = PBXBuildFile; fileRef = 50379B222058CBB4000EE86E /* capacitor.config.json */; };
503C1E0C29F85EE90059E6C4 /* Pods_App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AF277DCFFFF123FFC6DF26C7 /* Pods_App.framework */; };
503C1E0D29F85EE90059E6C4 /* Pods_App.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = AF277DCFFFF123FFC6DF26C7 /* Pods_App.framework */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
503C1E1929F860480059E6C4 /* ShareViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 503C1E1829F860480059E6C4 /* ShareViewController.swift */; };
503C1E1C29F860480059E6C4 /* MainInterface.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 503C1E1A29F860480059E6C4 /* MainInterface.storyboard */; };
503C1E2029F860480059E6C4 /* Share.appex in Embed Foundation Extensions */ = {isa = PBXBuildFile; fileRef = 503C1E1629F860480059E6C4 /* Share.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
Expand Down Expand Up @@ -43,17 +42,6 @@
name = "Embed Foundation Extensions";
runOnlyForDeploymentPostprocessing = 0;
};
503C1E0E29F85EE90059E6C4 /* Embed Frameworks */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "";
dstSubfolderSpec = 10;
files = (
503C1E0D29F85EE90059E6C4 /* Pods_App.framework in Embed Frameworks */,
);
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
Expand Down Expand Up @@ -192,7 +180,6 @@
504EC3021FED79650016851F /* Resources */,
9592DBEFFC6D2A0C8D5DEB22 /* [CP] Embed Pods Frameworks */,
502AF82729F80FC700316C15 /* Embed Foundation Extensions */,
503C1E0E29F85EE90059E6C4 /* Embed Frameworks */,
);
buildRules = (
);
Expand Down Expand Up @@ -369,7 +356,7 @@
CODE_SIGN_ENTITLEMENTS = Share/Share.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = "";
DEVELOPMENT_TEAM = W26J2734R6;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = Share/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = Share;
Expand All @@ -379,7 +366,8 @@
MARKETING_VERSION = 1.0;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = io.ionic.starter.Share;
"OTHER_CODE_SIGN_FLAGS[sdk=*]" = "--generate-entitlement-der";
PRODUCT_BUNDLE_IDENTIFIER = carstenklaffke.io.ionic.starter.Share;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_EMIT_LOC_STRINGS = YES;
Expand All @@ -399,7 +387,7 @@
CODE_SIGN_ENTITLEMENTS = Share/Share.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = "";
DEVELOPMENT_TEAM = W26J2734R6;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = Share/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = Share;
Expand All @@ -408,7 +396,8 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks";
MARKETING_VERSION = 1.0;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = io.ionic.starter.Share;
"OTHER_CODE_SIGN_FLAGS[sdk=*]" = "--generate-entitlement-der";
PRODUCT_BUNDLE_IDENTIFIER = carstenklaffke.io.ionic.starter.Share;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_EMIT_LOC_STRINGS = YES;
Expand Down Expand Up @@ -531,16 +520,19 @@
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = App/App.entitlements;
CODE_SIGN_IDENTITY = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = "";
DEVELOPMENT_TEAM = W26J2734R6;
INFOPLIST_FILE = App/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MARKETING_VERSION = 1.0;
"OTHER_CODE_SIGN_FLAGS[sdk=*]" = "--generate-entitlement-der";
OTHER_SWIFT_FLAGS = "$(inherited) \"-D\" \"COCOAPODS\" \"-DDEBUG\"";
PRODUCT_BUNDLE_IDENTIFIER = io.ionic.starter;
PRODUCT_BUNDLE_IDENTIFIER = carstenklaffke.io.ionic.starter;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
Expand All @@ -554,15 +546,18 @@
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = App/App.entitlements;
CODE_SIGN_IDENTITY = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = "";
DEVELOPMENT_TEAM = W26J2734R6;
INFOPLIST_FILE = App/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = io.ionic.starter;
"OTHER_CODE_SIGN_FLAGS[sdk=*]" = "--generate-entitlement-der";
PRODUCT_BUNDLE_IDENTIFIER = carstenklaffke.io.ionic.starter;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
Expand Down
2 changes: 1 addition & 1 deletion Example/SendIntentExample/ios/App/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def capacitor_pods
pod 'CapacitorHaptics', :path => '../../node_modules/@capacitor/haptics'
pod 'CapacitorKeyboard', :path => '../../node_modules/@capacitor/keyboard'
pod 'CapacitorStatusBar', :path => '../../node_modules/@capacitor/status-bar'
pod 'SendIntent', :path => '../../node_modules/send-intent'
pod 'SendIntent', :path => '../../../..'
end

target 'App' do
Expand Down
32 changes: 16 additions & 16 deletions Example/SendIntentExample/ios/App/Share/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@
<string>com.apple.share-services</string>
</dict>
<key>NSExtensionActivationRule</key>
<dict>
<key>NSExtensionActivationSupportsFileWithMaxCount</key>
<integer>5</integer>
<key>NSExtensionActivationSupportsImageWithMaxCount</key>
<integer>5</integer>
<key>NSExtensionActivationSupportsMovieWithMaxCount</key>
<integer>5</integer>
<key>NSExtensionActivationSupportsText</key>
<true/>
<key>NSExtensionActivationSupportsWebPageWithMaxCount</key>
<integer>1</integer>
<key>NSExtensionActivationSupportsWebURLWithMaxCount</key>
<integer>1</integer>
<key>NSExtensionActivationUsesStrictMatching</key>
<false/>
</dict>
<dict>
<key>NSExtensionActivationSupportsFileWithMaxCount</key>
<integer>5</integer>
<key>NSExtensionActivationSupportsImageWithMaxCount</key>
<integer>5</integer>
<key>NSExtensionActivationSupportsMovieWithMaxCount</key>
<integer>5</integer>
<key>NSExtensionActivationSupportsText</key>
<true/>
<key>NSExtensionActivationSupportsWebPageWithMaxCount</key>
<integer>1</integer>
<key>NSExtensionActivationSupportsWebURLWithMaxCount</key>
<integer>1</integer>
<key>NSExtensionActivationUsesStrictMatching</key>
<false/>
</dict>
</dict>
</plist>
42 changes: 33 additions & 9 deletions Example/SendIntentExample/ios/App/Share/ShareViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,21 +73,45 @@ class ShareViewController: UIViewController {
}
}

func loadUrl(from attachment: NSItemProvider) async throws -> URL? {
return try await withCheckedThrowingContinuation { continuation in
// Hier der Typ URL (NSURL in Objective-C)
attachment.loadItem(forTypeIdentifier: kUTTypeURL as String, options: nil) { (urlData, error) in
if let error = error {
continuation.resume(throwing: error)
} else if let url = urlData as? URL {
continuation.resume(returning: url)
} else if let url = urlData as? NSURL {
continuation.resume(returning: url as URL)
} else {
continuation.resume(returning: nil)
}
}
}
}

fileprivate func handleTypeUrl(_ attachment: NSItemProvider)
async throws -> ShareItem
{
let results = try await attachment.loadItem(forTypeIdentifier: kUTTypeURL as String, options: nil)
let url = results as! URL?
let shareItem: ShareItem = ShareItem()

if url!.isFileURL {
shareItem.title = url!.lastPathComponent
shareItem.type = "application/" + url!.pathExtension.lowercased()
shareItem.url = createSharedFileUrl(url)
if let results = try await loadUrl(from: attachment) {


let url = results as! URL?


if url!.isFileURL {
shareItem.title = url!.lastPathComponent
shareItem.type = "application/" + url!.pathExtension.lowercased()
shareItem.url = createSharedFileUrl(url)
} else {
shareItem.title = url!.absoluteString
shareItem.url = url!.absoluteString
shareItem.type = "text/plain"
}
} else {
shareItem.title = url!.absoluteString
shareItem.url = url!.absoluteString
shareItem.type = "text/plain"
print("Keine URL gefunden")
}

return shareItem
Expand Down
26 changes: 13 additions & 13 deletions Example/SendIntentExample/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
"version": "0.0.1",
"private": true,
"dependencies": {
"@capacitor/android": "5.0.0",
"@capacitor/app": "5.0.0",
"@capacitor/core": "5.0.0",
"@capacitor/filesystem": "5.0.0",
"@capacitor/haptics": "5.0.0",
"@capacitor/ios": "5.0.0",
"@capacitor/keyboard": "5.0.0",
"@capacitor/status-bar": "5.0.0",
"@ionic/react": "^7.0.0",
"@ionic/react-router": "^7.0.0",
"@capacitor/android": "6.0.0",
"@capacitor/app": "6.0.0",
"@capacitor/core": "6.0.0",
"@capacitor/filesystem": "6.0.0",
"@capacitor/haptics": "6.0.0",
"@capacitor/ios": "6.0.0",
"@capacitor/keyboard": "6.0.0",
"@capacitor/status-bar": "6.0.0",
"@ionic/react": "^8.2.7",
"@ionic/react-router": "^8.2.7",
"@testing-library/jest-dom": "^5.11.9",
"@testing-library/react": "^13.3.0",
"@testing-library/user-event": "^12.6.3",
Expand All @@ -29,7 +29,7 @@
"react-router": "^5.2.0",
"react-router-dom": "^5.2.0",
"react-scripts": "^5.0.0",
"send-intent": "^5.0.0",
"send-intent": "6.0.2",
"typescript": "^4.1.3",
"web-vitals": "^0.2.4",
"workbox-background-sync": "^5.1.4",
Expand Down Expand Up @@ -66,7 +66,7 @@
"iOS >=14"
],
"devDependencies": {
"@capacitor/cli": "5.0.0"
"@capacitor/cli": "^6.1.2"
},
"description": "An Ionic project"
}
}
4 changes: 4 additions & 0 deletions Example/SendIntentExample/src/pages/Tab1.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ const Tab1: React.FC<RouteComponentProps> = ({history, location, match}) => {
const [result, setResult] = useState('');

async function checkIntent() {
console.log("check intent")
return SendIntent.checkSendIntentReceived().then(async (result: any) => {
console.log("checked")
console.log(result)
if (result) {
console.log('SendIntent received');
let res = JSON.stringify(result);
Expand All @@ -28,6 +31,7 @@ const Tab1: React.FC<RouteComponentProps> = ({history, location, match}) => {
checkIntent();

useEffect(() => {
console.log("adding listener")
//Check-Intent: Es werden beide Varianten benötigt, mit und ohne Listener. Denn je nachdem wie das share
//angesteuert wird lädt die App neu (normaler Aufruf) oder nicht (Listener)
window.addEventListener("sendIntentReceived", () => {
Expand Down
2 changes: 1 addition & 1 deletion ios/Sources/SendIntentPlugin/SendIntentPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class SendIntentPlugin: CAPPlugin, CAPBridgedPlugin {
public let identifier = "SendIntentPlugin"
public let jsName = "SendIntent"
public let pluginMethods: [CAPPluginMethod] = [
CAPPluginMethod(name: "echo", returnType: CAPPluginReturnPromise)
CAPPluginMethod(name: "checkSendIntentReceived", returnType: CAPPluginReturnPromise)
]
private let implementation = SendIntent()

Expand Down

0 comments on commit 3a0a605

Please sign in to comment.