Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><em>UPDATE</em> After using a support ticket to Apple, they confirmed that calling sendData too often and with too much data can cause disconnects.</p> <p>I have had disconnects when hitting break points and when backgrounding. Since the break points won't happen on the app store, you need to handle the backgrounding case by beginning a background task when your app is about to enter the background. Then end this task when your app comes back to the foreground. On iOS 7 this gives you about 3 background minutes which is better than nothing.</p> <p>An additional strategy would be to schedule a local notification for maybe 15 seconds before your background time expires by using <code>[[UIApplication sharedApplication] backgroundTimeRemaining]</code>, that way you can bring the user back into the app before it suspends and the multi peer framework has to be shutdown. Perhaps the local notification would warn them that their session will expire in 10 seconds or something...</p> <p>If the background task expires and the app is still in the background, you have to tear down everything related to multi-peer connectivity, otherwise you will get crashes.</p> <pre><code>- (void) createExpireNotification { [self killExpireNotification]; if (self.connectedPeerCount != 0) // if peers connected, setup kill switch { NSTimeInterval gracePeriod = 20.0f; // create notification that will get the user back into the app when the background process time is about to expire NSTimeInterval msgTime = UIApplication.sharedApplication.backgroundTimeRemaining - gracePeriod; UILocalNotification* n = [[UILocalNotification alloc] init]; self.expireNotification = n; self.expireNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:msgTime]; self.expireNotification.alertBody = TR(@"Text_MultiPeerIsAboutToExpire"); self.expireNotification.soundName = UILocalNotificationDefaultSoundName; self.expireNotification.applicationIconBadgeNumber = 1; [UIApplication.sharedApplication scheduleLocalNotification:self.expireNotification]; } } - (void) killExpireNotification { if (self.expireNotification != nil) { [UIApplication.sharedApplication cancelLocalNotification:self.expireNotification]; self.expireNotification = nil; } } - (void) applicationWillEnterBackground { self.taskId = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^ { [self shutdownMultiPeerStuff]; [[UIApplication sharedApplication] endBackgroundTask:self.taskId]; self.taskId = UIBackgroundTaskInvalid; }]; [self createExpireNotification]; } - (void) applicationWillEnterForeground { [self killExpireNotification]; if (self.taskId != UIBackgroundTaskInvalid) { [[UIApplication sharedApplication] endBackgroundTask:self.taskId]; self.taskId = UIBackgroundTaskInvalid; } } - (void) applicationWillTerminate { [self killExpireNotification]; [self stop]; // shutdown multi-peer } </code></pre> <p>You'll also want this handler in your MCSession delegate due to Apple bug:</p> <pre><code>- (void) session:(MCSession*)session didReceiveCertificate:(NSArray*)certificate fromPeer:(MCPeerID*)peerID certificateHandler:(void (^)(BOOL accept))certificateHandler { if (certificateHandler != nil) { certificateHandler(YES); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload