At the moment I'm working on a iPhone app and I have a problem.
I want, that the player can send a gamecenter friendrequest.
In the apple Guide there are two methods I'm interested in.
The first would be
- (void)addRecipientsWithPlayerIDs:(NSArray *)playerids
and the second would be
- (void)setMessage:(NSString *)message
Now I don't know to put them in the right order to get on.
How can I set the player ID's and the message, and after that, how can I send the request.
Suppose you have player ids in friendsArray. Then try this:
GKFriendRequestComposeViewController *friendRequestViewController = [[GKFriendRequestComposeViewController alloc] init];
friendRequestViewController.composeViewDelegate = self;
[friendRequestViewController setMessage:#"Add your message here"];
if (friendsArray)
{
[friendRequestViewController addRecipientsWithPlayerIDs: friendsArray];
}
[self presentModalViewController: friendRequestViewController animated: YES];
Hope this helps.. :)
Related
I want the App to show all leaderboard when a user logs into the Game Center. I wrote the following code to do that, and it works OK until I once disconnected the network.
The App started without network, but local Game Center was logged in. When I reconnected the network and tapped to show leaderboards, it showed "No data available". I must terminate and reopen the App to make it work.
Oddly enough, if I added setLeaderboardIdentifier and did the same thing above, the specified leaderboard could be shown after network connected again.
Anything Wrong? Thanks
- (void)showGameCenter{
GKGameCenterViewController *gameView = [[GKGameCenterViewController alloc] init];
if(gameView != nil){
gameView.gameCenterDelegate = self;
[gameView setViewState:GKGameCenterViewControllerStateLeaderboards];
[gameView setLeaderboardTimeScope:GKLeaderboardTimeScopeAllTime];
// //[gameView setLeaderboardIdentifier:#"xxxxxxxxx"];
[self presentViewController: gameView animated: YES completion:nil];
}
}
I'm using UIImagePickerController to take pictures and videos from my app. Toggling between the two isn't too bad. If the user chooses to record a video, I first check this:
if (picker.cameraCaptureMode == UIImagePickerControllerCameraCaptureModeVideo)
{
[self captureVideo];
}
else
{
picker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModeVideo;
[self captureVideo];
}
This usually works totally fine. Here's the catch. I'm also using OpenTok by Tokbox to do video calls, and it seems like the captureMode assignment doesn't work after a video call. It seems completely crazy, but I made this modification to do some debugging:
if (picker.cameraCaptureMode == UIImagePickerControllerCameraCaptureModeVideo)
{
[self captureVideo];
}
else
{
picker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModeVideo;
if (picker.cameraCaptureMode != UIImagePickerControllerCameraCaptureModeVideo)
{
NSLog(#"Assignment unsuccessful???")
}
[self captureVideo];
}
And i get this "Assignment unsuccessful???" log every single time. UIImagePickerController must not be allowing the assignment or something. I really can't figure it out. I've also made a forum post on OpenTok's site to see if they're possibly not releasing some camera resources, but I don't think it's their problem.
Any insight here?
Use:
+ (NSArray *)availableCaptureModesForCameraDevice:(UIImagePickerControllerCameraDevice)cameraDevice
to check which source types are available. Also if you're using a simulator, it will never assign properly.
Solved with a solution on the TokBox forum. I needed to first change my audio session before trying to access the microphone.
AVAudioSession *mySession = [AVAudioSession sharedInstance];
[mySession setCategory:AVAudioSessionCategorySoloAmbient error:nil];
[self presentViewController:picker animated:YES completion:NULL];
I am using the most recent PayPal iOS sdk in my app. For some unknown reason, when I try to init the PayPalPaymentViewContoller then present it, it is crashing. I have determined that the viewController is nil, but I have no idea why.
Here are the two lines of code to do with this.
The first line is the init, and the second is present
PayPalPaymentViewController *paymentViewController = [[PayPalPaymentViewController alloc] initWithPayment:payment configuration:self.payPalConfig delegate:self];
[self presentViewController:paymentViewController animated:YES completion:nil];
Any ideas? Let me what more information you need. I am not really sure what else to provide.
Dave from PayPal here.
#linuxer have you followed our sample code? In particular, from step 5:
// Check whether payment is processable.
if (!payment.processable) {
// If, for example, the amount was negative or the shortDescription was empty, then
// this payment would not be processable. You would want to handle that here.
}
If the payment is not "processable", but you go ahead anyway to create the PayPalPaymentViewController, then you would indeed get back nil.
You should also see a message to that effect in your console log. Have you taken a look there?
When you create object for PayPalItem at here in withPrice param, amount always be in two value after decimal. See below example:
PayPalItem *item1 = [PayPalItem itemWithName:#"T Shirt" withQuantity:1 withPrice:[NSDecimalNumber decimalNumberWithString:**
[NSString stringWithFormat:#"%0.2f",overAllTotalAmt]
**] withCurrency:#"USD" withSku:#"Hip-00037"];
I have read allot in previous threads about FacebookSDK vs SocialFramework but I cant find anything regarding the more specific area of FriendPicker.
I have a picture in my application. Right now I use SLcomposeView to post to Facebook which works great.
I now want to add the possibility to tag a facebookfriend in that picture and post the picture with the friend included.
I first followed the: FriendPicker example - FacebookDev
My LoadData function will however not load any data probably because it doesnt use the Facebook Account from settings.
I then tried the code from the provided Facebook FreindPicker example (From the FacebookSDK). I then get bounced to facebook sign in but I receive sign in error (Error: 2) probably because I am already signed in through settings?
How do I best design the application for handling this?
Can I include "friendpicking" in the SlComposeView or do I need to remove it and only use Facebook SDK?
Will be better if you can post some of your code... Im using the following example to invoke the FBFriendPickerViewController
- (IBAction)addTAG:(id)sender {
if (self.friendPickerController == nil) {
// Create friend picker, and get data loaded into it.
self.friendPickerController = [[FBFriendPickerViewController alloc] init];
self.friendPickerController.title = #"Select Friends";
self.friendPickerController.delegate = self;
}
[self.friendPickerController loadData];
[self.friendPickerController clearSelection];
// Present the friend picker
[self.friendPickerController presentModallyFromViewController:self
animated:YES
handler:^(FBViewController *sender, BOOL donePressed) {
if (donePressed) {
self.selectedFriends = self.friendPickerController.selection;
NSLog(#"list of friends: %#", self.selectedFriends);
}
}];
}
Regards
Edited// the Scrumptious example app contains all what you need. Download the las facebokk SDK for iOS, go to samples.
I wanna set a button inside my app that, if clicked, app can jump to the default mailbox of iOS. I want to do this so users can check & send their mails.
Does this function need a private API or is this forbidden by Apple?
Thanks in advance for your kind help.
This does what you want:
let app = UIApplication.shared
if let url = NSURL(string: "message:"), app.canOpenURL(url) {
app.openURL(url)
}
The canOpenURL part checks if the user has got at least one email address setup in Mail that they can send/receive from.
Maybe you can use the url scheme like this:
NSString *email = #"mailto:?subject=YourSubject&body=MsgBody";
email = [email stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
[[UIApplication sharedApplication] openURL: [NSURL URLWithString:email]];
To Send an email from within your app, one of the first 2 answers will work: MFMailComposeViewController or using the url scheme mailto://.
As for checking the users email, there is currently no public way to launch the default iOS mail application. There are however a few 3rd party libraries available to allow you to set up your own mail client, for example MailCore, remail or Chilkat. I'm sure there are others but you get the idea.
How about using MFMailComposeViewController? You can set its subject, recipients, message body, the attachment, and then you can present it modally within your app. It will be better too since the user does not need to leave your app.
if ([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init];
mailViewController.mailComposeDelegate = self;
[mailViewController setSubject:subjectString];
[mailViewController setMessageBody:messageString isHTML:YES];
[self presentViewController:mailViewController animated:YES completion:nil];
}
Just remember to set the view controller calling the function above as the delegate of MFMailComposeViewControllerDelegate so that you can dismiss the view controller afterwards.
-(void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
[self dismissViewControllerAnimated:YES completion:nil];
}
Apple documentation on this class:
http://developer.apple.com/library/ios/#documentation/MessageUI/Reference/MFMailComposeViewController_class/Reference/Reference.html