mixpanel/mixpanel-iphone — pull request #54 by mightykan (2013-03-19 03:41:35+00:00)
Title: Rare Crash in the `deviceInfoProperties` Method

##### Description

The `CTTelephonyNetworkInfo` class is allocated, initialized and autoreleased in the `deviceInfoProperties` class method. I suspect since the `CTTelephonyNetworkInfo` is being autoreleased in a class method, it causes a deallocated reference crash.

##### Prerequisites

* An iPhone with an active cellular data connection. This problem will not show up on an iPhone that does not have an active and current cellular data connection. _Note_: This issue was only tested on an iPhone 5. Other iPhones, or iPads with cellular data connection, might also be affected.

* Turn off the flush interval in Mixpanel:
```objc
[[Mixpanel sharedInstance] setFlushInterval:0]
```

* Set up your app to flush all the events as the app goes to the background after a 30 second delay:
```objc
- (void)backgrounding
{
...
[self performSelector:@selector(flushEventsAsTask) withObject:nil afterDelay:30];
...
}
- (void)flushEventsAsTask
{
[[Mixpanel sharedInstance] flush];
}
```

##### Steps to Reproduce

The following steps have to be performed very quickly:

1. Make sure your device is using the cellular data connection. WiFi will not reproduce this issue.
2. Background the app and quickly go to the Settings app. It helps to have the Settings app in the recently used apps tray. Hit the Home button twice to bring up the recently used apps tray and choose Settings.
3. Turn on Airplane mode. Wait until the small airplane icon flies in and there is no indication of an active connection to a data/cell network.
4. Turn Airplane mode off and quickly switch back to the app by hitting the Home button twice to bring up the recently used apps tray and tapping the app icon.

##### Actual Results

2 out of 3 times, the app crashes as soon as it comes to the foreground with a message about a deallocated CTType.

##### Expected Results

No crashes and all the queued events being reported.

##### Solution

After a lot of trial and error, I discovered that manually releasing `CTTelephonyNetworkInfo` in the `deviceInfoProperties` seems to solve this issue:

```objc
CTTelephonyNetworkInfo *networkInfo = [[CTTelephonyNetworkInfo alloc] init];
CTCarrier *carrier = [networkInfo subscriberCellularProvider];
[networkInfo release];
```

This pull request contains this change.