Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-19441] useractivitywillsave does not fire before continuing on other device

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionInvalid
Resolution Date2015-09-03T08:09:30.000+0000
Affected Version/sRelease 5.0.0
Fix Version/sn/a
ComponentsiOS
Labelshandoff
ReporterFokke Zandbergen
AssigneeEric Merriman
Created2015-08-31T15:03:55.000+0000
Updated2017-03-20T21:42:36.000+0000

Description

The [Ti 5.0 sample app](https://github.com/appcelerator-developer-relations/appc-sample-ti500) will show that the useractivitywillsave event only fires when you call becomeCurrent(). It does not fire before/when you continue the activity on another device, like the [docs](https://appcelerator.github.io/appc-docs/latest/#!/api/Titanium.App.iOS.UserActivity-property-needsSave) say it will when you set needSave to true. This leaves you with no way to update the activity before the other devices takes over.

Comments

  1. Fokke Zandbergen 2015-09-02

    I ran some tests that showed that useractivitywillsave will fire when: * You call becomeCurrent() on an activity. * Before the current activity is sent for continuation on another devices ([as Apple says](https://developer.apple.com/library/prerelease/ios/documentation/Foundation/Reference/NSUserActivity_Class/#//apple_ref/occ/instp/NSUserActivity/needsSave)) but *only* if since that activity became current you have made a change (updated userInfo) to it. This is weird, since you'd expect the event would give you the chance to (only then) update the activity with e.g. the current text of the email you were composing. If you have to update the activity in order for the event to fire, then what is there left to do when it gets called?
  2. Fokke Zandbergen 2015-09-02

    From Apple's [Handoff Programming Guide: Best Practices](https://developer.apple.com/library/mac/documentation/UserExperience/Conceptual/Handoff/AdoptingHandoff/AdoptingHandoff.html#//apple_ref/doc/uid/TP40014338-CH2-SW14): {quote}To update the activity object’s userInfo dictionary efficiently, configure its delegate and set its needsSave property to YES whenever the userInfo needs updating. At appropriate times, Handoff invokes the delegate’s userActivityWillSave: callback, and the delegate can update the activity state.{quote} [This StackOverflow answer](http://stackoverflow.com/a/26792196/4626813) has a sample that demonstrates this:
       - (NSUserActivity *)customUserActivity 
       {
           if (!_customUserActivity) {
               _customUserActivity = [[NSUserActivity alloc] initWithActivityType:@"com.company.app.edit"];
               _customUserActivity.title = @"Editing in app";
               _customUserActivity.delegate = self;
           }
       
           return _customUserActivity;
       }
       
       - (void)textViewDidBeginEditing:(UITextView *)textView 
       {
           [self.customUserActivity becomeCurrent];
       }
       
       - (void)textViewDidChange:(UITextView *)textView 
       {
           self.customUserActivity.needsSave = YES;
       }
       
       - (BOOL)textViewShouldEndEditing:(UITextView *)textView 
       {
           [self.customUserActivity invalidate];
       
           return YES;
       }
       
       - (void)userActivityWillSave:(NSUserActivity *)userActivity 
       {
           [userActivity addUserInfoEntriesFromDictionary:@{ @"editText" : self.textView.text }];
       }
       
    So it seems we (and Apple:)) should update our guide/reference to make clear that you need to call needsSave every time you have a change and then update the activity with the actual change when asked via the useractivitywillsave event.
  3. Chee Kiat Ng 2015-09-03

    Thanks Fokke. closing as invalid and will open a tidoc ticket.
  4. Lee Morris 2017-03-20

    Closing ticket as invalid.

JSON Source