Background Fetch and Local Notification
<p>In my app, I am planning to use Local Notification and not Push Notifications. I need to check whether a transaction update is available, if YES, just notify the user with Local Notification. I have done the below steps.</p>

<ol>
<li>In <code>didFinishLaunchingWithOptions</code>, set fetch interval <code>[[UIApplication sharedApplication]setMinimumBackgroundFetchInterval:UIApplicationBackgroundFetchIntervalMinimum]</code>.</li>
<li><code>-(void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {</code> </li>
</ol>

<p>&gt; Added code for POST Request as below with my request data:</p>

<pre><code>NSURLConnection *conn = [[NSURLConnection alloc]initWithRequest:request delegate:self];

if(conn) {
    completionHandler(UIBackgroundFetchResultNewData);
}
 else {
    completionHandler(UIBackgroundFetchResultFailed);
}
</code></pre>

<ol start="3">
<li><p>After response parsing, comparing if any update is there and if any update is there, notification is displayed using the below code.</p>

<pre><code>UILocalNotification* localNotification = [[UILocalNotification alloc] init]; localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:1];
localNotification.timeZone = [NSTimeZone defaultTimeZone];
localNotification.alertTitle = @&amp;quot;SIB Mirror&amp;quot;;
localNotification.alertBody = @&amp;quot;You have a new transaction. Go to e-Statements to view it.&amp;quot;;
localNotification.timeZone = [NSTimeZone defaultTimeZone];
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
</code></pre></li>
</ol>

<p>The issue is most of the times, when phone is locked, getting error message 
&gt;Error Domain=NSURLErrorDomain Code=-1005 &quot;The network connection was lost.&quot; </p>

<p>and hence notification was not getting displayed. But when I connect Phone directly to Phone and in debug mode enable background sync, every thing works properly. </p>

<p>Kindly guide me an easy approach to do this or correct me if anything I am doing wrongly.</p>

<p>Thanks,</p>

<p>Mobile Developer.</p>