Reputation: 111
I have an existing iOS app that uses Parse.com. You can login with username and password, Facebook, or twitter, as well as create a new login. I am getting an update ready that has a WatchKit Extension to run a slimmed down version on the new Apple Watch. What I am wondering how to do is have the watch check if there is an existing PFUser
on the iPhone, or if even the iPhone user is logged out. What would you suggest for this?
I have the application ID for the Parse app in my AppDelegate, and initialize PFTwitterUtils
and PFFacebookUtils
in the AppDelegate, but those do not get called when running from watch.
Upvotes: 1
Views: 762
Reputation: 5121
I am not sure where Parse stores their data, but I don't think it is in your shared app group folder. If that is the case then parse in your extension would not have access to the same data as parse running in your iOS app (though I am not 100% positive on that.) I would recommend putting a "LoggedIn" setting in your shared user defaults. You can update that setting every time the user logs in or out in your iOS app and then just check that setting in your watch app.
Upvotes: 1
Reputation: 2093
I had the same issue some time ago, I finally decided to use darwinNotifications to send notifications between iPhone app and applewatch,and to share data between them I used SharedGroups. So when the user login: 1) I write the user in the shared groups 2) I send a darwin notification from the iOS app to the apple watch 3) Apple watch receive the darwin notification and reads the shared groups to check if there is a new user.
This code sends a darwin notification:
//Write the user on shared groups
CFNotificationCenterRef notification = CFNotificationCenterGetDarwinNotifyCenter ();
CFStringRef UserLoggedInCFString = (__bridgeCFStringRef)DarwinNotificationUserLoggedIn;
CFNotificationCenterPostNotification(notification, UserLoggedInCFString, NULL, NULL, YES);
This code on the applewatch detect the notification:
CFNotificationCenterRef notificationUserLoggedIn = CFNotificationCenterGetDarwinNotifyCenter (); // 1
CFStringRef userLoggedInCFString = (__bridgeCFStringRef)DarwinNotificationUserLoggedIn;
CFNotificationCenterAddObserver(notificationUserLoggedIn, (__bridge const void *)(self), &userHasLogguedIn, userLoggedInCFString,NULL, CFNotificationSuspensionBehaviorDeliverImmediately);
void userHasLogguedIn(CFNotificationCenterRef center,
void *observer,
CFStringRef name,
const void *object,
CFDictionaryRef userInfo)
{
//Read the user from shared groups.
}
Upvotes: 1