Deprecated this article (Reference to New article)
Ich habe untersucht, wie eine URL-Verknüpfung unter iOS durchgeführt wird. Da es in kivy-ios einen Teil der Zusammenarbeit mit mail APP gab, kann es durch Bezugnahme darauf implementiert werden.
Import / Vorverarbeitung
try:
from urllib.parse import quote
except ImportError:
from urllib import quote
from pyobjus import autoclass, objc_str
from pyobjus.dylib_manager import load_framework
load_framework('/System/Library/Frameworks/UIKit.framework')
NSURL = autoclass('NSURL')
NSString = autoclass('NSString')
UIApplication = autoclass('UIApplication')
Anruf (Mail)
uri = "mailto:[email protected]?subject=text&body=body"
nsurl = NSURL.alloc().initWithString_(objc_str(uri))
UIApplication.sharedApplication().openURL_(nsurl)
Lesen Sie Referenzseite und definieren Sie das URL-Schema mit XCode. Jetzt wird es von anderen Anwendungen aufgerufen, aber die meisten Anwendungen möchten ein Argument annehmen. Kivy-ios scheint jedoch standardmäßig keine Argumente zu erhalten, daher muss es von einem Mechanismus empfangen werden. kivy empfängt jetzt iOS openUrl-Ereignisse beim Generieren von Drop-File-Ereignissen. Dies kann jedoch nicht empfangen werden, da das Ereignis nicht an die Anwendung übertragen wurde. Es ist einfacher, dies umzuleiten, als ein neues Ereignis hinzuzufügen. Leiten Sie es also um. Der Fixspeicherort befindet sich unter tmp im Verzeichnis kivy-ios.
kivy/kivy/core/window/sdl.pyx
.
.
.
ctypedef struct SDL_TouchFingerEvent:
long touchId
long fingerId
unsigned char state
unsigned short x
unsigned short y
short dx
short dy
unsigned short pressure
# add start
ctypedef struct SDL_DropEvent:
unsigned int timestamp
char *file
# add end
ctypedef struct SDL_Event:
unsigned int type
SDL_MouseMotionEvent motion
SDL_MouseButtonEvent button
SDL_WindowEvent window
SDL_KeyboardEvent key
SDL_TextInputEvent text
SDL_TouchFingerEvent tfinger
# add start
SDL_DropEvent drop
# add end
# Events
int SDL_QUIT
int SDL_WINDOWEVENT
int SDL_SYSWMEVENT
int SDL_KEYDOWN
int SDL_KEYUP
int SDL_MOUSEMOTION
int SDL_MOUSEBUTTONDOWN
int SDL_MOUSEBUTTONUP
int SDL_TEXTINPUT
int SDL_FINGERDOWN
int SDL_FINGERUP
int SDL_FINGERMOTION
# add start
int SDL_DROPFILE
# add end
.
.
.
elif event.type == SDL_TEXTINPUT:
s = PyUnicode_FromString(<char *>event.text.text)
return ('textinput', s)
# add start
elif event.type == SDL_DROPFILE:
s = PyUnicode_FromString(<char *>event.drop.file)
action = ('dropfile', s)
return action
# add end
else:
if __debug__:
print('receive unknown sdl event', event.type)
pass
.
.
.
kivy/kivy/core/window/window_sdl.py
.
.
.
def _mainloop(self):
EventLoop.idle()
while True:
event = sdl.poll()
.
.
.
elif action == 'textinput':
key = args[0][0]
# XXX on IOS, keydown/up don't send unicode anymore.
# With latest sdl, the text is sent over textinput
# Right now, redo keydown/up, but we need to seperate both call
# too. (and adapt on_key_* API.)
self.dispatch('on_key_down', key, None, args[0],
self.modifiers)
self.dispatch('on_keyboard', None, None, args[0],
self.modifiers)
self.dispatch('on_key_up', key, None, args[0],
self.modifiers)
# add start
elif action == 'dropfile':
self.dispatch('on_dropfile', args[0])
# add end
# # video resize
# elif event.type == pygame.VIDEORESIZE:
.
.
.
# XXX FIXME wait for sdl resume
while True:
event = sdl.poll()
if event is False:
continue
if event is None:
continue
action, args = event[0], event[1:]
if action == 'quit':
EventLoop.quit = True
self.close()
break
elif action == 'windowrestored':
break
# add start
elif action == 'dropfile':
app.dispatch('on_dropfile', args[0])
# add end
.
.
.
kivy/kivy/app.py
.
.
.
# Return the current running App instance
_running_app = None
# modify start ( add on_dropfile )
__events__ = ('on_start', 'on_stop', 'on_pause', 'on_resume', 'on_dropfile')
# modify end
def __init__(self, **kwargs):
App._running_app = self
self._app_directory = None
self._app_name = None
.
.
.
def on_resume(self):
'''Event handler called when your application is resuming from
the Pause mode.
.. versionadded:: 1.1.0
.. warning::
When resuming, the OpenGL Context might have been damaged / freed.
This is where you can reconstruct some of your OpenGL state
e.g. FBO content.
'''
pass
# add start
def on_dropfile(self, filename):
'''Event called when a file is dropped on the application.
.. warning::
This event is currently used only on MacOSX with a patched version
of pygame, but is left in place for further evolution (ios,
android etc.)
.. versionadded:: 1.2.0
'''
pass
# add end
@staticmethod
def get_running_app():
.
.
.
main.py
.
.
.
def on_dropfile(self, filename): <----Hier wird es möglich, das durch URL-Verknüpfung aufgerufene Argument zu erhalten.
print self.mydecode(filename)
def mydecode(self, value):
if isinstance(value, unicode):
value = value.encode('raw_unicode_escape')
value = urllib.unquote(value)
return value
if __name__ == '__main__':
TestApp().run()
Recommended Posts