Wednesday, January 28, 2015

objective-c unique identifier for each iOS device

 if ([[UIDevice currentDevice] respondsToSelector:@selector(identifierForVendor)]) {
        
       str1=[NSString stringWithFormat:@"%@",
                             [[[UIDevice currentDevice] identifierForVendor] UUIDString]];
             

         }

objective-c substring of length

NSString* feng = [string substringToIndex:4]
NSString* zhong = [string substringFromIndex:5]

Monday, January 5, 2015

NSString to NSData

SString* myStr = @"This is the Testing String";

NSData* cData = [myStr dataUsingEncoding:NSUTF8StringEncoding];

Thursday, September 18, 2014

Iphone: Volume control in IOS8

MPVolumeView* volumeView;
//find the volumeSlider
UISlider* volumeViewSlider;

for (UIView *view in [volumeView subviews]){
        if ([view.class.description isEqualToString:@"MPVolumeSlider"]){
            volumeViewSlider = (UISlider*)view;
            break;
        }
    }
    
    if (volumeViewSlider !=nil) {
         [volumeViewSlider setValue:volume animated:YES];

    }


In IOS7 it was
[[MPMusicPlayerController applicationMusicPlayer] setVolume:volume];

Friday, September 12, 2014

IPhone: IOS8 Error Trying to start MapKit location updates without prompting for location authorization

Here is my full code to get the MapKit Map View working in iOS8!
In your AppName-Info.plist Add a new row with the key name being:
NSLocationWhenInUseUsageDescription
And/Or
NSLocationAlwaysUsageDescription
With the value being a string of the message that you want to be displayed:
YourAppName would like to use your location.
In your header file. (I use App Name-Prefix.pch but YourViewController.h will work too)
#define IS_OS_8_OR_LATER ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
self.locationManager = [[CLLocationManager alloc] init];
    if(IS_OS_8_OR_LATER) {
        [self.locationManager requestWhenInUseAuthorization];
        [self.locationManager requestAlwaysAuthorization];
    }