title: Omniture App Measurement for iphone getting issue when app goes background
body: <p>To Implement the Omniture Tracking in an iPhone Application, I have downloaded the AppMeasurement software from SiteCatalyst(AppMeasurement.h,libAppMeasurement.a,libAppMeasurementNoThumb.a).</p>
  
  <p>I am using Omniture's app measurement iphone library, linked the release and dev libraries. I instantiate them using the singleton method (getInstance). Implemented as below </p>
  
  <pre><code>#import "OmnitureTracking.h"
  #import "AppMeasurement.h"
  
  AppMeasurement *s = nil;
  
  
  @implementation OmnitureTracking
  
  + (void)beginTracking {
  s  = [[AppMeasurement getInstance] retain];
  s.account = @"";
  s.debugTracking = YES;
  }
  </code></pre>
  
  <p>Calling this 'beginTracking' in AppDelegate to initiate the tracking, for pagetracking implemented another method as below:</p>
  
  <pre><code>+ (void)trackViewForPage:(NSString *)pageName {
  NSLog(@"trackViewForPage::s instance::%@::",s);
  if (s == nil)
  return;
  
  [s clearVars];
  [s track:[NSDictionary dictionaryWithObjectsAndKeys:pageName, @"pageName", nil]];
  }
  </code></pre>
  
  <p>Implementaion working fine and getting below log:</p>
  
  <pre><code>2012-06-21 01:53:20.953 MyApp[857:607] App Measurement Library compile time = Aug  4 2011 16:29:52
  2012-06-21 01:53:21.418 MyApp[857:607] trackViewForPage::s instance::&lt;AppMeasurement: 0x28c4b0&gt;::
  2012-06-21 01:53:21.795 MyApp[857:607] 
  Omniture App Measurement Debug: http://MyApp.net/b/ss/MyAppiosappdev/0/OIP-2.1.2/s2253418?AQB=1&amp;ndh=1&amp;t=21/5/2012%205%3A53%3A20%204%20240&amp;vid=01398194867219045&amp;ce=UTF-8&amp;pageName=MyApp%201.2%20%281.2%29%20Launch&amp;ts=2362139876678&amp;events=event7%2Cevent5&amp;c1=D%3Dv2&amp;c2=D%3Dv6&amp;c3=D%3Dv11&amp;v2=MyApp%201.2%20%281.2%29&amp;v4=0&amp;v5=0&amp;v6=20&amp;v7=5&amp;v8=Thursday&amp;v9=4.3.3&amp;v12=D%3Dv3&amp;v13=D%3Dv3&amp;s=320x480&amp;c=24&amp;AQE=1
  </code></pre>
  
  <p>But when app goes background and enters foreground, app is crashing because of Tracking and getting the log as below:</p>
  
  <pre><code>Jun 21 03:07:41 unknown MyApp[467] &lt;Warning&gt;: trackViewForPage::s instance::(
      ""
  )::
  Jun 21 03:07:41 unknown MyApp[467] &lt;Error&gt;: -[__NSCFArray clearVars]: unrecognized selector sent to instance 0x28c4b0
  Jun 21 03:07:41 unknown MyApp[467] &lt;Error&gt;: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFArray clearVars]: unrecognized selector sent to instance 0x28c4b0'
  </code></pre>
  
  <p>"AppMeasurement" instance becoming nil or empty when app goes background and enters foreground, but I am not able to figure out whether its the Site Analyst iPhone Library issue or Coding issue.</p>
  
  <p>To handle the crash,I have done the nil check, but its not falling under nil case.</p>
  
  <p>Please help me in figuring out the "AppMeasurement" instance empty check and why "AppMeasurement" instance becoming empty when app goes background and enters foreground.</p>
  
  <p>Thanks</p>