Skip to content

Commit

Permalink
Merge pull request #417 from ToddLa/ios-16
Browse files Browse the repository at this point in the history
Fixes for iOS 16
  • Loading branch information
yoshisuga authored Sep 17, 2022
2 parents baba40f + cfb487c commit 9be78d3
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
39 changes: 32 additions & 7 deletions xcode/MAME4iOS/CloudSync.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@
#import "EmulatorController.h"
#import "Alert.h"

#if TARGET_OS_MACCATALYST
#import <Security/SecTask.h>
#else
// declare *just* the Security APIs we need to check for entitlments on iOS
typedef CFTypeRef SecTaskRef;
extern SecTaskRef SecTaskCreateFromSelf(CFAllocatorRef allocator);
extern CFTypeRef SecTaskCopyValueForEntitlement(SecTaskRef task, CFStringRef entitlement, CFErrorRef *error);
#endif

#define DebugLog 1
#if DebugLog == 0 || !defined(DEBUG)
#define NSLog(...) (void)0
Expand Down Expand Up @@ -62,16 +71,32 @@ +(NSString*)cloudIdentifier {
return [NSString stringWithFormat:@"iCloud.%@", NSBundle.mainBundle.bundleIdentifier];
}

// use the Security framework to see if we have the iCloud entitlement
+(BOOL)isEntitled {
SecTaskRef task = SecTaskCreateFromSelf(NULL);
if (task == NULL)
return FALSE;
CFTypeRef val = SecTaskCopyValueForEntitlement(task, CFSTR("com.apple.developer.icloud-services"), NULL);
CFRelease(task);
if (val == NULL)
return FALSE;
CFRelease(val);
return TRUE;
}

+(void)updateCloudStatus {

if (_container == nil) {
@try {
// **NOTE** CKContainer.defaultContainer will throw a uncatchable exception, dont use it.
//_container = CKContainer.defaultContainer;
_container = [CKContainer containerWithIdentifier:[self cloudIdentifier]];
}
@catch (id exception) {
NSLog(@"CLOUD STATUS: %@", exception);

if ([self isEntitled]) {
@try {
// **NOTE** CKContainer.defaultContainer will throw a uncatchable exception, dont use it.
//_container = CKContainer.defaultContainer;
_container = [CKContainer containerWithIdentifier:[self cloudIdentifier]];
}
@catch (id exception) {
NSLog(@"CLOUD STATUS: %@", exception);
}
}
if (_container == nil) {
NSLog(@"CLOUD STATUS: NO ENTITLEMENT");
Expand Down
4 changes: 4 additions & 0 deletions xcode/MAME4iOS/MAME4iOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,8 @@
EF474B872791E42900578663 /* MAME4iOS-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "MAME4iOS-Bridging-Header.h"; sourceTree = "<group>"; };
EF474B882791E42900578663 /* EmulatorController+EmulatorKeyboardSupport.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "EmulatorController+EmulatorKeyboardSupport.swift"; sourceTree = "<group>"; };
EF474B8A2791E4CD00578663 /* EmulatorKeyboard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmulatorKeyboard.swift; sourceTree = "<group>"; };
EF47838528D38F0A00DA4A56 /* Developer.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Developer.xcconfig; sourceTree = "<group>"; };
EF47838628D3B64B00DA4A56 /* mame-src */ = {isa = PBXFileReference; lastKnownFileType = folder; name = "mame-src"; path = ../../src; sourceTree = "<group>"; };
EF490D90277A5C8C00407865 /* history.dat.zip */ = {isa = PBXFileReference; lastKnownFileType = archive.zip; name = history.dat.zip; path = "../../iOS-res/history.dat.zip"; sourceTree = "<group>"; };
EF490D94277A5E0E00407865 /* cheat.7z */ = {isa = PBXFileReference; lastKnownFileType = file; name = cheat.7z; path = "../../iOS-res/cheat.7z"; sourceTree = "<group>"; };
EF490D95277A5E0E00407865 /* cheat.zip */ = {isa = PBXFileReference; lastKnownFileType = archive.zip; name = cheat.zip; path = "../../iOS-res/cheat.zip"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -734,6 +736,7 @@
isa = PBXGroup;
children = (
EF55DE312533C21E004E37EF /* MAME4iOS.xcconfig */,
EF47838528D38F0A00DA4A56 /* Developer.xcconfig */,
EF9F9C9E240070E700352554 /* README.md */,
EFFBA6FD24F1C91200F8666B /* WHATSNEW.md */,
EFE0036C264C0B0D00E42246 /* TODO.md */,
Expand All @@ -745,6 +748,7 @@
CEE6808F1635BA7000051BC2 /* MAME4iOS */,
92ECB8EC21EA984E00D1E3D0 /* MAME4tvOS */,
EFEEA4B325C9D41E00314132 /* TopShelf */,
EF47838628D3B64B00DA4A56 /* mame-src */,
CEE680C51635BB8500051BC2 /* Includes */,
CEE680881635BA7000051BC2 /* Frameworks */,
CEE680861635BA7000051BC2 /* Products */,
Expand Down
2 changes: 1 addition & 1 deletion xcode/MAME4iOS/TVAlertController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ extension TVAlertController: UIPopoverPresentationControllerDelegate {

// if the device rotates when popover is up, just center
func popoverPresentationController(_ popoverPresentationController: UIPopoverPresentationController, willRepositionPopoverTo rectPtr: UnsafeMutablePointer<CGRect>, in viewPtr: AutoreleasingUnsafeMutablePointer<UIView>) {
guard let view = self.presentingViewController?.view else { return }
guard !self.isBeingPresented, let view = self.presentingViewController?.view else { return }
popoverPresentationController.permittedArrowDirections = []
viewPtr.pointee = view
rectPtr.pointee = CGRect(x:view.bounds.width/2, y:view.bounds.height/2, width:0, height:0)
Expand Down

0 comments on commit 9be78d3

Please sign in to comment.