Note that there are some explanatory texts on larger screens.

plurals
  1. POUIActivity custom activityViewController crash on iPad
    primarykey
    data
    text
    <p>I have a custom UIActivity that I use in order to create a Contact to the device's AddressBook. In this UIActivity, I create an ABNewPersonViewController, put it inside a UINavigationController and return it in UIActivity's</p> <pre><code>- (UIViewController *)activityViewController </code></pre> <p>The problem is that on the iPad I get a crash due to a reference to a released UINavigationController. Messages are of type:</p> <pre><code>*** -[UINavigationController _viewControllerForSupportedInterfaceOrientations]: message sent to deallocated instance 0xa6f1660 </code></pre> <p>Also after my controller is dismissed, the iPad does not autorotate the view when the interface changes orientation.</p> <p>The code I use is the following:</p> <p><strong>In UIActivity</strong> </p> <pre><code>- (void)prepareWithActivityItems:(NSArray *)activityItems { // Prepare the AB View Controller ABRecordRef aContact = ABPersonCreate(); CFErrorRef error = NULL; ABRecordSetValue(aContact, kABPersonKindProperty, kABPersonKindOrganization, &amp;error); ABRecordSetValue(aContact, kABPersonOrganizationProperty, @"Apple Inc.", &amp;error); ABMultiValueRef phone = ABMultiValueCreateMutable(kABMultiStringPropertyType); ABMultiValueAddValueAndLabel(phone, @"+1 2345 784513", kABWorkLabel, NULL); ABRecordSetValue(aContact, kABPersonPhoneProperty, phone, &amp;error); CFRelease(phone); self.newContactVC.title = @"New company"; self.newContactVC.displayedPerson = aContact; [self.navigation setViewControllers:[NSArray arrayWithObject:self.newContactVC]]; CFRelease(aContact); } - (UIViewController *)activityViewController { return self.navigation; } // Dismisses the new-person view controller. - (void)newPersonViewController:(ABNewPersonViewController *)newPersonViewController didCompleteWithNewPerson:(ABRecordRef)person { [self activityDidFinish:YES]; } </code></pre> <p><strong>In the ViewController</strong> that calls this UIActivity</p> <pre><code>- (IBAction)showActionsSheet:(id)sender { AddToAddressBookActivity *abActivity = [[AddToAddressBookActivity alloc] init]; UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:nil applicationActivities:[NSArray arrayWithObject:abActivity]]; activityVC.excludedActivityTypes = @[UIActivityTypeAssignToContact, UIActivityTypeSaveToCameraRoll]; if (!self.popover || ![self.popover isPopoverVisible]) { self.popover = [[UIPopoverController alloc] initWithContentViewController:activityVC]; [self.popover setDelegate:self]; self.popover.passthroughViews = nil; [self.popover presentPopoverFromRect:self.showASBtn.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; } } </code></pre> <p>Any help would be greatly appreciated.</p> <p><em>Link to a demo project:</em> <a href="http://ge.tt/23MeOYq/v/0?c" rel="nofollow">http://ge.tt/23MeOYq/v/0?c</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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.
 

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