mixpanel/mixpanel-iphone

Flush Timer not started on initWithToken:launchOptions:andFlushInterval:

Closed this issue · 3 comments

The interval is set via _flushInterval , which skips the respective setter of course (which would in turn call startFlushTimer).

I noticed that because I'm working on a project where I don't have to start Mixpanel right in the AppDelegate, but much later on. So there's also no applicationDidBecomeActive to be called.
I wondered why nothing seemed to work, except when I flush myself. Then I discovered that simple fact :)

Current workaround is to set the flushInterval again after the init, manually.

mixpanel = Mixpanel(token: MixpanelToken, launchOptions: nil, andFlushInterval: 60)
mixpanel.checkForNotificationsOnActive = true
mixpanel.showNotificationOnActive = false  // Show Notifications manually.
mixpanel.checkForSurveysOnActive = true
mixpanel.showSurveyOnActive = false  // Show Surveys manually.
mixpanel.flushInterval = 60  // Workaround: startFlushTimer not called on Mixpanel init
mixpanel.flushOnBackground = true

Initially wanted to do a PR that fixes that, but wasn't sure what would be your preferred way of solving this :)

Cheers

uooq commented

After a half-day of frustration and a long interaction with some smart Mixpanel support folks, I finally got enough debugging info to figure out that this was going on.

+1 on a please fix request!

@originell
Thanks, I had same problem.

This might be easily solved in Mixpanel iOS SDK:
Method

 - (instancetype)initWithToken:(NSString *)apiToken launchOptions:(NSDictionary *)launchOptions andFlushInterval:(NSUInteger)flushInterval

sets _flushInterval, which is private NSUInteger variable of Mixpanel extension, instead of calling flushInterval property setter, which fires flush timer.
So solution is to sets:
self.flushInterval = flushInterval;
OR
call [self startFlushTimer]; after _flushInterval variable is set.

See my comment on #286