Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for watch os, disable iCloud for watch. #1319

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions MagicalRecord.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Pod::Spec.new do |s|
s.requires_arc = true
s.ios.deployment_target = '6.1'
s.osx.deployment_target = '10.8'
s.watchos.deployment_target = '3.0'

s.subspec 'Core' do |sp|
sp.framework = 'CoreData'
Expand Down
527 changes: 518 additions & 9 deletions MagicalRecord.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0700"
LastUpgradeVersion = "0900"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -26,6 +26,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES"
codeCoverageEnabled = "YES">
<Testables>
Expand Down Expand Up @@ -56,6 +57,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0700"
LastUpgradeVersion = "0900"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -26,6 +26,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES"
codeCoverageEnabled = "YES">
<Testables>
Expand Down Expand Up @@ -56,6 +57,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0700"
LastUpgradeVersion = "0900"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -26,6 +26,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES"
codeCoverageEnabled = "YES">
<Testables>
Expand All @@ -47,6 +48,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0700"
LastUpgradeVersion = "0900"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -26,6 +26,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES"
codeCoverageEnabled = "YES">
<Testables>
Expand All @@ -47,6 +48,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,26 +45,30 @@ OBJC_EXPORT NSString * __MR_nonnull const kMagicalRecordDidMergeChangesFromiClou
*/
- (void) MR_observeContextOnMainThread:(MR_nonnull NSManagedObjectContext *)otherContext;

#if !TARGET_OS_WATCH

/**
Merges changes from the supplied persistent store coordinator into self in response to changes from iCloud.

@param coordinator Persistent store coordinator

@see -MR_stopObservingiCloudChangesInCoordinator:

@since Available in v2.0 and later.
*/
- (void) MR_observeiCloudChangesInCoordinator:(MR_nonnull NSPersistentStoreCoordinator *)coordinator;

/**
Stops observation and merging of changes from the supplied persistent store coordinator in response to changes from iCloud.

@param coordinator Persistent store coordinator

@see -MR_observeiCloudChangesInCoordinator:

@since Available in v2.0 and later.
*/
- (void) MR_stopObservingiCloudChangesInCoordinator:(MR_nonnull NSPersistentStoreCoordinator *)coordinator;

#endif

@end
Original file line number Diff line number Diff line change
Expand Up @@ -85,24 +85,28 @@ - (void) MR_mergeChangesOnMainThread:(NSNotification *)notification;
}
}

#if !TARGET_OS_WATCH

- (void) MR_observeiCloudChangesInCoordinator:(NSPersistentStoreCoordinator *)coordinator;
{
if (![MagicalRecord isICloudEnabled]) return;
NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
[notificationCenter addObserver:self
selector:@selector(MR_mergeChangesFromiCloud:)
name:NSPersistentStoreDidImportUbiquitousContentChangesNotification
object:coordinator];
if (![MagicalRecord isICloudEnabled]) return;
NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
[notificationCenter addObserver:self
selector:@selector(MR_mergeChangesFromiCloud:)
name:NSPersistentStoreDidImportUbiquitousContentChangesNotification
object:coordinator];
}

- (void) MR_stopObservingiCloudChangesInCoordinator:(NSPersistentStoreCoordinator *)coordinator;
{
if (![MagicalRecord isICloudEnabled]) return;
NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
[notificationCenter removeObserver:self
name:NSPersistentStoreDidImportUbiquitousContentChangesNotification
object:coordinator];
if (![MagicalRecord isICloudEnabled]) return;
NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
[notificationCenter removeObserver:self
name:NSPersistentStoreDidImportUbiquitousContentChangesNotification
object:coordinator];
}

#endif

@end
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ + (NSManagedObjectContext *) MR_newPrivateQueueContext

- (void)MR_setWorkingName:(NSString *)workingName
{
void (^setWorkingName)() = ^{
void (^setWorkingName)(void) = ^{
[[self userInfo] setObject:workingName forKey:MagicalRecordContextWorkingName];
};

Expand All @@ -120,7 +120,7 @@ - (NSString *)MR_workingName
{
__block NSString *workingName;

void (^getWorkingName)() = ^{
void (^getWorkingName)(void) = ^{
workingName = [[self userInfo] objectForKey:MagicalRecordContextWorkingName];
};

Expand Down Expand Up @@ -263,17 +263,19 @@ + (void) MR_setDefaultContext:(NSManagedObjectContext *)moc
[[NSNotificationCenter defaultCenter] removeObserver:MagicalRecordDefaultContext];
}

NSPersistentStoreCoordinator *coordinator = [NSPersistentStoreCoordinator MR_defaultStoreCoordinator];
if (MagicalRecordUbiquitySetupNotificationObserver)
{
[[NSNotificationCenter defaultCenter] removeObserver:MagicalRecordUbiquitySetupNotificationObserver];
MagicalRecordUbiquitySetupNotificationObserver = nil;
}

#if !TARGET_OS_WATCH
NSPersistentStoreCoordinator *coordinator = [NSPersistentStoreCoordinator MR_defaultStoreCoordinator];

if ([MagicalRecord isICloudEnabled])
{
[MagicalRecordDefaultContext MR_stopObservingiCloudChangesInCoordinator:coordinator];
}
#endif

MagicalRecordDefaultContext = moc;
[MagicalRecordDefaultContext MR_setWorkingName:@"MagicalRecord Default Context"];
Expand All @@ -286,20 +288,23 @@ + (void) MR_setDefaultContext:(NSManagedObjectContext *)moc
}

[moc MR_obtainPermanentIDsBeforeSaving];
if ([MagicalRecord isICloudEnabled])
{
[MagicalRecordDefaultContext MR_observeiCloudChangesInCoordinator:coordinator];
}
else
{
// If icloud is NOT enabled at the time of this method being called, listen for it to be setup later, and THEN set up observing cloud changes
MagicalRecordUbiquitySetupNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kMagicalRecordPSCDidCompleteiCloudSetupNotification
object:nil
queue:[NSOperationQueue mainQueue]
usingBlock:^(NSNotification *note) {
[[NSManagedObjectContext MR_defaultContext] MR_observeiCloudChangesInCoordinator:coordinator];
}];
}

#if !TARGET_OS_WATCH
if ([MagicalRecord isICloudEnabled])
{
[MagicalRecordDefaultContext MR_observeiCloudChangesInCoordinator:coordinator];
}
else
{
// If icloud is NOT enabled at the time of this method being called, listen for it to be setup later, and THEN set up observing cloud changes
MagicalRecordUbiquitySetupNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kMagicalRecordPSCDidCompleteiCloudSetupNotification
object:nil
queue:[NSOperationQueue mainQueue]
usingBlock:^(NSNotification *note) {
[[NSManagedObjectContext MR_defaultContext] MR_observeiCloudChangesInCoordinator:coordinator];
}];
}
#endif
MRLogInfo(@"Set default context: %@", MagicalRecordDefaultContext);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,15 @@ - (void) MR_addiCloudContainerID:(NSString *)containerID contentNameKey:(NSStrin
[MagicalRecord setICloudEnabled:cloudURL != nil];

NSDictionary *options = [[self class] MR_autoMigrationOptions];
#if !TARGET_OS_WATCH
if (cloudURL) //iCloud is available
{
NSMutableDictionary *iCloudOptions = [[NSMutableDictionary alloc] init];
[iCloudOptions setObject:cloudURL forKey:NSPersistentStoreUbiquitousContentURLKey];
// [iCloudOptions setObject:cloudURL forKey:NSPersistentStoreUbiquitousContentURLKey];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You forgot to undo something here?


if ([contentNameKey length] > 0)
{
[iCloudOptions setObject:contentNameKey forKey:NSPersistentStoreUbiquitousContentNameKey];
// [iCloudOptions setObject:contentNameKey forKey:NSPersistentStoreUbiquitousContentNameKey];
}

options = [options MR_dictionaryByMergingDictionary:iCloudOptions];
Expand All @@ -174,7 +175,7 @@ - (void) MR_addiCloudContainerID:(NSString *)containerID contentNameKey:(NSStrin
{
MRLogWarn(@"iCloud is not enabled");
}

#endif

if ([self respondsToSelector:@selector(performBlockAndWait:)])
{
Expand All @@ -184,15 +185,22 @@ - (void) MR_addiCloudContainerID:(NSString *)containerID contentNameKey:(NSStrin
}
else
{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
[self lock];
#pragma clang diagnostic pop
[self MR_addSqliteStoreNamed:storeIdentifier withOptions:options];
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
[self unlock];
#pragma clang diagnostic pop
#if TARGET_OS_WATCH
[self performBlockAndWait:^{
[self MR_addSqliteStoreNamed:storeIdentifier withOptions:options];
}];
#else
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
[self lock];
#pragma clang diagnostic pop
[self MR_addSqliteStoreNamed:storeIdentifier withOptions:options];
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
[self unlock];
#pragma clang diagnostic pop
#endif

}

dispatch_async(dispatch_get_main_queue(), ^{
Expand Down