iOS - HomeKit: why it takes too long to add a user? - ios

I am trying to add a user (HMUser) to my home (HMHome) by
[self.home addUserWithCompletionHandler:^(HMUser *user, NSError *error) {
if (error) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Error"
message:error.localizedDescription
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
return;
}
NSLog(#"add done!");
[weakSelf.tableView reloadData];
}];
as referenced from: https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/HomeKitDeveloperGuide/ManagingUsers/ManagingUsers.html
From my phone (whose iCloud email is: me#gmail.com for e.g.), I add a guest (whose iCloud email is: guest#gmail.com for e.g.). Immediately, the guest receives a notification from Apple and has to press Accept, as expected. After that, my app can display the guest email, which is correct. The issue is: the guest is very hard to view my shared home. Sometimes I have to wait ~ 2 hours but the guest still cannot view my home layout. I tried to reset wifi/bluetooth on the guest phone but things are not better.
Do you have any ideas about this issue on how to fix it?
Thanks in advance,

Related

Why does [PFPurchase buyProduct] requires me to login twice?

I use PFPurchase's buyProduct method call to initiate the in-app purchase process. Although it requires me to enter the test account's email address and the password twice to complete the process.
When I enter the email and the password for the first time, the prompt just disappears and comes back after 2-3 seconds and I have to enter them again.
I use auto-renewing subscriptions with a trial period of 7 days.
My app has one ViewController and I have the below code in the viewDidLoad function.
[PFPurchase addObserverForProduct:#"com.tls.1monthsubscription" block:^(SKPaymentTransaction *transaction) {
NSLog(#"Product purchased");
[self checkReceipt];
}];
Below function gets called when I tap on the "BUY" button from the UI:
-(IBAction)purchaseThirtyDaysSubscriptionBtnAction:(id)sender
{
[SVProgressHUD show];
[PFPurchase buyProduct:#"com.tls.1monthsubscription" block:^(NSError *error) {
if (!error) {
[SVProgressHUD dismiss];
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Purchase Succeeded" message:#"You have purchased subscription successfully!" delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil, nil];
[alertView show];
} else {
[SVProgressHUD showErrorWithStatus:[error localizedDescription]];
}
}];
}
Any ideas?

Parse - Sign Up and Login at the same time

Using Parse (iOS framework), I am able to sign up and login successfully using two API.
When user log in, it will cache the user and so accessing "currentUser" will return appropriate object. But sign up API is not caching.
Is there any way that sign up itself will cache the user and avoid separate log in functionality?
It should automatically log you in as well. For example, if in your completion block in signUpInBackground, you have a segue to your main screen and in your main screen, it is supposed to show information related to the user, then it will because [PFUser currentUser] is set to the user that registered.
here is an example
[user signUpInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (error) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:[[error userInfo] objectForKey:#"error"] message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:#"Ok", nil];
[alertView show];
// Bring the keyboard back up, because they'll probably need to change something.
[_usernameField becomeFirstResponder];
}
else{
// Success!
[self performSegueWithIdentifier:#"goToMain" sender:self];
}
}];

saveEvent returning "No calendar has been set"

I am attempting to save an event into the calendar, from my application.
My code works for iOS 7, but on iOS 6, it returns No calendar has been set.
The application prompts for user to grant access to the calendar, on iOS 7.
But no such prompt appears for iOS 6. Although the application is granted access in the Settings-> Privacy -> Calendar.
And yes, I have already implemented the requestAccessToEntityType:completion:.
Here is my code snippet.
EKEventStore *objStore = [[EKEventStore alloc]init];
if ([objStore respondsToSelector:#selector(requestAccessToEntityType:completion:)])
{
// iOS 6 and later
[objStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error)
{
dispatch_async(dispatch_get_main_queue(), ^{
if (granted)
{
// code here for when the user allows your app to access the calendar
EKEvent *calEvent = [EKEvent eventWithEventStore:objStore];
calEvent.title = mstrTitleEvent;
calEvent.startDate = self.dateToBeSet;
calEvent.endDate = self.dateToBeSet;
calEvent.calendar = objStore.defaultCalendarForNewEvents;
EKAlarm *objAlarm = [EKAlarm alarmWithAbsoluteDate:self.dateToBeSet];
[calEvent addAlarm:objAlarm];
NSError *error;
BOOL _bStatus = [objStore saveEvent:calEvent span:EKSpanThisEvent commit:YES error:&error];
UIAlertView *alertV;
if(_bStatus)
{
alertV = [[UIAlertView alloc]initWithTitle:#"Congratulations" message:#"Saved To Calendar" delegate:nil cancelButtonTitle:#"Right On!" otherButtonTitles:nil];
[alertV show];
}
else
{
alertV = [[UIAlertView alloc]initWithTitle:#"Alert" message:[NSString stringWithFormat:#"Error saving to calendar, with error %#.",[error localizedDescription]] delegate:nil cancelButtonTitle:#"Cancel" otherButtonTitles:nil];
[alertV show];
}
}
else
{
// code here for when the user does NOT allow your app to access the calendar
UIAlertView *alertV = [[UIAlertView alloc]initWithTitle:#"Alert" message:#"Please grant access to the calendar, and try again later." delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil];
[alertV show];
}
});
}];
}
Just managed to somehow find a solution for my problem.
I had to navigate from one page to another, so posting the link to the two pages.
First ->
https://discussions.apple.com/message/16497282#16497282
Then, from there to ->
https://discussions.apple.com/message/16479587#16479587
I had to go into Settings>iCloud> and turn on Calendars.
After that, I tried to attempt and run my code, and it was working well and fine again.
Do attempt this, if you facing a similar problem.
I was working on iPad 2, and with iOS 6.1.3 installed on the device.
Amazing I am testing my code on two different devices, one it works fine and the other it will not work. Just looked in setting and the one with it not working has iCloud calendar and reminders turned off, just turn them on and it all works now... this has to be a bug

can't login with facebook on iOS

I am trying to login to a facebook account without the admin and test user I have been testing with. This is using the Parse.com framework facebook login utility. I get the error:
NSLocalizedDescription=User is not a test user owned by the application
My code to authenticate with facebook is hitting this condition:
[PFFacebookUtils logInWithPermissions:nil block:^(PFUser *user, NSError *error) {
if (!user) {
NSLog(#"User doesn't exist");
NSLog(#"%#", error);
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Error"
message:error.localizedDescription
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alertView show];
}
I have set my app to: "Live and Available to All Users" in the facebook developer app dashboard.
Why am I receiving this error and how do I allow my app to be logged in by any user with a facebook account?
The problem was that I was already logged in in the simulator with a non valid account.

iOS: How do I detect if an email has been successfully sent?

I am trying to check if an Email message was sent and display an Alert allowing the user know.
I tried the delegate method below , but sadly will display the alert message if user cancels as well. Any help will be appreciated and rewarded.
- (void)mailComposeController:(MFMailComposeViewController*)controller
didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error{
if (error) { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Error" message:
[NSString stringWithFormat:#"Error %#", [error description]] delegate:self
cancelButtonTitle:#"Dismiss" otherButtonTitles:nil];
[alert show];
}
NSLog(#"email sent");
}
}
All that it means when that function is called is that something happened with the email because the MFMailComposeViewController is finished. To know what did actually happen, you have to take a look at the value of result, which can be any of the following:
MFMailComposeResultCancelled
MFMailComposeResultSaved
MFMailComposeResultSent
MFMailComposeResultFailed
As rmaddy says in comments, you can't be 100% sure that the email was actually sent (it could be stuck in the outbox). What MFMailComposeResultSent signifies, then, is that the email has been sent over to the Mail app, which will send it as soon as it can.

Resources