EKEvent not passing title to view - objective-c

I'm having problems when creating a calendar event in my app, i have a collection view that have dates when you click one of them the view controller pops out without the name or date that i passed by code.
Here's the code:
EKEventStore *eventStore = [[EKEventStore alloc] init];
if([eventStore respondsToSelector:#selector(requestAccessToEntityType:completion:)]) {
//This code will run when uses has made his/her choice
EKEvent *event = [EKEvent eventWithEventStore:eventStore];
[event setTitle:theTitle];
event.startDate = date;
event.endDate = date;
EKEventEditViewController *controller = [[EKEventEditViewController alloc] init];
controller.navigationBar.backgroundColor = [UIColor blackColor];
[event setCalendar:[eventStore defaultCalendarForNewEvents]];
NSError *err;
[eventStore saveEvent:event span:EKSpanThisEvent error:&err];
NSLog(#"err %#", err);
controller.eventStore = eventStore;
controller.editViewDelegate = self;
[self presentViewController:controller animated:YES completion:nil];
}
The code is in the
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
Does EKEventStore have special methods to set the date or title?

Related

CNContactPickerViewController gets error (CNPropertyNotFetchedException) - Objective-C

I am calling the Contact Picker View like so:
- (void)openContacts {
CNContactPickerViewController *picker = [[CNContactPickerViewController alloc] init];
picker.delegate = self;
picker.displayedPropertyKeys = #[CNContactGivenNameKey];
[self presentViewController:picker animated:YES completion:nil];
}
And I am handling the selections with this delegate method:
- (void)contactPicker:(CNContactPickerViewController *)picker didSelectContacts:(NSArray<CNContact *> *)contacts {
for (CNContact *contact in contacts) {
NSLog(#"%#",contact);
NSString *phone;
NSString *mobilePhone;
for (CNLabeledValue *label in contact.phoneNumbers) {
if ([label.label isEqualToString:CNLabelPhoneNumberMobile] || [label.label isEqualToString:CNLabelPhoneNumberiPhone]) {
mobilePhone = [label.value stringValue];
} else if ([label.label isEqualToString:CNLabelPhoneNumberMain]) {
phone = [label.value stringValue];
}
}
}
}
The NSLog outputs the following for contact: <CNContact: 0x78e56e50: identifier=1861C9BD-143B-4E93-8475-F9079F5D6192, givenName=Kate, familyName=Bell, organizationName=Creative Consulting, phoneNumbers=(not fetched), emailAddresses=(not fetched), postalAddresses=(not fetched)>
This only occurs on simulator and iOS9 iPad. I don't get an error with my iOS10 iPhone.
You should first ask permission for this. Then you can show picker.
CNContactStore *store = [[CNContactStore alloc] init];
[store requestAccessForEntityType:CNEntityTypeContacts completionHandler:^(BOOL granted, NSError * _Nullable error)
{
CNContactPickerViewController *picker = [[CNContactPickerViewController alloc] init];
picker.delegate = self;
picker.displayedPropertyKeys = #[CNContactGivenNameKey];
[self presentViewController:picker animated:YES completion:nil];
}];
In this case you'll show picker always, without dependance on user's choice. So you should check property availability like that:
if ([CNContactStore authorizationStatusForEntityType:CNEntityTypeContacts] == CNAuthorizationStatusAuthorized)
{
}

Objective C: button only works if clicked twice

My button only registers when it is clicked twice for some reason. Anyone know why?
- (IBAction)refreshButton:(UIButton *)sender {
keynames = [[NSMutableArray alloc] init];
keynums = [[NSMutableArray alloc] init];
Firebase *resp = [[Firebase alloc] initWithUrl: #"https://somelink"];
[resp observeEventType:FEventTypeChildAdded withBlock:^(FDataSnapshot *snapshot) {
int x = 0;
[tabView beginUpdates];
for (NSString* key in snapshot.value){
[mutkeynames addObject:key];
[mutkeynums addObject:snapshot.value[key][#"value"]];
x++;
}
[tabView endUpdates];
}];
dispatch_async(dispatch_get_main_queue(), ^{
[self.tabView reloadData];
});
}

Game Center not showing in iOS 5

I used this tutorial to access GameCenter.
http://www.raywenderlich.com/3276/how-to-make-a-simple-multiplayer-game-with-game-center-tutorial-part-12
I am able to lo in the game center but then if I want to use this code:
SFAppDelegate * delegate = (SFAppDelegate *) [UIApplication sharedApplication].delegate;
[[GCHelper sharedInstance] findMatchWithMinPlayers:2 maxPlayers:2 viewController:self delegate:self];
This code should work, but if I call i it only shows black screen with blue toolbar in above.
the "self" in here is UIViewController and this controller implements the GCHelper delegate methods.
the method find ... looks like this:
- (void)findMatchWithMinPlayers:(int)minPlayers maxPlayers:(int)maxPlayers viewController:(UIViewController *)viewController delegate:(id<GCHelperDelegate>)theDelegate {
if (!gameCenterAvailable) return;
matchStarted = NO;
self.match = nil;
self.presentingViewController = viewController; // ?
delegate = theDelegate;
[presentingViewController dismissModalViewControllerAnimated:NO];
if (pendingInvite != nil)
{
[presentingViewController dismissModalViewControllerAnimated:NO];
GKMatchmakerViewController *mmvc = [[[GKMatchmakerViewController alloc] initWithInvite:pendingInvite] autorelease];
mmvc.matchmakerDelegate = self;
[presentingViewController presentModalViewController:mmvc animated:YES];
self.pendingInvite = nil;
self.pendingPlayersToInvite = nil;
}
else
{
[presentingViewController dismissModalViewControllerAnimated:NO];
GKMatchRequest *request = [[[GKMatchRequest alloc] init] autorelease];
request.minPlayers = minPlayers;
request.maxPlayers = maxPlayers;
request.playersToInvite = pendingPlayersToInvite;
GKMatchmakerViewController *mmvc = [[[GKMatchmakerViewController alloc] initWithMatchRequest:request] autorelease];
mmvc.matchmakerDelegate = self;
[presentingViewController presentModalViewController:mmvc animated:YES];
self.pendingInvite = nil;
self.pendingPlayersToInvite = nil;
}
}
I don't know what am I doing wrong....
Thanks for any suggestions for correction.
:)

Action sheet getting caught on tabbar

This is a tricky one that I've been working on for a while. I have a an action sheet that appears in a view with a tabbar, sometimes when I dismiss the action sheet it gets "caught" in the tabbar and am unable to do anything.The app doesn't crash because if i minimize it and then come back in it is dimissed, it just appears that the modal behavior isn't being dismissed properly.
I recently changed how the action sheet is displayed from "showInView" to "showFromTabBar" and am not sure if this is creating the issue.
Thanks,
William
Edit:
Below is the code I use to dismiss my actionsheet:
-(void)doneButtonPressed:(id)sender{
if ([[self viewWithTag:1] isKindOfClass:[PickerView class]]) {
PickerView *picker = (PickerView *)[self viewWithTag:1];
if (picker.selectedRow == nil) {
[picker populateSelectRowForRow:0 andComponent:0];
}
NSNotification *note = [NSNotification notificationWithName:#"doneButtonPressed" object:self.indexPath userInfo:picker.selectedRow];
[[NSNotificationCenter defaultCenter] postNotification:note];
}else {
DatePickerView *picker = (DatePickerView *)[self viewWithTag:1];
NSDictionary *extraInfo = [[NSDictionary alloc] initWithObjects:[[NSArray alloc] initWithObjects:[self formatDateToString:[picker date]], nil] forKeys:[[NSArray alloc] initWithObjects:#"value", nil]];
NSNotification *note = [NSNotification notificationWithName:#"doneButtonPressed" object:self.indexPath userInfo:extraInfo];
[[NSNotificationCenter defaultCenter] postNotification:note];
}
[self dismissWithClickedButtonIndex:0 animated:YES];
}
and the notification method that is called:
-(void)pickerUpdate:(NSNotification *)note{
NSIndexPath *indexPath = [note object];
NSDictionary *extraInfo = [note userInfo];
NSDictionary *dict = [[tableController.sectionAndFields objectAtIndex:indexPath.section] objectAtIndex:(indexPath.row + kHeaderAndFooterOffset)];
[tableController.formDetails setObject:[extraInfo objectForKey:#"value"] forKey:[dict objectForKey:#"key"]];
NSArray *reloadArray = [[NSArray alloc] initWithObjects:indexPath, nil];
[indexPath release];
[self.tv reloadRowsAtIndexPaths:reloadArray withRowAnimation:NO];
[reloadArray release];
}
I did manage to solve this however it feels very much like a hack, I introduced a delay into the code using:
[self performSelector:#selector(dismissFromActionSheet) withObject:nil afterDelay:0.2];
With dismissFromActionSheet being:
-(void)dismissFromActionSheet{
[self dismissWithClickedButtonIndex:0 animated:YES];
}

Stack A scroll view onto UIImagePickerController

I'd like to first say I'm a little new to anything but tutorial examples, so sorry if this is a daft question.
I have modified some sample code ever so slightly so that instead of closing a UIImagePickerController once the user has picked an image it processes it in the background.
This seems to work quite well, but once the user has picked all of the images they want to process the only button they're presented with is "Cancel".
I was hoping to change the code so that it adds the selected image to a scrolling view at the bottom of the image picker, but can't find a way to stack or overlay anything onto the UIImagePickerController view.
The code I have so far is below:
-(IBAction)LoadPhotoAlbums:(id)sender
{
NSLog(#"LoadPhotoAlbums");
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
return;
}
if(photoPicker == NULL) {
photoPicker = [[UIImagePickerController alloc] init];
photoPicker.delegate = self;
photoPicker.allowsImageEditing = NO;
}
photoPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:photoPicker animated:YES];
[pool release];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
if([[info objectForKey:#"UIImagePickerControllerMediaType"] isEqualToString:K_UI_TYPE_IMAGE])
{
NSLog(#"Image Selected");
selectedImage = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setDateFormat:#"ddMMMyyyyHHmmss"];
NSString *date = [dateFormatter stringFromDate:[NSDate date]];
NSData *imageData = UIImageJPEGRepresentation(selectedImage,0.9);
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
selectedImagePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:[NSString stringWithFormat:#"%#.jpg", date]];
NSLog(#"Image path is %#", selectedImagePath);
if([imageData writeToFile:selectedImagePath atomically:YES])
NSLog(#"Write Successful");
}
//[picker dismissModalViewControllerAnimated:YES];
//add to listofimages view.
[self uploadSelectedImage];
}