create ios app using kivy to run in background (a clock alarm)

554 views
Skip to first unread message

sosfos

unread,
Mar 28, 2016, 1:38:05 AM3/28/16
to Kivy users support
I am going to create a clock alarm for ios, but encountered problems when I realized that apple has a lot of limitations for run code in background.

I don't have much experiences with obj-c or ios development, but just started to play kivy for a while.

Any one have same problem and got resolved?

Thank you!

ZenCODE

unread,
Mar 28, 2016, 2:24:24 AM3/28/16
to Kivy users support
Yup. Both iOS and Android pause/stop executing apps when you switch to another one. On Android, it was fairly straightforward using a service to get around this but not so for iOS....

I don't think anyone has done this with Kivy yet. We are going to have to do such a thing for background downloads, but we're not quite there yet. On Android, one can create a service with Kivy, but there is currently no equivalent for iOS. I'm afraid you will need to get your hand dirty and try using PyObjus to execute in the background.

https://pyobjus.readthedocs.org/en/latest/

https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html

Another option would be to create timers.

http://stackoverflow.com/questions/7004472/ios-creating-using-interval-specific-timers

Timer would certainly be simpler, but I'm not sure if that would suit your needs?

eli teofil

unread,
Mar 28, 2023, 7:07:23 PM3/28/23
to Kivy users support
hi, i am attempting to create a background task for my kivy-ios app. The code i have so for is this:
from pyobjus import autoclass, protocol, objc_str, selector, objc_b
from pyobjus.dylib_manager import make_dylib, load_dylib
from pyobjus.dylib_manager import load_framework, INCLUDE
load_framework('/System/Library/Frameworks/BackgroundTasks.framework')
NSString = autoclass('NSString')
NSObject = autoclass('NSObject')
uniqueIdent = NSString.alloc().initWithUTF8String_('org.kivy.fleetdriver.trackdriver')
NSDate = autoclass('NSDate').alloc().init()
#print("date:",NSDate)
#BGTask = autoclass('BGTask').alloc()
#print("my bgtask instance",dir(BGTask))
#NSObject = autoclass('NSObject')
#print("uniqe indentifier:",uniqueIdent)
#BGTaskScheduler = NSObject
BGTaskScheduler = autoclass('BGTaskScheduler').alloc()
#BGTaskScheduler.init()
print("my background scheduler instance:", dir(BGTaskScheduler))
BGAppRefreshTaskRequest = autoclass("BGAppRefreshTaskRequest").alloc()
#print("my BGAppRefrfesh instance:",dir(BGAppRefreshTaskRequest))
#print("setting identifier")
#request(uniqueIdent)
request = BGAppRefreshTaskRequest
request.identifier = uniqueIdent
request.init()
request.earliestBeginDate = NSDate
try:
BGTaskScheduler.shared.submit(request)
except Exception as e:
print(e)
How ever when i run the app in Xcode Iphone simulator  it complains
that the BGTaskScheduler has no attribute named shared is also not in the list when I dir(BGTaskScheduler)). Check the output here:
my background scheduler instance: ['.cxx_destruct', 'CAMLType', 'CAMLTypeForKey_', 'CAMLTypeSupportedForKey_', 'CA_addValue_multipliedBy_', 'CA_archivingValueForKey_', 'CA_copyNumericValue_', 'CA_copyRenderValue', 'CA_distanceToValue_', 'CA_interpolateValue_byFraction_', 'CA_interpolateValues___interpolator_', 'CA_prepareRenderValue', 'CA_roundToIntegerFromValue_', 'CA_validateValue_forKey_', 'CKAssignToContainerWithID_', 'CKDescription', 'CKDescriptionPropertiesWithPublic_private_shouldExpand_', 'CKExpandedDescription', 'CKHashedDescription', 'CKPropertiesDescription', 'CKPropertiesDescriptionStringFromProperties_', 'CKSingleLineDescription', 'CKStatusReport', 'CalClassName', 'NSRepresentation', 'RBSIsXPCObject', 'SCN_setupDisplayLinkWithQueue_screen_', '_CKDescriptionWithExpansion_', '_ICSStringWithOptions_', '_ICSStringWithOptions_appendingToString_', '_NSItemProviderTypeCoercion_coercedUIImageValueFromNSDataValue_error_', '_NSItemProviderTypeCoercion_coercedUIImageValueFromNSURLValue_error_', '___tryRetain_OA', '__autorelease_OA', '__autorotationSanityCheckObjectFromSource_selector_', '__class__', '__cls_storage', '__copy_properties__', '__dealloc_zombie', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getter___lock', '__getter___permittedIdentifiers', '__getter___registrations', '__getter___runningTasksMap', '__gt__', '__hash__', '__im_afterDelay_', '__im_afterDelay_modes_', '__im_getInvocation_', '__im_onDetachedThread', '__im_onMainThread', '__im_onMainThreadIfNecessary', '__im_onThread_', '__im_onThread_immediateForMatchingThread_', '__init__', '__init_subclass__', '__isKindOfUIView', '__ivarDescriptionForClass_', '__le__', '__lt__', '__methodDescriptionForClass_', '__module__', '__ne__', '__new__', '__objcclass__', '__propertyDescriptionForClass_', '__pyx_vtable__', '__reduce__', '__reduce_ex__', '__release_OA', '__repr__', '__retain_OA', '__setattr__', '__setstate__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_accessibilityFinalize', '_accessibilityGetContextID', '_addObserver_forProperty_options_context_', '_allowsDirectEncoding', '_applyTraitStorageRecordsForTraitCollection_', '_cfTypeID', '_changeValueForKey_key_key_usingBlock_', '_changeValueForKey_usingBlock_', '_changeValueForKeys_count_maybeOldValuesDict_maybeNewValuesDict_usingBlock_', '_conformsToProtocolNamed_', '_connectInterfaceBuilderEventConnection_', '_copyDescription', '_cplCopyProperties_fromOtherObject_withCopyBlock_', '_destroyObserverList', '_didChangeValuesForKeys_', '_didEndKeyValueObserving', '_handleAppLaunch', '_implicitObservationInfo', '_init', '_intents_compareValue_relation_', '_intents_displayImageForLanguage_', '_intents_displayImageWithLocalizer_', '_intents_enumerateObjectsOfClass_withBlock_', '_intents_indexingRepresentation', '_intents_isValidKey_', '_intents_localizedCopyForLanguage_', '_intents_localizedCopyWithLocalizer_', '_intents_readableDescriptionForLanguage_', '_intents_readableDescriptionForLanguage_withMetadata_', '_intents_readableDescriptionWithLocalizer_', '_intents_readableDescriptionWithLocalizer_metadata_', '_intents_readableSubtitleForLanguage_', '_intents_readableSubtitleForLanguage_withMetadata_', '_intents_readableSubtitleWithLocalizer_', '_intents_readableSubtitleWithLocalizer_metadata_', '_intents_readableTitleForLanguage_', '_intents_readableTitleForLanguage_withMetadata_', '_intents_readableTitleWithLocalizer_', '_intents_readableTitleWithLocalizer_metadata_', '_intents_setterForPropertyWithName_', '_internalAccessibilityAttributedHint', '_internalAccessibilityAttributedLabel', '_internalAccessibilityAttributedUserInputLabels', '_internalAccessibilityAttributedValue', '_internalSetAccessibilityAttributedHint_', '_internalSetAccessibilityAttributedLabel_', '_internalSetAccessibilityAttributedUserInputLabels_', '_internalSetAccessibilityAttributedValue_', '_isDeallocating', '_isGestureType_', '_isKVOA', '_isMKClusterAnnotation', '_isRunningTaskOfClass_', '_isToManyChangeInformation', '_ivarDescription', '_keyboardActivate', '_keyboardActivateEventDown_', '_localClassNameForClass', '_lock', '_mapkit_implementationOfSelector_isFromSubclassOfClass_', '_mapkit_isInternalAnnotation', '_mapkit_isInternalAnnotationView', '_methodDescription', '_mf_checkToAllowExclusiveLocksWithLock_', '_mf_checkToAllowLock_', '_mf_checkToAllowOrderingWithLock_', '_mf_checkToAllowStrictProgressionWithLock_', '_mf_dumpLockCallStacks_ordering_', '_mf_lockOrderingForType_', '_mf_ntsCheckToAllowLock_', '_mf_ntsIsLocked', '_na_addNotificationObserverProxy_', '_na_removeNotificationObserverProxy_', '_notifyObserversForKeyPath_change_', '_notifyObserversOfChangeFromValuesForKeys_toValuesForKeys_', '_observerStorage', '_observerStorageOfSize_', '_overrideUseFastBlockObservers', '_pendingChangeNotificationsArrayForKey_create_', '_permittedIdentifiers', '_pl_prettyDescription', '_pl_prettyDescriptionWithIndent_', '_propertyDescription', '_queueForRegistration_', '_receiveBox_', '_registrations', '_removeObserver_forProperty_', '_runTask_registration_', '_runningTasks', '_runningTasksMap', '_setLock_', '_setPermittedIdentifiers_', '_setRegistrations_', '_setRunningTasksMap_', '_setTraitStorageList_', '_shortMethodDescription', '_simulateExpirationForTaskWithIdentifier_', '_simulateLaunchForTaskWithIdentifier_', '_traitStorageList', '_tryRetain', '_ui_descriptionBuilder', '_uikit_applyValueFromTraitStorage_forKeyPath_', '_uikit_valueForTraitCollection_', '_uikit_variesByTraitCollections', '_unsafe_registerForTaskWithIdentifier_usingQueue_launchHandler_', '_unsafe_registrationForIdentifier_', '_unsafe_submitTaskRequest_error_', '_web_description', '_webkit_invokeOnMainThread', '_willBeginKeyValueObserving', '_willChangeValuesForKeys_', 'accessibilityActivate', 'accessibilityActivationPoint', 'accessibilityAssistiveTechnologyFocusedIdentifiers', 'accessibilityAttributedHint', 'accessibilityAttributedLabel', 'accessibilityAttributedUserInputLabels', 'accessibilityAttributedValue', 'accessibilityContainer', 'accessibilityContainerType', 'accessibilityCustomActions', 'accessibilityCustomRotors', 'accessibilityDecrement', 'accessibilityDragSourceDescriptors', 'accessibilityDropPointDescriptors', 'accessibilityElementAtIndex_', 'accessibilityElementCount', 'accessibilityElementDidBecomeFocused', 'accessibilityElementDidLoseFocus', 'accessibilityElementIsFocused', 'accessibilityElements', 'accessibilityElementsHidden', 'accessibilityFrame', 'accessibilityHeaderElements', 'accessibilityHint', 'accessibilityIdentification', 'accessibilityIdentifier', 'accessibilityIncrement', 'accessibilityLabel', 'accessibilityLanguage', 'accessibilityLocalizedStringKey', 'accessibilityNavigationStyle', 'accessibilityPath', 'accessibilityPerformEscape', 'accessibilityPerformMagicTap', 'accessibilityRespondsToUserInteraction', 'accessibilityScroll_', 'accessibilitySetIdentification_', 'accessibilityTextualContext', 'accessibilityTraits', 'accessibilityUserInputLabels', 'accessibilityValue', 'accessibilityViewIsModal', 'addChainedObservers_', 'addObservationTransformer_', 'addObserverBlock_', 'addObserver_', 'addObserver_forKeyPath_options_context_', 'addObserver_forObservableKeyPath_', 'allowSafePerformSelector', 'allowsWeakReference', 'ams_generateDescriptionWithSubObjects_', 'associatedObjectForKey_', 'autoContentAccessingProxy', 'autorelease', 'awakeAfterUsingCoder_', 'awakeFromNib', 'boolValueSafe', 'boolValueSafe_', 'bs_encoded', 'bs_isPlistableType', 'bs_secureEncoded', 'cancelAllTaskRequests', 'cancelTaskRequestWithIdentifier_', 'ck_bindInStatement_atIndex_', 'classForArchiver', 'classForCoder', 'classForKeyedArchiver', 'classForPortCoder', 'className', 'cn_updateDictionaryForKey_withChanges_', 'conformsToProtocol_', 'copy', 'cplCopyPropertiesFromObject_withCopyBlock_', 'cplCopyProperties_fromObject_withCopyBlock_', 'cplDecodePropertiesFromCoder_', 'cplDeepCopy', 'cplEncodePropertiesWithCoder_', 'cplFullDescription', 'cplHash', 'cplIsEqual_', 'cplIsEqual_withEqualityBlock_', 'cplProperties_areEqualToPropertiesOf_diffTracker_withEqualityBlock_', 'cplProperties_areEqualToPropertiesOf_withEqualityBlock_', 'cplSpecialHash', 'cplSpecialIsEqual_', 'currentContextCanExecuteSelector_', 'da_addNullRunLoopSourceAndPerformSelector_withObject_afterDelay_inModes_', 'da_performSelectorThatDoesntAffectRetainCount_withObject_', 'dcaxRespondsToSelector_fromExtrasProtocol_', 'dcaxValueForKey_', 'dealloc', 'debugDescription', 'debugHierarchyAdditionalGroupingIDs', 'debugHierarchyObjectsInGroupWithID_outOptions_', 'debugHierarchyPropertyDescriptions', 'debugHierarchyValueForPropertyWithName_', 'defaultAccessibilityTraits', 'description', 'descriptionAtIndent_', 'dictionaryWithValuesForKeys_', 'didChangeValueForKey_', 'didChangeValueForKey_withSetMutation_usingObjects_', 'didChange_valuesAtIndexes_forKey_', 'disallowSafePerformSelector', 'doesNotRecognizeSelector_', 'doubleValueSafe', 'doubleValueSafe_', 'ef_observeKeyPath_options_autoCancelToken_usingBlock_', 'ef_observeKeyPath_options_usingBlock_', 'ef_onScheduler_', 'enc', 'encodeWithCAMLWriter_', 'finalize', 'finishObserving', 'forwardInvocation_', 'forwardingTargetForSelector_', 'fromMainThreadPostNotificationName_object_userInfo_', 'fromNotifySafeThreadPerformSelector_withObject_', 'fromNotifySafeThreadPostNotificationName_object_userInfo_', 'getPendingTaskRequestsWithCompletionHandler_', 'get_address', 'handleInvalidExecutionContextForSelector_requirement_', 'hash', 'if_setValueIfNonNil_forKey_', 'if_setValueIfYES_forKey_', 'implementsSelector_', 'indexOfAccessibilityElement_', 'init', 'initFromPQLResultSet_error_', 'initWithCPLArchiver_', 'int64ValueSafe', 'int64ValueSafe_', 'isAccessibilityElement', 'isAccessibilityElementByDefault', 'isElementAccessibilityExposedToInterfaceBuilder', 'isEqual_', 'isFault', 'isKindOfClass_', 'isMemberOfClass_', 'isNSArray__', 'isNSCFConstantString__', 'isNSData__', 'isNSDate__', 'isNSDictionary__', 'isNSNumber__', 'isNSObject__', 'isNSOrderedSet__', 'isNSSet__', 'isNSString__', 'isNSTimeZone__', 'isNSValue__', 'isNull', 'isProxy', 'methodDescriptionForSelector_', 'methodForSelector_', 'methodSignatureForSelector_', 'mf_exclusiveLocks', 'mf_lock', 'mf_lockOrdering', 'mf_lockWithPriority', 'mf_objectWithHighest_', 'mf_strictLockOrdering', 'mf_tryLock', 'mf_tryLockWithPriority', 'mf_unlock', 'multicaster_queueForSelector_', 'mutableArrayValueForKeyPath_', 'mutableArrayValueForKey_', 'mutableCopy', 'mutableOrderedSetValueForKeyPath_', 'mutableOrderedSetValueForKey_', 'mutableSetValueForKeyPath_', 'mutableSetValueForKey_', 'na_addNotificationBlockObserverForName_object_queue_usingBlock_', 'na_addNotificationBlockObserverForObject_keyPath_options_usingBlock_', 'na_associatedObjectForDescriptor_', 'na_removeNotificationBlockObserver_', 'na_setAssociatedObject_assocatedObjectDescriptor_', 'observationInfo', 'observeValueForKeyPath_ofObject_change_context_', 'oclass', 'okToNotifyFromThisThread', 'pep_afterDelay_', 'pep_getInvocation_', 'pep_onDetachedThread', 'pep_onMainThread', 'pep_onMainThreadIfNecessary', 'pep_onOperationQueue_', 'pep_onOperationQueue_priority_', 'pep_onThread_', 'pep_onThread_immediateForMatchingThread_', 'performBlockOnMainThreadSynchronously_', 'performSelectorInBackground_withObject_', 'performSelectorOnMainThread_withObject_waitUntilDone_', 'performSelectorOnMainThread_withObject_waitUntilDone_modes_', 'performSelector_', 'performSelector_object_afterDelay_', 'performSelector_onThread_withObject_waitUntilDone_', 'performSelector_onThread_withObject_waitUntilDone_modes_', 'performSelector_withObject_', 'performSelector_withObject_afterDelay_', 'performSelector_withObject_afterDelay_ignoreMenuTracking_', 'performSelector_withObject_afterDelay_inModes_', 'performSelector_withObject_withObject_', 'pkaxRespondsToSelector_fromExtrasProtocol_', 'pkaxValueForKey_', 'pl_briefDescription', 'plistArchiveWithCPLArchiver_', 'postNotificationWithDescription_', 'prepareForInterfaceBuilder', 'receiveObservedError_', 'receiveObservedValue_', 'registerForTaskWithIdentifier_usingQueue_launchHandler_', 'release', 'releaseOnMainThread', 'removeObservation_', 'removeObservation_forObservableKeyPath_', 'removeObserver_forKeyPath_', 'removeObserver_forKeyPath_context_', 'replacementObjectForArchiver_', 'replacementObjectForCoder_', 'replacementObjectForKeyedArchiver_', 'replacementObjectForPortCoder_', 'respondsToSelector_', 'retain', 'retainCount', 'retainWeakReference', 'self', 'setAccessibilityActivationPoint_', 'setAccessibilityAttributedHint_', 'setAccessibilityAttributedLabel_', 'setAccessibilityAttributedUserInputLabels_', 'setAccessibilityAttributedValue_', 'setAccessibilityContainerType_', 'setAccessibilityContainer_', 'setAccessibilityCustomActions_', 'setAccessibilityCustomRotors_', 'setAccessibilityDragSourceDescriptors_', 'setAccessibilityDropPointDescriptors_', 'setAccessibilityElementsHidden_', 'setAccessibilityElements_', 'setAccessibilityFrame_', 'setAccessibilityHeaderElements_', 'setAccessibilityHint_', 'setAccessibilityIdentifier_', 'setAccessibilityLabel_', 'setAccessibilityLanguage_', 'setAccessibilityNavigationStyle_', 'setAccessibilityPath_', 'setAccessibilityRespondsToUserInteraction_', 'setAccessibilityTextualContext_', 'setAccessibilityTraits_', 'setAccessibilityUserInputLabels_', 'setAccessibilityValue_', 'setAccessibilityViewIsModal_', 'setAssociatedObject_forKey_', 'setIsAccessibilityElement_', 'setNilValueForKey_', 'setObservationInfo_', 'setObservation_forObservingKeyPath_', 'setShouldGroupAccessibilityChildren_', 'setValue_forKeyPath_', 'setValue_forKey_', 'setValue_forUndefinedKey_', 'setValuesForKeysWithDictionary_', 'shouldGroupAccessibilityChildren', 'storedAccessibilityActivationPoint', 'storedAccessibilityContainerType', 'storedAccessibilityElementsHidden', 'storedAccessibilityFrame', 'storedAccessibilityNavigationStyle', 'storedAccessibilityRespondsToUserInteraction', 'storedAccessibilityTraits', 'storedAccessibilityViewIsModal', 'storedClassNameForCPLArchiver_', 'storedIsAccessibilityElement', 'storedShouldGroupAccessibilityChildren', 'stringValueSafe', 'stringValueSafe_', 'submitTaskRequest_error_', 'superclass', 'supportsBSXPCSecureCoding', 'supportsRBSXPCSecureCoding', 'toPBCodable', 'uiPresentationManager', 'un_safeBoolValue', 'upcase_first_letter', 'utf8ValueSafe', 'utf8ValueSafe_', 'validateValue_forKeyPath_error_', 'validateValue_forKey_error_', 'valueForKeyPath_', 'valueForKey_', 'valueForUndefinedKey_', 'wfName', 'wfType', 'willChangeValueForKey_', 'willChangeValueForKey_withSetMutation_usingObjects_', 'willChange_valuesAtIndexes_forKey_', 'zone']
'BGTaskScheduler' object has no attribute 'shared'

If I do BGTaskScheduler.init() than Xcode says:
*** Assertion failure in -[BGTaskScheduler init], BGTaskScheduler.m:112
2023-03-28 18:01:12.227855-0500 fleetdriver[19847:564250] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Do not directly instantiate; use the shared scheduler instead'
*** First throw call stack:
(
0   CoreFoundation                      0x00007fff2043a126 __exceptionPreprocess + 242
1   libobjc.A.dylib                     0x00007fff20177f78 objc_exception_throw + 48
2   CoreFoundation                      0x00007fff20439f4f +[NSException raise:format:] + 0
3   Foundation                          0x00007fff207881ca -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 191
4   BackgroundTasks                     0x00007fff4a63633f -[BGTaskScheduler init] + 101
5   fleetdriver                         0x0000000101650eec ffi_call_unix64 + 76
6   ???                                 0x00006000031a16a0 0x0 + 105553168307872
)
libc++abi.dylib: terminating with uncaught exception of type NSException
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Do not directly instantiate; use the shared scheduler instead'
terminating with uncaught exception of type NSException
CoreSimulator 857.14 - Device: iPhone 8 (FE3220DE-9123-46AF-B736-D1B36B3149ED) - Runtime: iOS 14.1 (18A8394) - DeviceType: iPhone 8

can somebody point me into the right direction or share some examples.Thank you

eli teofil

unread,
Mar 28, 2023, 7:11:35 PM3/28/23
to Kivy users support

Robert

unread,
Mar 28, 2023, 7:59:54 PM3/28/23
to Kivy users support
Try asking here https://discord.gg/n9wtdf6c

Danylo Romanov

unread,
Jun 1, 2023, 5:34:01 AM6/1/23
to Kivy users support
Hi all! Have faced with the same limitation of Kivy IOS. Are there any solutions to the issue found?

Robert

unread,
Jun 1, 2023, 12:36:34 PM6/1/23
to Kivy users support
No Kivy-ios experience here, try asking on Discord https://discord.gg/hdER8YG9

kaukone...@gmail.com

unread,
Aug 21, 2023, 2:17:17 AM8/21/23
to Kivy users support
> On Android, it was fairly straightforward using a service to get around this but not so for iOS....

Could someone give an example with Android how to do this?
br. Markus

Robert

unread,
Aug 21, 2023, 12:26:53 PM8/21/23
to Kivy users support

eli teofil

unread,
Oct 6, 2023, 12:08:23 AM10/6/23
to Kivy users support
I think i got this background app thing working
The reason i was looking into iOS background tasks was to enable my app to track driver’s location even if the app is in the background. So the steps below might not work for your use case.
So far the steps below work in the iPhone simulator i do not have a real device to test.
 I followed all the steps a outlined by Apple in this guide https://developer.apple.com/documentation/uikit/app_and_environment/scenes/preparing_your_ui_to_run_in_the_background/using_background_tasks_to_update_your_app?language=objc
In my kivy app the on _location and on_status methods are decorated with the @mainthread which means the gps tracking stuff runs on the main kivy thread
@mainthread
def on_location(self,**kwargs):
@mainthread
def on_status(self, stype, status):
In the plyer implementation for iOS, pryer/plyer/platforms/ios/gps.py,   i’ve added three additional flags to the CLLocationManager
def _start(self, **kwargs):
        self._location_manager.delegate = self
        self._location_manager.allowsBackgroundLocationUpdates = True
        self._location_manager.pausesLocationUpdatesAutomatically = False
        self._location_manager.requestWhenInUseAuthorization()
In my Kivy app i call the newSubmitAppRefresh() in the on_pause app method
def on_pause(self):      
        print("app paused")
        self.newSubmitAppRefresh()
Below is the code of the newSubmitAppRefresh():
 def newSubmitAppRefresh(self):
        from pyobjus import autoclass, protocol, objc_str, selector, objc_b, objc_py_types

        from pyobjus.dylib_manager import make_dylib, load_dylib
        from pyobjus.dylib_manager import load_framework, INCLUDE
        load_framework('/System/Library/Frameworks/BackgroundTasks.framework')
        BGTaskScheduler = autoclass('BGTaskScheduler')
        if not hasattr(self, 'registerForTaskWithIdentifier_usingQueue_launchHandler_'):
            self._location_manager = BGTaskScheduler.alloc()
        uniqueIdent = objc_str('org.kivy.fleetdriver.trackdriver')
        schedulerResult = BGTaskScheduler.registerForTaskWithIdentifier_usingQueue_launchHandler_(uniqueIdent, None, self.testLaunchHandler())
        print("BGTaskScheduler.registerForTaskWithIdentifier result: ",schedulerResult)
One thing to note is that the uniqueIdent is exactly the same with the one set in Xcode under the permitted identifiers. In ios settings the app needs the permissions like in the image
Screen Shot 2023-10-05 at 9.24.46 PM.png
The BGTaskScheduler.registerForTaskWithIdentifier_usingQueue_launchHandler_ returns False in my case but strange enough it still works and by works i mean the app keeps running even though i am opening multiple other apps. I had it running for about an hour without any problem.

eli teofil

unread,
Oct 6, 2023, 12:12:05 AM10/6/23
to Kivy users support
Reply all
Reply to author
Forward
0 new messages