Dérivé de ShareMe, plantage sur iPad mais pas sur iPhone

Bonjour à tous,

j’ai implémenté la fonction shareMe du cours dans mon app en cours de dev et ça fonctionne très bien sur mon iPhone mais ça plante sur l’iPad et je ne comprends pas pourquoi.
J’ai ça:

et erreur console suivante:
2018-01-31 08:22:32.664616+0100 Calc4relais[1657:2033358] [LayoutConstraints] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don’t want.
Try this:
(1) look at each constraint and try to figure out which you don’t expect;
(2) find the code that added the unwanted constraint or constraints and fix it.
(
« <NSLayoutConstraint:0x1c409d790 UILabel:0x101a18ad0’Fille’.width == 70 (active)> »,
« <NSLayoutConstraint:0x1c02882a0 Calc4relais.UISwitchCustom:0x101b2ad90.width == 70 (active)> »,
« <NSLayoutConstraint:0x1c409d8d0 UILabel:0x101a18db0’Gar\U00e7on’.width == 70 (active)> »,
« <NSLayoutConstraint:0x1c409d970 H:[UILabel:0x101a18ad0’Fille’]-(10)-[Calc4relais.UISwitchCustom:0x101b2ad90] (active)> »,
« <NSLayoutConstraint:0x1c409d9c0 H:[Calc4relais.UISwitchCustom:0x101b2ad90]-(10)-[UILabel:0x101a18db0’Gar\U00e7on’] (active)> »,
« <NSLayoutConstraint:0x1c409db50 H:[UIStackView:0x101a184d0]-(21)-| (active, names: ‹ | ›:UITableViewCellContentView:0x101a182e0 )> »,
« <NSLayoutConstraint:0x1c409dba0 H:|-(21)-[UIStackView:0x101a184d0] (active, names: ‹ | ›:UITableViewCellContentView:0x101a182e0 )> »,
« <NSLayoutConstraint:0x1c0289dd0 ‹ UISV-canvas-connection › UIStackView:0x101a184d0.leading == UILabel:0x101a18ad0’Fille’.leading (active)> »,
« <NSLayoutConstraint:0x1c0289e70 ‹ UISV-canvas-connection › H:[UILabel:0x101a18db0’Gar\U00e7on’]-(0)-| (active, names: ‹ | ›:UIStackView:0x101a184d0 )> »,
« <NSLayoutConstraint:0x1c028a820 ‹ UIView-Encapsulated-Layout-Width › UITableViewCellContentView:0x101a182e0.width == 972 (active)> »
)

Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x1c409d8d0 UILabel:0x101a18db0’Garçon’.width == 70 (active)>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2018-01-31 08:22:32.673782+0100 Calc4relais[1657:2033358] [MC] Lazy loading NSBundle MobileCoreServices.framework
2018-01-31 08:22:32.676214+0100 Calc4relais[1657:2033358] [MC] Loaded MobileCoreServices.framework
2018-01-31 08:22:32.703144+0100 Calc4relais[1657:2033358] [LayoutConstraints] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don’t want.
Try this:
(1) look at each constraint and try to figure out which you don’t expect;
(2) find the code that added the unwanted constraint or constraints and fix it.
(
« <NSLayoutConstraint:0x1c8099e60 UILabel:0x101f1a350.width == 50 (active)> »,
« <NSLayoutConstraint:0x1c028c1c0 ‹ UISV-fill-proportionally › UILabel:0x101f1a350.width == 0 (active)> »
)

Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x1c8099e60 UILabel:0x101f1a350.width == 50 (active)>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2018-01-31 08:22:32.715086+0100 Calc4relais[1657:2033358] [LayoutConstraints] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don’t want.
Try this:
(1) look at each constraint and try to figure out which you don’t expect;
(2) find the code that added the unwanted constraint or constraints and fix it.
(
« <NSLayoutConstraint:0x1c809a6d0 UILabel:0x101f1cc70.width == 50 (active)> »,
« <NSLayoutConstraint:0x1c42828f0 ‹ UISV-fill-proportionally › UILabel:0x101f1cc70.width == 0 (active)> »
)

Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x1c809a6d0 UILabel:0x101f1cc70.width == 50 (active)>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2018-01-31 08:22:32.724239+0100 Calc4relais[1657:2033358] [LayoutConstraints] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don’t want.
Try this:
(1) look at each constraint and try to figure out which you don’t expect;
(2) find the code that added the unwanted constraint or constraints and fix it.
(
« <NSLayoutConstraint:0x1c809aea0 UILabel:0x101f1f710.width == 50 (active)> »,
« <NSLayoutConstraint:0x1c809db00 ‹ UISV-fill-proportionally › UILabel:0x101f1f710.width == 0 (active)> »
)

Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x1c809aea0 UILabel:0x101f1f710.width == 50 (active)>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2018-01-31 08:22:32.734070+0100 Calc4relais[1657:2033358] [LayoutConstraints] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don’t want.
Try this:
(1) look at each constraint and try to figure out which you don’t expect;
(2) find the code that added the unwanted constraint or constraints and fix it.
(
« <NSLayoutConstraint:0x1c809b670 UILabel:0x101f21db0.width == 50 (active)> »,
« <NSLayoutConstraint:0x1c4283d40 ‹ UISV-fill-proportionally › UILabel:0x101f21db0.width == 0 (active)> »
)

Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x1c809b670 UILabel:0x101f21db0.width == 50 (active)>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2018-01-31 08:22:32.777094+0100 Calc4relais[1657:2033358] [LayoutConstraints] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don’t want.
Try this:
(1) look at each constraint and try to figure out which you don’t expect;
(2) find the code that added the unwanted constraint or constraints and fix it.
(
« <NSLayoutConstraint:0x1c4288e30 ‹ UISV-canvas-connection › UIStackView:0x101a227a0.leading == UITextField:0x102861600.leading (active)> »,
« <NSLayoutConstraint:0x1c4288e80 ‹ UISV-canvas-connection › H:[UILabel:0x101a237c0]-(0)-| (active, names: ‹ | ›:UIStackView:0x101a227a0 )> »,
« <NSLayoutConstraint:0x1c4288f70 ‹ UISV-fill-proportionally › UITextField:0x102861600.width == UIStackView:0x101a227a0.width (active)> »,
« <NSLayoutConstraint:0x1c4289010 ‹ UISV-fill-proportionally › UILabel:0x101a237c0.width == 0 (active)> »,
« <_UISystemBaselineConstraint:0x1c42a1320 ‹ UISV-spacing › H:[UITextField:0x102861600]-(NSLayoutAnchorConstraintSpace(8))-[UILabel:0x101a237c0] (active)> »
)

Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x1c4289010 ‹ UISV-fill-proportionally › UILabel:0x101a237c0.width == 0 (active)>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2018-01-31 08:22:32.778070+0100 Calc4relais[1657:2033358] [LayoutConstraints] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don’t want.
Try this:
(1) look at each constraint and try to figure out which you don’t expect;
(2) find the code that added the unwanted constraint or constraints and fix it.
(
« <NSLayoutConstraint:0x1c4288e30 ‹ UISV-canvas-connection › UIStackView:0x101a227a0.leading == UITextField:0x102861600.leading (active)> »,
« <NSLayoutConstraint:0x1c4288e80 ‹ UISV-canvas-connection › H:[UILabel:0x101a237c0]-(0)-| (active, names: ‹ | ›:UIStackView:0x101a227a0 )> »,
« <NSLayoutConstraint:0x1c4288f70 ‹ UISV-fill-proportionally › UITextField:0x102861600.width == UIStackView:0x101a227a0.width (active)> »,
« <_UISystemBaselineConstraint:0x1c42a1320 ‹ UISV-spacing › H:[UITextField:0x102861600]-(NSLayoutAnchorConstraintSpace(8))-[UILabel:0x101a237c0] (active)> »
)

Will attempt to recover by breaking constraint
<_UISystemBaselineConstraint:0x1c42a1320 ‹ UISV-spacing › H:[UITextField:0x102861600]-(NSLayoutAnchorConstraintSpace(8))-[UILabel:0x101a237c0] (active)>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2018-01-31 08:22:32.784402+0100 Calc4relais[1657:2033358] [LayoutConstraints] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don’t want.
Try this:
(1) look at each constraint and try to figure out which you don’t expect;
(2) find the code that added the unwanted constraint or constraints and fix it.
(
« <NSLayoutConstraint:0x1c42805f0 H:[UILabel:0x101a246f0]-(0)-[UILabel:0x101a249d0’%’] (active)> »,
« <NSLayoutConstraint:0x1c428a140 ‹ UISV-spacing › H:[UILabel:0x101a246f0]-(20)-[UILabel:0x101a249d0’%’] (active)> »
)

Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x1c428a140 ‹ UISV-spacing › H:[UILabel:0x101a246f0]-(20)-[UILabel:0x101a249d0’%’] (active)>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2018-01-31 08:22:32.784845+0100 Calc4relais[1657:2033358] [LayoutConstraints] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don’t want.
Try this:
(1) look at each constraint and try to figure out which you don’t expect;
(2) find the code that added the unwanted constraint or constraints and fix it.
(
« <NSLayoutConstraint:0x1c42805a0 H:[UILabel:0x101a24410’\U00e9cart:’]-(10)-[UILabel:0x101a246f0] (active)> »,
« <NSLayoutConstraint:0x1c428a0a0 ‹ UISV-spacing › H:[UILabel:0x101a24410’\U00e9cart:’]-(20)-[UILabel:0x101a246f0] (active)> »
)

Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x1c428a0a0 ‹ UISV-spacing › H:[UILabel:0x101a24410’écart:’]-(20)-[UILabel:0x101a246f0] (active)>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2018-01-31 08:22:40.084297+0100 Calc4relais[1657:2033358] [MC] System group container for systemgroup.com.apple.configurationprofiles path is /private/var/containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles
2018-01-31 08:22:40.087295+0100 Calc4relais[1657:2033358] [MC] Reading from public effective user settings.
2018-01-31 08:22:54.915912+0100 Calc4relais[1657:2033358] [MC] Filtering mail sheet accounts for bundle ID: fr.pro4eps.Calc4relais, source account management: 1
2018-01-31 08:22:54.929650+0100 Calc4relais[1657:2033358] [MC] Filtering mail sheet accounts for bundle ID: fr.pro4eps.Calc4relais, source account management: 2
2018-01-31 08:22:55.193479+0100 Calc4relais[1657:2033358] [MC] Filtering mail sheet accounts for bundle ID: fr.pro4eps.Calc4relais, source account management: 1
2018-01-31 08:22:55.194537+0100 Calc4relais[1657:2033358] [MC] Filtering mail sheet accounts for bundle ID: fr.pro4eps.Calc4relais, source account management: 2
2018-01-31 08:22:55.368353+0100 Calc4relais[1657:2033358] *** Terminating app due to uncaught exception ‹ NSGenericException ›, reason: ‹ Your application has presented a UIActivityViewController (<UIActivityViewController: 0x1020e9a00>). In its current trait environment, the modalPresentationStyle of a UIActivityViewController with this style is UIModalPresentationPopover. You must provide location information for this popover through the view controller’s popoverPresentationController. You must provide either a sourceView and sourceRect or a barButtonItem. If this information is not known when you present the view controller, you may provide it in the UIPopoverPresentationControllerDelegate method -prepareForPopoverPresentation. ›
*** First throw call stack:
(0x185156364 0x18439c528 0x18f353fec 0x18ea5ac18 0x18ea586dc 0x18e97ab3c 0x18e96def0 0x18e6ff54c 0x1850fdedc 0x1850fb894 0x1850fbe50 0x18501be58 0x186ec8f84 0x18e77067c 0x100a2b380 0x184b3856c)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)

La fonction de partage via UIActivity controller est déclenchée par un Right Bar Button item qui est connecté (et lui seul, j’ai bien vérifié).

Voici le code au cas ou ça viendrai de là mais je n’en ai pas l’impression:

@IBAction func shareTypedText() {
if let nameC1:String = ui_prenomC1.text, let nameC2:String = ui_prenomC2.text, let nameC3:String = ui_prenomC3.text, let nameC4:String = ui_prenomC4.text, let timeC1:String = ui_timeC1.text, let timeC2:String = ui_timeC2.text, let timeC3:String = ui_timeC3.text, let timeC4:String = ui_timeC4.text, let number1:String = ui_number1.text, let number2:String = ui_number2.text,let number3:String = ui_number3.text,let number4:String = ui_number4.text, let marque1:String = ui_marquesTextfield.text, let marque2:String = ui_marques2 .text, let marque3:String = ui_marques3.text, let noteRelais:String = notePerfRelais.text, let noteFinale:String = ui_noteFinale.text, let tempsTh:String = ui_timeTheorique.text, let tempsRea:String = ui_timeRealTest.text, let gap:String = ui_gap.text, let purcentGap:String = displayGap.text, let noteC1:String = ui_noteC1.text, let noteC2:String = ui_noteC2.text,let noteC3:String = ui_noteC3.text,let noteC4:String = ui_noteC4.text, let noteGap:String = ui_noteEff.text {

// date formatée
let _dateNow = Date()
let _frenchDate = DateFormatter()
_frenchDate.dateStyle = .medium
_frenchDate.timeStyle = .medium
_frenchDate.locale = Locale(identifier: « FR-fr »)
let dateFormat = _frenchDate.string(from: _dateNow)

        let message = "\n Le \(dateFormat) \n Configuration testée: \(number1)-\(number2)-\(number3)-\(number4) \n -\(nameC1): \(timeC1) (\(noteC1)) \n -\(nameC2): \(timeC2) (\(noteC2)) \n -\(nameC3): \(timeC3) (\(noteC3)) \n -\(nameC4): \(timeC4) (\(noteC4)) \n\n Marque transmission 1: \(marque1) pieds \n Marque transmission 2: \(marque2) pieds \n Marque transmission 3: \(marque3) pieds \n\n Valeur du relais théorique: \(tempsTh) \n Temps réel du relais: \(tempsRea)\n Amélioration de: \(gap) soit \(purcentGap) (\(noteGap)) \n Note du 4x50m: \(noteRelais) \n\n \(noteFinale)"
        let share = UIActivityViewController(activityItems: [message], applicationActivities: nil)
        present(share, animated: true, completion: nil)
    }
    
}

Si quelqu’un voit le truc, je suis preneur. Merci!!!

Tu as un joli souci de contraintes :smiley:

Pour savoir quelle(s) contrainte(s) pose(nt) problème, je te conseille de leur donner un identifiant, car ensuite dans la console, c’est cet identifiant qui apparaîtra plutôt que NSLayoutConstraint:0x1c409dba0 qui est très compliqué ensuite à repérer.

Ensuite, une par une, c’est à toi de voir pourquoi la contrainte n’est pas satisfaisante et les erreurs vont ensuite disparaître les unes après les autres.
Comme d’habitude, sinon, partage ton code (après avoir renommé les contraintes), je jetterai un coup d’oeil :wink:

1 « J'aime »

Salut schitpoun,

je sais que j’ai des problèmes de contraintes mais ça plante uniquement quand je clique sur le bouton de partage. T’es sur que ça vient pas de là:
‘NSGenericException’, reason: ‘Your application has presented a UIActivityViewController (<UIActivityViewController: 0x1020e9a00>). In its current trait environment, the modalPresentationStyle of a UIActivityViewController with this style is UIModalPresentationPopover. You must provide location information for this popover through the view controller’s popoverPresentationController. You must provide either a sourceView and sourceRect or a barButtonItem. If this information is not known when you present the view controller, you may provide it in the UIPopoverPresentationControllerDelegate method -prepareForPopoverPresentation.’

Ah ouais, exact, je me suis concentré sur les erreurs de contraintes, y’en avait tellement que je suis passé à côté de l’erreur qui fait planter ton app :smile:
Je trouvais ça aussi bizarre qu’un souci de contraintes te faisait pointer l’erreur sur le AppDelegate, je dois me réveiller un peu !

Bref, essaye d’ajouter ces deux lignes avant le present pour prendre en charge l’iPad :

if let popoverController = share.popoverPresentationController { popoverController.barButtonItem = sender }

25

Ah, le sender ne doit pas être défini.

Alors : popoverController.barButtonItem = navigationItem.rightBarButtonItem

Il me semble que tu as dit que c’était déclenché par un bouton dans la barre à droite.

je viens de tester sur le simulateur et ça ne semble pas planter. Par contre je n’ai pas compris le truc. il s’agit d’une déclaration à faire pour préciser si c’est un iPad? c’est ça?
Merci pour la solution en tous cas! :wink:

Oui, en fait sur iPad, comme tu fais une présentation en popover (ce qui est un peu bizarre au passage, mais ça a certainement du sens dans ton expérience si tu l’as choisi !), il ne sait pas bien se présenter sur l’écran de destination donc tu dois lui définir un controller pour qu’il soit capable de le faire.

https://developer.apple.com/documentation/uikit/uipopoverpresentationcontroller

Je n’ai rien fait pour que ça soit en propover. Je voulais que ça fasse comme sur l’iPhone en modal. Manifestement, le même code ne produit pas les mêmes effets en fonction du device… J’ai suivi pas à pas le tutoriel de Maxime à ce sujet.

Ah mais je viens de tilter, le share c’est l’actionSheet qui se déclenche en bas de l’iPhone et te permet d’envoyer ça sur iMessage, WhatsApp, etc. ?

Dans ces cas là, c’est manifestement inévitable (je ne le savais pas !) de passer sur du popover !
Je pensais que c’était une simple transition entre écrans.

D’ailleurs, ça se fait soit comme je te l’ai indiqué, soit en sourceView et sourceRect apparemment :slight_smile:

D’ac! Super. Merci. Je retiens pour la suite!! :kissing:
Merci encore pour ta réactivité!

1 « J'aime »