Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Dynamic Libraries. Could it potentially Work?
-
Now that iOS 8 and 9 support the use of dynamically loaded frameworks (not just the ones made by apple) would it be possible to load a custom framework inside Pythonista.
I have tested this idea with frameworks provided by apple, but I am interested to know if I created my own would I be able to use it?
Using this example from here I can see what libraries are loaded.
From again from here I can load iOS builtin frameworks. The python implementation. -
Hope so. I still want OpenCV for a project I'm working on. As far as computer vision tasks go it's on the easier side, but still very hard to do with PIL.
-
It should be possible to load custom frameworks if you code-sign them properly with an Apple Developer certificate. See the discussionin this thread.
-
Would the Apple Developer certificate that Apple now provide to all Xcode 7.x users that allows you to put iOS apps onto a physical device classify as valid, or would I still need to pay the $100 a year fee?
Also is there any way I can get the developer disk image of the latest iOS 9.1 beta without re-downloading Xcode 7 again?
EDIT: Don't worry about the developer disk image, I got it (through re-downloading Xcode, unfortunately) -
@omz is this an issue with code signing or something completely different?
ERROR 3587 Failed to run preflight on the Framework: /private/var/mobile/Containers/Shared/AppGroup/877D6E00-D22C-4407-9A69-C27FA4B9356A/Documents/OpenCV/Frameworks/Realm.framework The bundle “Realm” couldn’t be loaded because it is damaged or missing necessary resources. Try reinstalling the bundle. dlopen_preflight(/private/var/mobile/Containers/Shared/AppGroup/877D6E00-D22C-4407-9A69-C27FA4B9356A/Documents/OpenCV/Frameworks/Realm.framework/Realm): no suitable image found. Did find: /private/var/mobile/Containers/Shared/AppGroup/877D6E00-D22C-4407-9A69-C27FA4B9356A/Documents/OpenCV/Frameworks/Realm.framework/Realm: mmap() errno=1 validating first page of '/private/var/mobile/Containers/Shared/AppGroup/877D6E00-D22C-4407-9A69-C27FA4B9356A/Documents/OpenCV/Frameworks/Realm.framework/Realm' None
Using the following method to load.
# coding: utf-8 import os import sys import ctypes from ctypes import util from objc_util import * def loadLibrary(library): bundle = ObjCClass("NSBundle").bundleWithPath_(library) preflightError = ctypes.c_void_p() preflight = bundle.preflightAndReturnError_(ctypes.byref(preflightError)) if not preflight: error = ObjCInstance(preflightError) userinfo = error.userInfo() print 'ERROR', error.code() print 'Failed to run preflight on the Framework: %s' % userinfo['NSBundlePath'] print error.localizedDescription() print error.localizedRecoverySuggestion() print userinfo['NSDebugDescription'] return loadError = ctypes.c_void_p() loaded = bundle.loadAndReturnError_(ctypes.byref(loadError)) if not loaded: error = ObjCInstance(preflightError) userinfo = error.userInfo() print 'ERROR', error.code() print 'Failed to load the Framework: %s' % userinfo['NSBundlePath'] print error.localizedDescription() print error.localizedRecoverySuggestion() return print 'Loaded Library:', bundle.bundlePath() print 'Version:', bundle.versionNumber() print 'Executable:', bundle.executablePath() print 'Identifier:', bundle.bundleIdentifier() principalClass = bundle.principalClass() if principalClass is None: print 'So close. But sadly this library has no principalClass' return bundle, None principalClass = ObjCInstance(principalClass) return bundle, principalClass if __name__ == '__main__': pui = loadLibrary('/System/Library/Frameworks/PhotosUI.framework') print pui p = os.path.abspath('/var/mobile/Containers/Bundle/Application/38B17589-94F5-48DB-A9ED-B992692EF890/Pythonista.app/Frameworks/PythonistaKit.framework') pykit = loadLibrary(p) print pykit dyl = loadLibrary('Frameworks/Realm.framework') print dyl
-
After further testing I have been able to get it down to this
ERROR 3587 Failed to run preflight on the Framework: /private/var/mobile/Containers/Shared/AppGroup/877D6E00-D22C-4407-9A69-C27FA4B9356A/Documents/OpenCV/Frameworks/Realm.framework The bundle “Realm” couldn’t be loaded because it is damaged or missing necessary resources. Try reinstalling the bundle. dlopen_preflight(/private/var/mobile/Containers/Shared/AppGroup/877D6E00-D22C-4407-9A69-C27FA4B9356A/Documents/OpenCV/Frameworks/Realm.framework/Realm): no suitable image found. Did find: /private/var/mobile/Containers/Shared/AppGroup/877D6E00-D22C-4407-9A69-C27FA4B9356A/Documents/OpenCV/Frameworks/Realm.framework/Realm: mmap() errno=1 validating first page of '/private/var/mobile/Containers/Shared/AppGroup/877D6E00-D22C-4407-9A69-C27FA4B9356A/Documents/OpenCV/Frameworks/Realm.framework/Realm' None
Which after doing a bit of research is related to code signing. So while it would be possible to have dynamically loaded libraries in iOS 8 and greater, they will only work if they have been code signed by @omz.
-
Huh. @omz might be able to provide code signed libraries without any bindings in the app, so people could use them. That'd be interesting. You could prevent app size increasing by using iOS 9's new feature that allows parts of the app to be downloaded as needed.
-
Cethric, did you sign the frameworks with your own developer key?
-
I did not sign that one. However I also tried with a blank Xcode iOS Cocoa Touch Framework which I did sign using the iPhone Developer key which Apple supply for free for any iOS 8 or greater application for development purposes. (It was introduced in the Xcode 7 beta) and I got the same result from it.
-
see https://forum.omz-software.com/topic/1984/realm-io-module
It is unclear to me whether this approach worked because it was signed with th same key used for pythonista
-
I am not quite sure what you mean?
@omz was able to use it as it was his key but I cannot because the keys are different. (Is what I think you mean by that...) -
He means he's unsure if it'd work for any developer key besides that of @omz
-
right, i am saying try the exact steps listed by omz, except use your key.
-
Following what @omz does exactly, fails for my returning
False
on load. -
This could be a great potential use case for In App Purchases in the future ;)