TextExpander / TextExpanderTouchSDK

TextExpander touch SDK
85 stars 13 forks source link

SMTEDelegateController's - expansionStatusForceLoad:snippetCount:loadDate:error: returns a snippetCount of 0 until first expansion takes place or you exit & re-enter the app #5

Closed dburr closed 9 years ago

dburr commented 10 years ago

I'm seeing an odd behavior with the SDK, specifically SMTEDelegateController's -expansionStatusForceLoad:snippetCount:loadDate:error:. When an app first starts, it always returns a snippetCount of 0 (but it correctly returns YES indicating that TE is enabled, and the loadDate is correct), until an expansion takes place. After the first expansion, it starts returning the correct snippetCount. Also, exiting & re-entering the app (by clicking the Home button and then tapping the app's icon) also results in a correct snippetCount. If I re-load my snippets by calling - getSnippets, when I get bounced back to the app, I also get a correct snippetCount as well. It's just after the initial startup of an app (i.e. a cold start, not resuming, etc.) that snippetCount returns 0 (but again loadDate is correct).

SmilinBrian commented 10 years ago

We are probably trying to do too much with one method -- you have to read the comment in SMTEDelegateController.h carefully.

The "YES TE is enabled, but snippetCount == 0 at startup" is almost certainly because you called it with ForceLoad: NO. If you do not force loading, this method examines the data without loading it because loading can be expensive if the user has hundreds of snippets. So what it tells you by returning YES with ForceLoad: NO and the snippets not yet loaded is, essentially, "there is snippet data here that can probably be read successfully".

In the most common case, when the SMTEDelegateController textViewShouldBeginEditing: delegate message is received for a UITextView, it kicks off an asynchronous load of the snippet data (if not yet loaded) so that it can detect snippet abbreviations when the user begins typing. This is so your app startup can be as quick as possible.

Regarding the loading of the snippets after exiting & re-entering the app (snippetCount changes): Probably now that TextExpander touch requires iOS 7, we should now take away the SMTEDelegateController willEnterForeground method. The comment on that one does not make it clear, but you do not need to call that on iOS 7, at least now that Reminders can no longer be used for snippet transfer. In this case, willEnterForeground is kicking off an asynchronous load of the snippets because the stored date of the snippet data does not match the "loaded" date (which is nil if the data has not yet been loaded).

In other words, if your app is iOS 7-only, you no longer need to call willEnterForeground for the delegate.

I hope this makes sense. I'm updating the comment on willEnterForeground for the next SDK release -- consider it deprecated but we still support apps on iOS 6 for now.

dburr commented 10 years ago

Ah, I understand now, thanks for the clarification. I mistakenly thought that setting forceLoad to YES forced the actual call out to TextExpander.app to load the latest snippets. Thanks for the clarification as well as for the note about willEnterForeground.