Last active
September 14, 2018 16:36
-
-
Save ewieberappc/cd79eb35dc615dd5f118bec6d51de395 to your computer and use it in GitHub Desktop.
A basic Share Extension Test created by combining two simple test cases. Contains the ShareViewController for the extension and the index controller and view for the Titanium Project
This file contains hidden or 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
var appGroupId = 'group.com.YourGroupId'; | |
var props = Ti.App.iOS.createUserDefaults({ | |
suiteName: appGroupId | |
}); | |
var score = props.getInt('score'); | |
if (!score) | |
score = 1; | |
props.setInt('score', score); | |
// Get the shared container path | |
var sharedPath = Ti.Filesystem.directoryForSuite(appGroupId); | |
// Copy a file from the application to the shared container | |
var appFile = Ti.Filesystem.getFile(sharedPath, 'somesharefile.txt'); | |
Ti.API.error(appFile); | |
function doClick(e) { | |
score = props.getInt('score'); | |
Ti.API.error("++++++++++ score was: "+score); | |
score += 1; | |
props.setInt('score', score); | |
Ti.API.error("++++++++++ score is: "+props.getInt('score')); | |
if (appFile.createFile()) | |
appFile.write("Hello"); | |
Ti.API.error("++++++++++ data was: "+appFile.read()); | |
appFile.write($.text.value); | |
Ti.API.error("++++++++++ data is: "+appFile.read()); | |
} | |
function getImages(e) { | |
var dir = Ti.Filesystem.getFile(sharedPath); | |
var dir_files = dir.getDirectoryListing(); | |
var views = []; | |
for (var i=0;i<dir_files.length;i++){ | |
if (dir_files[i].indexOf("image") == -1) | |
continue; | |
var view = Ti.UI.createImageView({ | |
image: Ti.Filesystem.getFile(sharedPath, dir_files[i]) | |
}); | |
views.push(view); | |
} | |
$.scroll.views = views; | |
} | |
$.index.open(); |
This file contains hidden or 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
<Alloy> | |
<Window class="container"> | |
<TextField id="text" borderColor="black" top="30%" value="This is from the app" /> | |
<Button onClick="doClick" top="40%">OK</Button> | |
<Button onClick="getImages" top="50%">Get Images</Button> | |
<ScrollableView id="scroll" showPagingControl="true" top="60%" height="40%"/> | |
</Window> | |
</Alloy> |
This file contains hidden or 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
<!-- Replace items in [] --> | |
<ios> | |
<team-id>[TEAM ID HERE]</team-id> | |
<capabilities> | |
<app-groups> | |
<group>[group.com.YourGroupId]</group> | |
</app-groups> | |
</capabilities> | |
<extensions> | |
<extension projectPath="[Path to extension's .xcodeproj]"> | |
<target name="[Target Name]"> | |
<provisioning-profiles> | |
<device>[Device-UDID]</device> | |
<dist-appstore/> | |
<dist-adhoc/> | |
</provisioning-profiles> | |
</target> | |
</extension> | |
</extensions> | |
<key>NSExtensionAttributes</key> | |
<dict> | |
<key>NSExtensionActivationRule</key> | |
<dict> | |
<key>NSExtensionActivationSupportsImageWithMaxCount</key> | |
<integer>10</integer> | |
<key>NSExtensionActivationSupportsMovieWithMaxCount</key> | |
<integer>1</integer> | |
<key>NSExtensionActivationSupportsWebURLWithMaxCount</key> | |
<integer>1</integer> | |
</dict> | |
</dict> | |
<plist> | |
<dict> | |
<key>CFBundleURLTypes</key> | |
<array> | |
<dict> | |
<key>CFBundleTypeRole</key> | |
<string>Editor</string> | |
<key>CFBundleURLName</key> | |
<string>[com.Your.AppId]</string> | |
</dict> | |
</array> | |
</dict> | |
</plist> | |
</ios> |
Great. Would have been good if tiapp.xml was included too.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
I am trying to implement this, and I already got it working if the app is not in background mode, but otherwise, I am getting an error. There is something about the code that I don't really get. When you call the performSelector function, where is that openURL handler?
I think that my error has something to do with this. This is the error log:
[ERROR] : The application has crashed with an uncaught exception 'NSInvalidArgumentException'.
[ERROR] : Reason:
[ERROR] : Expected 'sourceApplication' to be NSString. Please verify you are passing in 'sourceApplication' from your app delegate (not the UIApplication* parameter). If your app delegate implements iOS 9's application:openURL:options:, you should pass in options[UIApplicationOpenURLOptionsSourceApplicationKey].
[ERROR] : Stack trace:
[ERROR] : 0 CoreFoundation 0x0000000116043af3 __exceptionPreprocess + 147
[ERROR] : 1 libobjc.A.dylib 0x00000001155df141 objc_exception_throw + 48
[ERROR] : 2 Caramba 0x000000010ebf869f __77-[FBSDKApplicationDelegate application:openURL:sourceApplication:annotation:]_block_invoke + 0
[ERROR] : 3 CoreFoundation 0x0000000115fe2c2c CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER + 12
[ERROR] : 4 CoreFoundation 0x0000000115fe2b29 _CFXRegistrationPost + 425
[ERROR] : 5 CoreFoundation 0x0000000115fe2892 ___CFXNotificationPost_block_invoke + 50
[ERROR] : 6 CoreFoundation 0x0000000115fa6162 -[_CFXNotificationRegistrar find:object:observer:enumerator:] + 1826
[ERROR] : 7 CoreFoundation 0x0000000115fa52c1 _CFXNotificationPost + 673
[ERROR] : 8 Foundation 0x000000010fb26b24 -[NSNotificationCenter postNotificationName:object:userInfo:] + 66
[ERROR] : 9 Caramba 0x000000010eb249c3 -[TiApp application:openURL:options:] + 403
[ERROR] : 10 UIKit 0x0000000111462a1d __45-[UIApplication _applicationOpenURL:payload:]_block_invoke + 813
[ERROR] : 11 UIKit 0x0000000111462456 -[UIApplication _applicationOpenURL:payload:] + 707
[ERROR] : 12 UIKit 0x000000011146f6c5 -[UIApplication _handleNonLaunchSpecificActions:forScene:withTransitionContext:completion:] + 6705
[ERROR] : 13 UIKit 0x0000000111474383 -[UIApplication _handleApplicationActivationWithScene:transitionContext:completion:] + 2406
[ERROR] : 14 UIKit 0x0000000111473786 -[UIApplication _handleApplicationLifecycleEventWithScene:transitionContext:completion:] + 461
[ERROR] : 15 UIKit 0x0000000111455921 __70-[UIApplication scene:didUpdateWithDiff:transitionContext:completion:]_block_invoke + 159
[ERROR] : 16 UIKit 0x0000000111455599 -[UIApplication scene:didUpdateWithDiff:transitionContext:completion:] + 978
[ERROR] : 17 UIKit 0x0000000111973d9c -[UIApplicationSceneClientAgent scene:handleEvent:withCompletion:] + 509
[ERROR] : 18 FrontBoardServices 0x000000011d955f81 __80-[FBSSceneImpl updater:didUpdateSettings:withDiff:transitionContext:completion:]_block_invoke.376 + 205
[ERROR] : 19 FrontBoardServices 0x000000011d9835f6 FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK + 24
[ERROR] : 20 FrontBoardServices 0x000000011d98346d -[FBSSerialQueue _performNext] + 186
[ERROR] : 21 FrontBoardServices 0x000000011d9837f6 -[FBSSerialQueue _performNextFromRunLoopSource] + 45
[ERROR] : 22 CoreFoundation 0x0000000115fe9c01 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17
[ERROR] : 23 CoreFoundation 0x0000000115fcf0cf __CFRunLoopDoSources0 + 527
[ERROR] : 24 CoreFoundation 0x0000000115fce5ff __CFRunLoopRun + 911
[ERROR] : 25 CoreFoundation 0x0000000115fce016 CFRunLoopRunSpecific + 406
[ERROR] : 26 GraphicsServices 0x000000011796fa24 GSEventRunModal + 62
[ERROR] : 27 UIKit 0x00000001114580d4 UIApplicationMain + 159
[ERROR] : 28 Caramba 0x000000010e94fd44 main + 100
[ERROR] : 29 libdyld.dylib 0x000000011a1af65d start + 1
In a native code, usually this error would be related to the app delegate openURL method, but in Titanium I don't know how to solve this, I have spent 2 days already.
Could you help me, please?
Thank you very much!