Sharekit not populating facebook text box - objective-c

Here is the code I use. I am able to see popup but I do not see the text pre-populated in the facebook popup.
Any suggestions?
- (IBAction) shareViaFacebook
{
[self prepareToShare];
// create the item to share
NSString *share = [NSString stringWithFormat:#"I'm tracking %# in some stuff, check it out! http://somewebsite.com/g/%d #TEST",
self.game.name,
[self.game.serverId intValue]];
SHKItem *item = [SHKItem text:share];
// share the item
[SHKFacebook shareItem:item];
}
On the same age, the following code for twitter works just fine. That is everything gets prepopulated
- (IBAction) shareViaTwitter
{
[self prepareToShare];
// create the item to share
NSString *share = [NSString stringWithFormat:#"I'm tracking %# in some stuff, check it out! http://somewebsite.com/g/%d #TEST",
self.game.name,
[self.game.serverId intValue]];
SHKItem *item = [SHKItem text:share];
// share the item
[SHKTwitter shareItem:item];
}

This is an example from my project using ShareKit:
NSString *finalPostedString = [[NSString alloc] initWithFormat:#"Check out this"];
SHKItem *item1= [SHKItem text:finalPostedString];
SHKActionSheet *actionSheet = [SHKActionSheet actionSheetForItem:item1];
[actionSheet showInView:self];
Try that out and hopefully it helps.
EDIT: Or more specifically, check this thread out that also should answer your question:
iPhone/iOS - How to use "ShareKit" to post only to Facebook or only to Twitter

Related

Objective-C MPMediaItem with null URL

I have a project that makes use of a MPMediaPickerController to select audio files from the Media Player. However, when trying to store it's URL, I am getting nothing but null returned. My code can be seen below:
- (void)showMediaPicker:(NSString *)title {
MPMediaPickerController *picker = [[MPMediaPickerController alloc] initWithMediaTypes:MPMediaTypeAny];
picker.delegate = self;
picker.prompt = title;
picker.allowsPickingMultipleItems = NO;
picker.showsCloudItems = NO;
[self.viewController presentViewController:picker animated:YES completion:NULL];
}
- (void)mediaPicker: (MPMediaPickerController *)mediaPicker didPickMediaItems:(MPMediaItemCollection *)mediaItemCollection {
MPMediaItem *item = [mediaItemCollection.items firstObject];
NSURL *assetURL = [item valueForProperty:MPMediaItemPropertyAssetURL];//returning null
NSString *type = [self contentTypeForFile:assetURL.lastPathComponent];
NSString *title = [item valueForProperty:MPMediaItemPropertyTitle];
[self callbackWithName:title type:type url:assetURL];
}
For whatever reason, my *assetURL is nil upon selecting a single audio item from the device's library. The only answers i could find with respect to this problem often relate to the url being null when a cloud item is selected from the MediaPicker. However, as seen above, I have set showCloudItems = NO.
I would greatly appreciate any help; let me know if you need any additional information!
Turns out, music from the "iCloud Music Library" is DRM protected and therefore, the assetURL is left null when selected in the MPMediaPickerController. The simple fix was to turn off the "iCloud Music Library" setting from within the settings for the "Music" app. I would expect picker.showsCloudItems = NO; to prevent this, but apparently I was mistaken.

iOs Custom scheme in MFMailComposeViewController

I'm trying to send via MFMailComposeViewController a custom url scheme so that the receipient could tap on the embedded link and open my application on his iphone.
So far the receipient gets an email but nothing happens when he taps on the LINK.
here is the code:
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self; // <- very important step if you want feedbacks on what the user did with your email sheet
[picker setSubject:#"Incoming task"];
// Fill out the email body text
NSString * types = #"";
for(NSString *type in task.location_types){
types = [types stringByAppendingFormat:#"%#|",type];
}
if(types.length > 1){
types = [types substringToIndex:types.length - 1];
}
NSString *desc = [task.description stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *link = [NSString stringWithFormat:#"helpy://?taskid=%d&desc=%#&types=%#\"",task.TaskId,desc,types];
NSString *emailBody = [NSString stringWithFormat:#"TAP HERE<script type=\"text/javascript\" charset=\"utf-8\">function doSomething() { window.location = \"%#\;return false;}</script>",link];
[picker setMessageBody:emailBody isHTML:YES];
picker.navigationBar.barStyle = UIBarStyleBlack;
[controller presentModalViewController:picker animated:YES];
[picker release];
helpy://?taskid=..... is my custom registered URL Scheme and if I type it from the address bar of the browser it opens up my application on the iPhone.
For some reason when this link is embedded into email, tapping it does not do anything.
Any help?
thanks
I highly doubt that Mail will execute JavaScript on iOS (even on the desktop I highly doubt it, but haven't tried it though). Simply set the URL as the href attribute of your hyperlink and everything should work fine. Any reason why you want to do it with JavaScript? I'm just curious ;-)
NSString *link = [NSString stringWithFormat:#"helpy://?taskid=%d&desc=%#&types=%#\"",task.TaskId,desc,types];
NSString *emailBody = [NSString stringWithFormat:#"TAP HERE", link];

ShareKit email form not always displaying

I'm using ShareKit to share objects to Twitter, Facebook, and Email. Twitter and Facebook works fine, but email doesn't. And I don't really know why.
It seems like it works quite randomly.
I set it up like this:
[self.customView.shareButton addTarget:self action:#selector(sharePost:) forControlEvents:UIControlEventTouchUpInside];
- (void)sharePost:(UIButton *)sender
{
NSURL *url = [NSURL URLWithString:self.currentPost.link];
// Add image.
NSString *imageUrlString = [NSString stringWithFormat:[link]];
NSURL *imageUrl = [NSURL URLWithString:imageUrlString];
UIImageView *postImage = [[UIImageView alloc] init];
[postImage setImageWithURL:imageUrl];
SHKItem *item = [SHKItem image:postImage.image title:[NSString stringWithFormat:#"%#", self.currentPost.title]];
[item setURL:url];
[item setMailBody:[NSString stringWithFormat:#"%# %#", self.currentPost.title, self.currentPost.link]];
// Get the ShareKit action sheet
// This works
SHKActionSheet *actionSheet = [SHKActionSheet actionSheetForItem:item];
// ShareKit detects top view controller (the one intended to present ShareKit UI) automatically,
// but sometimes it may not find one. To be safe, set it explicitly.
[SHK setRootViewController:self];
// Display the action sheet.
[actionSheet showInView:self.view];
}
Any ideas or what I'm missing or doing wrong?
Try to change the RootViewController and view you are using:
[SHK setRootViewController:self.view.window.rootViewController];
[actionSheet showInView:self.view.window.rootViewController.view];
Most likely your view controller hierarchy is somewhat messed up.

Upload photo using new iOS Facebook SDK API (3.0)

How can I upload a photo to facebook from an iOS app using their new API/SDK? I've already tried and I'm not getting anywhere, just keep running in circles. Here is the code I currently have:
-(void)dataForFaceboo{
self.postParams =
[[NSMutableDictionary alloc] initWithObjectsAndKeys:
self.uploadPhoto.image, #"picture", nil];
}
-(void)uploadToFacebook{
[self dataForFacebook];
NSLog(#"Going to facebook: %#", self.postParams);
// Hide keyboard if showing when button clicked
if ([self.photoCaption isFirstResponder]) {
[self.photoCaption resignFirstResponder];
}
// Add user message parameter if user filled it in
if (![self.photoCaption.text
isEqualToString:kPlaceholderPostMessage] &&
![self.photoCaption.text isEqualToString:#""])
{
[self.postParams setObject:self.photoCaption.text forKey:#"message"];
}
[FBRequestConnection startWithGraphPath:#"me/feed"
parameters:self.postParams
HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error)
{
NSString *alertText;
if (error) {
alertText = [NSString stringWithFormat:
#"error: domain = %#, code = %d",
error.domain, error.code];
} else {
alertText = [NSString stringWithFormat:
#"Posted action, id: %#",
[result objectForKey:#"id"]];
}
// Show the result in an alert
[[[UIAlertView alloc] initWithTitle:#"Result"
message:alertText
delegate:self
cancelButtonTitle:#"OK!"
otherButtonTitles:nil] show];
}];
}
Your code is fine, some slight changes to be done:
add the image to the dictionary in NSData format, like
[params setObject:UIImagePNGRepresentation(_image) forKey:#"picture"];
and change the graph path to "me/photos" instead of "me/feed"
Make these changes, it worked for me.
Remember you need to use "publish_actions" permissions.
"me/photos" is meant for the photo actually be in the "Photo's" list on your Facebook profile. "me/feed" is just a post on the timeline.

Updating UITextField with contact info selected from iPhone Contacts

After calling the PeoplePicker and selecting an entry from Contacts I can't seem to get the selected contact information to display in my view. Following Apple's Address Book Programming Guide for iOS, I display the People Picker modally and make a selection. Apple's code examples have the information being displayed in UILabels while I, because I also allow the user to manually input information into the text fields in the same view controller, need to have the information displayed in UITextFields. I've proved that the selected data winds up in the target UITextField (which is named "contactName") by printing to the console. The problem is, the selected data is not displayed in the view. When the user inputs manually, there is no problem. I just can't figure out how to transfer the data from the Address Book into the UITextFields in the view controller.
I've been trying for days, but can't resolve this issue. I'm probably overlooking something very basic. I'm new at this, so any help will be appreciated.
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person
{
// NSString* name = (NSString *)ABRecordCopyValue(person,kABPersonFirstNameProperty);
NSString *name = [NSString stringWithFormat:#"%# %#",ABRecordCopyValue(person,kABPersonFirstNameProperty), ABRecordCopyValue(person,kABPersonLastNameProperty)];
self.contactName.text = name; // 11/17/11
NSLog(#"%#", name);
// [name release]; Commenting out this code prevents the app from freezing when a name is selected from the picker. 11/25/11
NSLog(#"%#",self.contactName.text); // 11/17/11
// 11/16/11 add additional contact info here
[self dismissModalViewControllerAnimated:YES];
return NO;
}
As of iOS 6, [self dismissModalViewControllerAnimated] is deprecated. If you try this, your code will work.
[self dismissViewControllerAnimated:YES completion:^(void) {
NSString *name = [NSString stringWithFormat:#"%#", ABRecordCopyValue(person, kABPersonFirstNameProperty)];
contactName.text=name;
}];
-(IBAction)addToAddressbook:(id)sender{
NSString *fname=#"firstname";
NSString *lname=#"lastname";
NSArray *arrayAdd=[[NSArray alloc]initWithObjects:#"street Name",#"city Name",#"country code",#"zip",nil];
UIImage *image=[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:#"ambani.png" ofType:nil]];
[self addContact:fname:lname:arrayAdd:image];
}
-(void) addContact:(NSString *)firstname:(NSString *)lastname:(NSArray *)arrayAddress:(UIImage *)currentImage
{
ABAddressBookRef addressBook=ABAddressBookCreate();
ABRecordRef person=ABPersonCreate();
//set Image
NSData * dataRef = UIImagePNGRepresentation(currentImage);
ABPersonSetImageData(person, (CFDataRef)dataRef, nil);
//set FirstName and LastName
ABRecordSetValue(person, kABPersonFirstNameProperty,firstname, nil);
ABRecordSetValue(person, kABPersonLastNameProperty,lastname, nil);
//Add Address
ABMutableMultiValueRef address=ABMultiValueCreateMutable(kABMultiDictionaryPropertyType);
NSMutableDictionary *addressDictionary=[[NSMutableDictionary alloc]init];
[addressDictionary setObject:[arrayAddress objectAtIndex:0] forKey:(NSString *)kABPersonAddressStreetKey];
[addressDictionary setObject:[arrayAddress objectAtIndex:1]forKey:(NSString *)kABPersonAddressCityKey];
[addressDictionary setObject:[arrayAddress objectAtIndex:2] forKey:(NSString *)kABPersonAddressCountryCodeKey];
[addressDictionary setObject:[arrayAddress objectAtIndex:3] forKey:(NSString *)kABPersonAddressCountryKey];
ABMultiValueAddValueAndLabel(address, addressDictionary, kABHomeLabel, nil);
ABRecordSetValue(person, kABPersonAddressProperty, address, nil);
ABAddressBookAddRecord(addressBook,person, nil);
ABAddressBookSave(addressBook,nil);
objABPersonViewController=[[ABUnknownPersonViewController alloc]init];
objABPersonViewController.displayedPerson=person;
[self.navigationController pushViewController:objABPersonViewController animated:YES];
CFRelease(person);
}
-(void) validateAndDisplayContacts
{
if([firstName length]==0)
{
firstName=#" ";
}
lblName.text=[NSString stringWithFormat:#"%# : %#",#"First Name",name];
[firstName release];
if([mobile length]==0)
{
mobile=#" ";
}
lblPhone.text=[NSString stringWithFormat:#"%# : %#",#"Mobile",mobile];
[mobile release];
if([email length]==0)
{
email=#" ";
}
lblEmail.text=[NSString stringWithFormat:#"%# : %#",#"Email",email];
[email release];
}
- (void)unknownPersonViewController:(ABUnknownPersonViewController *) unknownCardViewController didResolveToPerson:(ABRecordRef)person
{
[objABPersonViewController dismissModalViewControllerAnimated:YES];
}