質問編集履歴
2
Xcodeのクラッシュレポート
test
CHANGED
File without changes
|
test
CHANGED
@@ -401,3 +401,257 @@
|
|
401
401
|
|
402
402
|
|
403
403
|
ご教示いただければ幸いです。
|
404
|
+
|
405
|
+
|
406
|
+
|
407
|
+
|
408
|
+
|
409
|
+
### Xcode クラッシュレポート
|
410
|
+
|
411
|
+
```ここに言語を入力
|
412
|
+
|
413
|
+
#import "PLCrashReporter.h"
|
414
|
+
|
415
|
+
#import "CrashReporter.h"
|
416
|
+
|
417
|
+
|
418
|
+
|
419
|
+
#include "UndefinePlatforms.h"
|
420
|
+
|
421
|
+
#include <mach-o/ldsyms.h>
|
422
|
+
|
423
|
+
#include "RedefinePlatforms.h"
|
424
|
+
|
425
|
+
|
426
|
+
|
427
|
+
extern "C" NSString* UnityGetCrashReportsPath();
|
428
|
+
|
429
|
+
|
430
|
+
|
431
|
+
static NSUncaughtExceptionHandler* gsCrashReporterUEHandler = NULL;
|
432
|
+
|
433
|
+
|
434
|
+
|
435
|
+
static decltype(_mh_execute_header) * sExecuteHeader = NULL;
|
436
|
+
|
437
|
+
extern "C" void UnitySetExecuteMachHeader(const decltype(_mh_execute_header)* header)
|
438
|
+
|
439
|
+
{
|
440
|
+
|
441
|
+
sExecuteHeader = header;
|
442
|
+
|
443
|
+
}
|
444
|
+
|
445
|
+
|
446
|
+
|
447
|
+
extern "C" const decltype(_mh_execute_header) * UnityGetExecuteMachHeader() {
|
448
|
+
|
449
|
+
return sExecuteHeader;
|
450
|
+
|
451
|
+
}
|
452
|
+
|
453
|
+
|
454
|
+
|
455
|
+
static void SavePendingCrashReport()
|
456
|
+
|
457
|
+
{
|
458
|
+
|
459
|
+
if (![[UnityPLCrashReporter sharedReporter] hasPendingCrashReport])
|
460
|
+
|
461
|
+
return;
|
462
|
+
|
463
|
+
|
464
|
+
|
465
|
+
NSFileManager *fm = [NSFileManager defaultManager];
|
466
|
+
|
467
|
+
NSError *error;
|
468
|
+
|
469
|
+
|
470
|
+
|
471
|
+
if (![fm createDirectoryAtPath: UnityGetCrashReportsPath() withIntermediateDirectories: YES attributes: nil error: &error])
|
472
|
+
|
473
|
+
{
|
474
|
+
|
475
|
+
::printf("CrashReporter: could not create crash report directory: %s\n", [[error localizedDescription] UTF8String]);
|
476
|
+
|
477
|
+
return;
|
478
|
+
|
479
|
+
}
|
480
|
+
|
481
|
+
|
482
|
+
|
483
|
+
NSData *data = [[UnityPLCrashReporter sharedReporter] loadPendingCrashReportDataAndReturnError: &error];
|
484
|
+
|
485
|
+
if (data == nil)
|
486
|
+
|
487
|
+
{
|
488
|
+
|
489
|
+
::printf("CrashReporter: failed to load crash report data: %s\n", [[error localizedDescription] UTF8String]);
|
490
|
+
|
491
|
+
return;
|
492
|
+
|
493
|
+
}
|
494
|
+
|
495
|
+
|
496
|
+
|
497
|
+
NSString* file = [UnityGetCrashReportsPath() stringByAppendingPathComponent: @"crash-"];
|
498
|
+
|
499
|
+
unsigned long long seconds = (unsigned long long)[[NSDate date] timeIntervalSince1970];
|
500
|
+
|
501
|
+
file = [file stringByAppendingString: [NSString stringWithFormat: @"%llu", seconds]];
|
502
|
+
|
503
|
+
file = [file stringByAppendingString: @".plcrash"];
|
504
|
+
|
505
|
+
if ([data writeToFile: file atomically: YES])
|
506
|
+
|
507
|
+
{
|
508
|
+
|
509
|
+
::printf("CrashReporter: saved pending crash report.\n");
|
510
|
+
|
511
|
+
if (![[UnityPLCrashReporter sharedReporter] purgePendingCrashReportAndReturnError: &error])
|
512
|
+
|
513
|
+
{
|
514
|
+
|
515
|
+
::printf("CrashReporter: couldn't remove pending report: %s\n", [[error localizedDescription] UTF8String]);
|
516
|
+
|
517
|
+
}
|
518
|
+
|
519
|
+
}
|
520
|
+
|
521
|
+
else
|
522
|
+
|
523
|
+
{
|
524
|
+
|
525
|
+
::printf("CrashReporter: couldn't save crash report.\n");
|
526
|
+
|
527
|
+
}
|
528
|
+
|
529
|
+
|
530
|
+
|
531
|
+
// Now copy out a pending version that we can delete if/when we send it
|
532
|
+
|
533
|
+
file = [UnityGetCrashReportsPath() stringByAppendingPathComponent: @"crash-pending.plcrash"];
|
534
|
+
|
535
|
+
if ([data writeToFile: file atomically: YES])
|
536
|
+
|
537
|
+
{
|
538
|
+
|
539
|
+
::printf("CrashReporter: saved copy of pending crash report.\n");
|
540
|
+
|
541
|
+
}
|
542
|
+
|
543
|
+
else
|
544
|
+
|
545
|
+
{
|
546
|
+
|
547
|
+
::printf("CrashReporter: couldn't save copy of pending crash report.\n");
|
548
|
+
|
549
|
+
}
|
550
|
+
|
551
|
+
}
|
552
|
+
|
553
|
+
|
554
|
+
|
555
|
+
static void InitCrashReporter()
|
556
|
+
|
557
|
+
{
|
558
|
+
|
559
|
+
NSError *error;
|
560
|
+
|
561
|
+
|
562
|
+
|
563
|
+
UnityInstallPostCrashCallback();
|
564
|
+
|
565
|
+
if ([[UnityPLCrashReporter sharedReporter] enableCrashReporterAndReturnError: &error])
|
566
|
+
|
567
|
+
::printf("CrashReporter: initialized\n");
|
568
|
+
|
569
|
+
else
|
570
|
+
|
571
|
+
NSLog(@"CrashReporter: could not enable crash reporter: %@", error);
|
572
|
+
|
573
|
+
|
574
|
+
|
575
|
+
SavePendingCrashReport();
|
576
|
+
|
577
|
+
}
|
578
|
+
|
579
|
+
|
580
|
+
|
581
|
+
static void UncaughtExceptionHandler(NSException *exception)
|
582
|
+
|
583
|
+
{
|
584
|
+
|
585
|
+
NSLog(@"Uncaught exception: %@: %@\n%@", [exception name], [exception reason], [exception callStackSymbols]);
|
586
|
+
|
587
|
+
if (gsCrashReporterUEHandler)
|
588
|
+
|
589
|
+
gsCrashReporterUEHandler(exception);
|
590
|
+
|
591
|
+
}
|
592
|
+
|
593
|
+
|
594
|
+
|
595
|
+
static void InitObjCUEHandler()
|
596
|
+
|
597
|
+
{
|
598
|
+
|
599
|
+
// Crash reporter sets its own handler, so we have to save it and call it manually
|
600
|
+
|
601
|
+
gsCrashReporterUEHandler = NSGetUncaughtExceptionHandler();
|
602
|
+
|
603
|
+
NSSetUncaughtExceptionHandler(&UncaughtExceptionHandler);
|
604
|
+
|
605
|
+
}
|
606
|
+
|
607
|
+
|
608
|
+
|
609
|
+
void InitCrashHandling()
|
610
|
+
|
611
|
+
{
|
612
|
+
|
613
|
+
#if ENABLE_CUSTOM_CRASH_REPORTER
|
614
|
+
|
615
|
+
InitCrashReporter();
|
616
|
+
|
617
|
+
#endif
|
618
|
+
|
619
|
+
|
620
|
+
|
621
|
+
#if ENABLE_OBJC_UNCAUGHT_EXCEPTION_HANDLER
|
622
|
+
|
623
|
+
InitObjCUEHandler();
|
624
|
+
|
625
|
+
#endif
|
626
|
+
|
627
|
+
}
|
628
|
+
|
629
|
+
|
630
|
+
|
631
|
+
// This function will be called when AppDomain.CurrentDomain.UnhandledException event is triggered.
|
632
|
+
|
633
|
+
// When running on device the app will do a hard crash and it will generate a crash log.
|
634
|
+
|
635
|
+
extern "C" void CrashedCheckBelowForHintsWhy()
|
636
|
+
|
637
|
+
{
|
638
|
+
|
639
|
+
#if ENABLE_IOS_CRASH_REPORTING || ENABLE_CUSTOM_CRASH_REPORTER
|
640
|
+
|
641
|
+
// Make app crash hard here
|
642
|
+
|
643
|
+
__builtin_trap();
|
644
|
+
|
645
|
+
|
646
|
+
|
647
|
+
// Just in case above doesn't work
|
648
|
+
|
649
|
+
abort();
|
650
|
+
|
651
|
+
#endif
|
652
|
+
|
653
|
+
}
|
654
|
+
|
655
|
+
|
656
|
+
|
657
|
+
```
|
1
コードの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -226,7 +226,149 @@
|
|
226
226
|
|
227
227
|
|
228
228
|
|
229
|
-
|
229
|
+
```ここに言語を入力
|
230
|
+
|
231
|
+
#if UNITY_IPHONE || UNITY_IOS
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
using System.IO;
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
using UnityEditor;
|
240
|
+
|
241
|
+
using UnityEditor.Callbacks;
|
242
|
+
|
243
|
+
using UnityEditor.iOS.Xcode;
|
244
|
+
|
245
|
+
|
246
|
+
|
247
|
+
using GoogleMobileAds.Editor;
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
public static class PListProcessor
|
252
|
+
|
253
|
+
{
|
254
|
+
|
255
|
+
[PostProcessBuild]
|
256
|
+
|
257
|
+
public static void OnPostProcessBuild(BuildTarget buildTarget, string path)
|
258
|
+
|
259
|
+
{
|
260
|
+
|
261
|
+
string plistPath = Path.Combine(path, "Info.plist");
|
262
|
+
|
263
|
+
PlistDocument plist = new PlistDocument();
|
264
|
+
|
265
|
+
plist.ReadFromFile(plistPath);
|
266
|
+
|
267
|
+
|
268
|
+
|
269
|
+
if (!GoogleMobileAdsSettings.Instance.IsAdManagerEnabled && !GoogleMobileAdsSettings.Instance.IsAdMobEnabled)
|
270
|
+
|
271
|
+
{
|
272
|
+
|
273
|
+
NotifyBuildFailure("Neither Ad Manager nor AdMob is enabled yet.");
|
274
|
+
|
275
|
+
}
|
276
|
+
|
277
|
+
|
278
|
+
|
279
|
+
if (GoogleMobileAdsSettings.Instance.IsAdManagerEnabled)
|
280
|
+
|
281
|
+
{
|
282
|
+
|
283
|
+
plist.root.SetBoolean("GADIsAdManagerApp", true);
|
284
|
+
|
285
|
+
}
|
286
|
+
|
287
|
+
|
288
|
+
|
289
|
+
if (GoogleMobileAdsSettings.Instance.IsAdMobEnabled)
|
290
|
+
|
291
|
+
{
|
292
|
+
|
293
|
+
string appId = GoogleMobileAdsSettings.Instance.AdMobIOSAppId;
|
294
|
+
|
295
|
+
if (appId.Length == 0)
|
296
|
+
|
297
|
+
{
|
298
|
+
|
299
|
+
NotifyBuildFailure(
|
300
|
+
|
301
|
+
"iOS AdMob app ID is empty. Please enter a valid app ID to run ads properly.");
|
302
|
+
|
303
|
+
}
|
304
|
+
|
305
|
+
else
|
306
|
+
|
307
|
+
{
|
308
|
+
|
309
|
+
plist.root.SetString("GADApplicationIdentifier", appId);
|
310
|
+
|
311
|
+
}
|
312
|
+
|
313
|
+
}
|
314
|
+
|
315
|
+
|
316
|
+
|
317
|
+
if (GoogleMobileAdsSettings.Instance.DelayAppMeasurementInit)
|
318
|
+
|
319
|
+
{
|
320
|
+
|
321
|
+
plist.root.SetBoolean("GADDelayAppMeasurementInit", true);
|
322
|
+
|
323
|
+
}
|
324
|
+
|
325
|
+
|
326
|
+
|
327
|
+
File.WriteAllText(plistPath, plist.WriteToString());
|
328
|
+
|
329
|
+
}
|
330
|
+
|
331
|
+
|
332
|
+
|
333
|
+
private static void NotifyBuildFailure(string message)
|
334
|
+
|
335
|
+
{
|
336
|
+
|
337
|
+
string prefix = "[GoogleMobileAds] ";
|
338
|
+
|
339
|
+
|
340
|
+
|
341
|
+
bool openSettings = EditorUtility.DisplayDialog(
|
342
|
+
|
343
|
+
"Google Mobile Ads", "Error: " + message, "Open Settings", "Close");
|
344
|
+
|
345
|
+
if (openSettings)
|
346
|
+
|
347
|
+
{
|
348
|
+
|
349
|
+
GoogleMobileAdsSettingsEditor.OpenInspector();
|
350
|
+
|
351
|
+
}
|
352
|
+
|
353
|
+
#if UNITY_2017_1_OR_NEWER
|
354
|
+
|
355
|
+
throw new BuildPlayerWindow.BuildMethodException(prefix + message);
|
356
|
+
|
357
|
+
#else
|
358
|
+
|
359
|
+
throw new OperationCanceledException(prefix + message);
|
360
|
+
|
361
|
+
#endif
|
362
|
+
|
363
|
+
}
|
364
|
+
|
365
|
+
}
|
366
|
+
|
367
|
+
|
368
|
+
|
369
|
+
#endif
|
370
|
+
|
371
|
+
```
|
230
372
|
|
231
373
|
|
232
374
|
|