how to make separate achievements - iphone

I have achievements in game Center for my iPhone but my app is universal so am making achievements for the iPad i don't want them to be displayed with the iPhone achievements i want them both to be seperate
-(void)checkAchievements6
{
if(score>10000)//achievement for getting 10000 points.
{
GKAchievement *achievement= [[GKAchievement alloc] initWithIdentifier:#"5Digit"];
achievement.percentComplete = 100.0;
achievement.showsCompletionBanner=YES;
if(achievement!= NULL)
{
[achievement reportAchievementWithCompletionHandler: ^(NSError *error)
{
if(error != nil){
NSLog(#"Achievement failed");
}
else
{
NSLog(#"Achievement Success");
}
}];
}
}
}

I'm not sure if this is exactly what you are asking, but could it be something like this?
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
//iPhone achievement code
} else {
//iPad achievement code
}

Related

To detect IOS device type

I have found the solutions from here:
Determine device (iPhone, iPod Touch) with iPhone SDK
From the link, it suggests to use the library https://gist.github.com/1323251
But obviously the library is quite outdated. I couldn't find the iPhone 5 and new iPad and etc in the list.
Does anyone know how can I find the completed and updated list?
Thank you so much.
you can easily detect iphone, iphone5 and iPad with below condition:-
if([[UIDevice currentDevice]userInterfaceIdiom]==UIUserInterfaceIdiomPhone)
{
if ([[UIScreen mainScreen] bounds].size.height == 568.0f)
{
}
else
{
//iphone 3.5 inch screen
}
}
else
{
//[ipad]
}
my answer:-
Detect device type
Here's the updated version of https://gist.github.com/1323251 .
I'll keep it updated when new devices are released.
https://github.com/froztbytes/UIDeviceHardware
This works just fine:
if([UIDevice currentDevice].userInterfaceIdiom==UIUserInterfaceIdiomPad) {
NSLog(#"IPAD");
}else{
NSLog(#"IPHONE");
}
Just adding to #Mohammad Kamran Usmani answer. More specific iPhone types:
#import UIKit;
//Check which iPhone it is
double screenHeight = [[UIScreen mainScreen] bounds].size.height;
if(UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPad)
{
NSLog(#"All iPads");
} else if (UI_USER_INTERFACE_IDIOM()== UIUserInterfaceIdiomPhone)
{
if(screenHeight == 480) {
NSLog(#"iPhone 4/4S");
smallFonts = true;
} else if (screenHeight == 568) {
NSLog(#"iPhone 5/5S/SE");
smallFonts = true;
} else if (screenHeight == 667) {
NSLog(#"iPhone 6/6S");
} else if (screenHeight == 736) {
NSLog(#"iPhone 6+, 6S+");
} else {
NSLog(#"Others");
}
}
Use the following code:
#import <sys/utsname.h>
- (NSString *)machineName
{
struct utsname systemInfo;
uname(&systemInfo);
NSString *temp = [NSString stringWithCString:systemInfo.machine
encoding:NSUTF8StringEncoding];
if ([temp rangeOfString:#"iPod"].location != NSNotFound)
{
return #"iPod";
}
if ([temp rangeOfString:#"iPad"].location != NSNotFound)
{
return #"iPad";
}
if ([temp rangeOfString:#"iPhone"].location != NSNotFound)
{
return #"iPhone";
}
return #"Unknown device";
}
I'm with other guys are maintaining the code on GitHub so please take the latest code from there. We're continuously adding new devices in the list.
Objective-C : GitHub/DeviceUtil
Swift : GitHub/DeviceGuru
#include <sys/types.h>
#include <sys/sysctl.h>
- (NSString*)hardwareDescription {
NSString *hardware = [self hardwareString];
if ([hardware isEqualToString:#"iPhone1,1"]) return #"iPhone 2G";
if ([hardware isEqualToString:#"iPhone1,2"]) return #"iPhone 3G";
if ([hardware isEqualToString:#"iPhone3,1"]) return #"iPhone 4";
if ([hardware isEqualToString:#"iPhone4,1"]) return #"iPhone 4S";
if ([hardware isEqualToString:#"iPhone5,1"]) return #"iPhone 5";
if ([hardware isEqualToString:#"iPod1,1"]) return #"iPodTouch 1G";
if ([hardware isEqualToString:#"iPod2,1"]) return #"iPodTouch 2G";
if ([hardware isEqualToString:#"iPad1,1"]) return #"iPad";
if ([hardware isEqualToString:#"iPad2,6"]) return #"iPad Mini";
if ([hardware isEqualToString:#"iPad4,1"]) return #"iPad Air WIFI";
//there are lots of other strings too, checkout the github repo
//link is given at the top of this answer
if ([hardware isEqualToString:#"i386"]) return #"Simulator";
if ([hardware isEqualToString:#"x86_64"]) return #"Simulator";
return nil;
}
- (NSString*)hardwareString {
size_t size = 100;
char *hw_machine = malloc(size);
int name[] = {CTL_HW,HW_MACHINE};
sysctl(name, 2, hw_machine, &size, NULL, 0);
NSString *hardware = [NSString stringWithUTF8String:hw_machine];
free(hw_machine);
return hardware;
}
You can use the following code
if(screenSize.width==2048 && screenSize.height==1536)
{
LetterParams.DeviceType=1;//IPadRetina
}
else if(screenSize.width==2048/2 && screenSize.height==1536/2)
{
LetterParams.DeviceType=2;//IPad Non-Retina
}
else if(screenSize.width==1136 && screenSize.height==640)
{
LetterParams.DeviceType=3;//IPhoneRetina
}
else
{
LetterParams.DeviceType=4;//IPhone & Ipod
}
Here is a method that I came up with that focuses on key devices for screen measurement functions. It is a quick way to determine what you need. This will detect up to iPhone 5 and 5th Gen. iPod touches.
typedef enum{
iPadRetina,iPadNoRetina,iPhoneiPod35InchRetina,iPhoneiPod35InchNoRetina,iPhoneiPod4InchRetina}DeviceType;
-(void)yourCustomFunctionThatNeedsToKnowDeviceType
{
NSLog(#"device type = %i",[self getDeviceType]);
switch ([self getDeviceType])
{
case iPadRetina:
{
NSLog(#"This device is one of the following: iPad 3, iPad 4");
break;
}
case iPadNoRetina:
{
NSLog(#"This device is one of the following: iPad 1, iPad 2, iPad mini");
break;
}
case iPhoneiPod35InchRetina:
{
NSLog(#"This device is one of the following: iPhone 4/4S or iPod Touch 4th Generation");
break;
}
case iPhoneiPod35InchNoRetina:
{
NSLog(#"This device is one of the following: iPhone 3G/3GS or iPod Touch 3rd Generation");
break;
}
case iPhoneiPod4InchRetina:
{
NSLog(#"This device is one of the following: iPhone 5 or iPod Touch 5th Generation");
break;
}
}
}
-(int)getDeviceType
{
// Get the ratio of the device's screen (height/width)
CGFloat screenRatio = [UIScreen mainScreen].bounds.size.height/[UIScreen mainScreen].bounds.size.width;
// Initialize return value to negative value
DeviceType type = -1;
if(screenRatio > 1.5)
{
/*
4.0-Inch Screen
This implies that the device is either an iPhone 5 or a 5th generation iPod
Retina display is implicit
*/
type = iPhoneiPod4InchRetina;
}
else
{
/*
Device must be iPad 1/2/3/4/mini or iPhone 4/4S or iPhone 3G/3GS
*/
// Take a screenshot to determine if the device has retina display or not
UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, 0.0);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *scaleCheckImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
{
/*
Device must be iPad 1/2/3/4/mini
*/
if(scaleCheckImage.scale == 1)
{
// iPad 1/2/mini (No Retina)
type = iPadNoRetina;
}
else if(scaleCheckImage.scale == 2)
{
// iPad 3/4 (Retina)
type = iPadRetina;
}
}
else
{
/*
Device must be iPhone 4/4S or iPhone 3G/3GS or iPod Touch 3rd Generation or iPod Touch 4th Generation
*/
if(scaleCheckImage.scale == 1)
{
// iPhone 3G/3GS or iPod Touch 3rd Generation (No Retina)
type = iPhoneiPod35InchNoRetina;
}
else if(scaleCheckImage.scale == 2)
{
// iPhone 4/4S or iPod Touch 4th Generation (Retina)
type = iPhoneiPod35InchRetina;
}
}
}
return type;
}
if(UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPad)
{
NSLog(#"All iPads");
}
else
{
else if (UI_USER_INTERFACE_IDIOM()== UIUserInterfaceIdiomPhone)
{
if( screenHeight > 480 && screenHeight < 667 )
{
NSLog(#"iPhone 5/5s/6");
}
else if ( screenHeight > 480 && screenHeight < 736 )
{
NSLog(#"Other iPhones Resizable");
}
else if ( screenHeight > 480 )
{
NSLog(#"iPhone 6 +");
}
else
{
NSLog(#"iPhone 4s and others");
}
}

How to check live streaming url response iphone

In my app I am doing live streaming with the following code :
-(void)playurl:(id)sender
{
self.mpPlayer=[[[MPMoviePlayerController alloc]initWithContentURL:[NSURL URLWithString:#"http://alwatan.lsops.net/live/alwradio_ar_audio.sdp/playlist.m3u8"]] autorelease];
[self.mpPlayer prepareToPlay];
if(interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
self.mpPlayer.view.frame = CGRectMake(0, 50, 768, 400);
}
else if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
self.mpPlayer.view.frame = CGRectMake(0, 0, 1024, 500);
}
[self.mpPlayer play];
self.mpPlayer.movieSourceType = MPMovieSourceTypeStreaming;
//self.mpPlayer.movieSourceType = MPMovieSourceTypeFile;
self.mpPlayer.shouldAutoplay = TRUE;
self.mpPlayer.controlStyle = MPMovieControlStyleDefault;
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:mpPlayer];
[scrollView addSubview:self.mpPlayer.view];
if(isVideoPlay)
{
isVideoPlay = FALSE;
}
else
{
isVideoPlay = TRUE;
}
}
- (void) moviePlayBackDidFinish:(NSNotification*)notification
{
NSError *error = [[notification userInfo] objectForKey:#"error"];
if (error) {
}
else
{
MPMoviePlayerController *moviePlayer = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer];
}
}
Everything is fine but my problem is that is url is not runing then application will be crashed so how can I check the live streaming url response so I can mange the condition and give alert for url not respond.
Thanks,
Use the following notification
MPMoviePlayerPlaybackStateDidChangeNotification
and check for
 if(moviePlayer.state == MPMoviePlaybackStateStopped)
{
// Alert
}
else  if(moviePlayer.state == MPMoviePlaybackStatePlaying)
{
// Alert
}
else  if(moviePlayer.state == MPMoviePlaybackStatePaused)
{
// Alert
}
else  if(moviePlayer.state == MPMoviePlaybackStateInterrupted)
{
// Alert
}
else  if(moviePlayer.state == MPMoviePlaybackStateSeekingForward)
{
// Alert
}
else  if(moviePlayer.state == MPMoviePlaybackStateSeekingBackward)
{
// Alert
}
My experience with MPMoviePlayerControler has been that it's not very good with error handling. One possibility would be to request the URL first, then only load the .m3u8 file when your stream is running.
You could use NSURLConnection and friends to try and load the stream, and, if necessary, read the file looking for something specific that indicates the stream is running (perhaps the presence of a line containing #EXTINF:.

GameCenter integration Complications?

I called the code below to add Game center user banner pop up at the top of the screen, but it says Game is not recognized by Game Center:
I added this to my addDidFinishLaunching:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
[[GKLocalPlayer localPlayer] authenticateWithCompletionHandler:^(NSError *error){
if (error ==nil) {
NSLog(#"Success");
} else {
NSLog(#"Fail");
}
}];
For viewing leader boards, what code do I need to add to properly call it?
-(void)viewscores:(SPEvent*)event{
CODE HERE
}
You could try it like that :
GKLeaderboardViewController *leaderboardVC = [[[GKLeaderboardViewController alloc]init]autorelease];
if (leaderboardVC !=nil) {
leaderboardVC.leaderboardDelegate = self;
[self presentViewController:leaderboardVC];
}
I hope it helps :-)

iPhone: first song not pause before start next song

In My app Song play through buffering,
I have two music player in my app,
But it plays both musicplayer songs together. It does not pause the first song even when I try to pause.
i refer this tutorial:
http://cocoawithlove.com/2008/09/streaming-and-playing-live-mp3-stream.html
for that i try to call
[streamer pause];
- (void)pause
{
#synchronized(self)
{
if (state == AS_PLAYING)
{
err = AudioQueuePause(audioQueue);
if (err)
{
[self failWithErrorCode:AS_AUDIO_QUEUE_PAUSE_FAILED];
return;
}
self.state = AS_PAUSED;
}
else if (state == AS_PAUSED)
{
err = AudioQueueStart(audioQueue, NULL);
if (err)
{
[self failWithErrorCode:AS_AUDIO_QUEUE_START_FAILED];
return;
}
self.state = AS_PLAYING;
}
}
}
streamer calls the pause method of buffering.
How can i do that?
if (audioPlayer.playing==YES) {
[audioPlayer pause];
}
try this.

MPMoviePlayerController play error on iPad

I'm writing an app that will be playing videos alot using the MPMoviePlayerController on the iPad. The problem is the app was working fine and playing the videos when I stopped working about 15 hours ago but now the videos do not play. The MPMoviePlayerController will show the first frame from the video, and in full screen view I can scrub through the movie fine but when I hit play it just pauses right away. I have the code below, when debugging i noticed that when I call play it sends an MPMoviePlayerPlaybackStateDidChangeNotification with the playbackState being MPMoviePlaybackStatePlaying and then right away it sends another MPMoviePlayerPlaybackStateDidChangeNotification notification with playbackState being MPMoviePlaybackStatePaused. Not sure if that helps but please let me know if you see anything wrong in my code or have an ideas, thanks.
- (void)handleNotification:(NSNotification *)notification {
if ([[notification name] isEqualToString:MPMoviePlayerPlaybackStateDidChangeNotification]) {
if (_videoPlayer.playbackState == MPMoviePlaybackStatePlaying) {
_playButtonLarge.hidden = YES;
_scrubber.maximumValue = _videoPlayer.duration;
[_playPauseButton setBackgroundImage:[UIImage imageNamed:#"video_controls_pause.png"] forState:UIControlStateNormal];
if (_updateScrubberTimer == nil) {
_updateScrubberTimer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:#selector(updateScrubber) userInfo:nil repeats:YES];
}
} else if (_videoPlayer.playbackState == MPMoviePlaybackStatePaused || _videoPlayer.playbackState == MPMoviePlaybackStateStopped) {
[_playPauseButton setBackgroundImage:[UIImage imageNamed:#"video_controls_play.png"] forState:UIControlStateNormal];
_playButtonLarge.hidden = NO;
if (_updateScrubberTimer != nil) {
[_updateScrubberTimer invalidate];
_updateScrubberTimer = nil;
}
if (_videoPlayer.playbackState == MPMoviePlaybackStateStopped) {
_scrubber.value = 0.0f;
_timePlayedLabel.text = #"0:00";
_timeRemainingLabel.text = #"-0:00";
_videoPlayerBG.hidden = NO;
}
}
} else if ([[notification name] isEqualToString:MPMoviePlayerPlaybackDidFinishNotification]) {
NSNumber *reason = [[notification userInfo] objectForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey];
if ([reason intValue] == MPMovieFinishReasonPlaybackEnded) {
_videoPlayerBG.hidden = NO;
}
_scrubber.value = _scrubber.maximumValue;
}
}
- (void)playPause {
if ([_videos count] > 0) {
if (_videoPlayer.playbackState == MPMoviePlaybackStatePaused || _videoPlayer.playbackState == MPMoviePlaybackStateStopped) {
_playButtonLarge.hidden = YES;
_videoPlayerBG.hidden = YES;
if ([_videoPlayer contentURL] == nil) {
Video *video = [_videos objectAtIndex:0];
[_videoPlayer setContentURL:video.videoURL];
}
if (![_videoPlayer isPreparedToPlay]) {
[_videoPlayer prepareToPlay];
}
[_videoPlayer play];
} else if (_videoPlayer.playbackState == MPMoviePlaybackStatePlaying) {
_playButtonLarge.hidden = NO;
[_videoPlayer pause];
}
}
}
I think I figured it out, I put the following code before every call to play
if (![_videoPlayer isPreparedToPlay]) {
[_videoPlayer prepareToPlay];
}
works now, if anyone else has any input let me know