- NSString *identifierForVendor = [[UIDevice currentDevice].identifierForVendor UUIDString];
- NSString *identifierForAdvertising = [[ASIdentifierManager sharedManager].advertisingIdentifier UUIDString];
- //第一次调用这个方法的时候,系统会提示用户让他同意你的app获取麦克风的数据
- // 其他时候调用方法的时候,则不会提醒用户
- // 而会传递之前的值来要求用户同意
- [[AVAudioSession sharedInstance] requestRecordPermission:^(BOOL granted) {
- if (granted) {
- // 用户同意获取数据
- } else {
- // 可以显示一个提示框告诉用户这个app没有得到允许?
- }
- }];
- NSArray *arr = @[];
- id item = [arr firstObject];
- // 之前你需要做以下工作
- id item = [arr count] > 0 ? arr[0] : nil;
- UIImageRenderingModeAutomatic // 根据图片的使用环境和所处的绘图上下文自动调整渲染模式。
- UIImageRenderingModeAlwaysOriginal // 始终绘制图片原始状态,不使用Tint Color。
- UIImageRenderingModeAlwaysTemplate // 始终根据Tint Color绘制图片,忽略图片的颜色信息。
- UIImage *img = [UIImage imageNamed:@"myimage"];
- img = [img imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
- UINavigationBar *bar = self.navigationController.navigationBar;
- UIColor *color = [UIColor greenColor];
- if ([bar respondsToSelector:@selector(setBarTintColor:)]) { // iOS 7+
- bar.barTintColor = color;
- } else { // what year is this? 2012?
- bar.tintColor = color;
- }
- + (UIColor *)viewFlipsideBackgroundColor;
- + (UIColor *)scrollViewTexturedBackgroundColor;
- + (UIColor *)underPageBackgroundColor;
- @property (nonatomic, readonly) BOOL wirelessRoutesAvailable; // 是否有设备可以连接的无线线路?
- @property (nonatomic, readonly) BOOL wirelessRouteActive; // 设备现在是否连接上了网络
- NSString *const MPVolumeViewWirelessRoutesAvailableDidChangeNotification;
- NSString *const MPVolumeViewWirelessRouteActiveDidChangeNotification;
- @import CoreTelephony.CTTelephonyNetworkInfo; // new modules syntax!
- @interface AppDelegate ()
- // we need to keep a reference to the CTTelephonyNetworkInfo object, otherwise the notifications won't be fired!
- @property (nonatomic, strong) CTTelephonyNetworkInfo *networkInfo;
- @end
- @implementation ViewController
- - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
- // whatever stuff your method does...
- self.networkInfo = [[CTTelephonyNetworkInfo alloc] init];
- NSLog(@"Initial cell connection: %@", self.networkInfo.currentRadioAccessTechnology);
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(radioAccessChanged) name:
- CTRadioAccessTechnologyDidChangeNotification object:nil];
- // whatever stuff your method does...
- }
- - (void)radioAccessChanged {
- NSLog(@"Now you're connected via %@", self.networkInfo.currentRadioAccessTechnology);
- }
- @end
- #import <SSKeychain.h>
- - (BOOL)saveCredentials:(NSError **)error {
- SSKeychainQuery *query = [[SSKeychainQuery alloc] init];
- query.password = @"MySecretPassword";
- query.service = @"MyAwesomeService";
- query.account = @"John Doe";
- query.synchronizable = YES;
- return [query save:&error];
- }
- - (NSString *)savedPassword:(NSError **)error {
- SSKeychainQuery *query = [[SSKeychainQuery alloc] init];
- query.service = @"MyAwesomeService";
- query.account = @"John Doe";
- query.synchronizable = YES;
- query.password = nil;
- if ([query fetch:&error]) {
- return query.password;
- }
- return nil;
- }
- NSString *html = @"<bold>Wow!</bold> Now <em>iOS</em> can create <h3>NSAttributedString</h3> from HTMLs!";
- NSDictionary *options = @{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType};
- NSAttributedString *attrString = [[NSAttributedString alloc] initWithData:[html dataUsingEncoding:NSUTF8StringEncoding]
- options:options documentAttributes:nil error:nil];
- #import <SSKeychain.h>
- - (BOOL)saveCredentials:(NSError **)error {
- SSKeychainQuery *query = [[SSKeychainQuery alloc] init];
- query.password = @"MySecretPassword";
- query.service = @"MyAwesomeService";
- query.account = @"John Doe";
- query.synchronizable = YES;
- return [query save:&error];
- }
- - (NSString *)savedPassword:(NSError **)error {
- SSKeychainQuery *query = [[SSKeychainQuery alloc] init];
- query.service = @"MyAwesomeService";
- query.account = @"John Doe";
- query.synchronizable = YES;
- query.password = nil;
- if ([query fetch:&error]) {
- return query.password;
- }
- return nil;
- NSAttributedString *attrString; // from previous code
- NSDictionary *options = @{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType};
- NSData *htmlData = [attrString dataFromRange:NSMakeRange(0, [attrString length]) documentAttributes:options error:nil];
- NSString *htmlString = [[NSString alloc] initWithData:htmlData encoding:NSUTF8StringEncoding];
- // From NSData.h
- /* Create an NSData from a Base-64 encoded NSString using the given options. By default, returns nil when the input is not recognized
- as valid Base-64.
- */
- - (id)initWithBase64EncodedString:(NSString *)base64String options:(NSDataBase64DecodingOptions)options;
- /* Create a Base-64 encoded NSString from the receiver's contents using the given options.
- */
- - (NSString *)base64EncodedStringWithOptions:(NSDataBase64EncodingOptions)options;
- /* Create an NSData from a Base-64, UTF-8 encoded NSData. By default, returns nil when the input is not recognized as valid Base-64.
- */
- - (id)initWithBase64EncodedData:(NSData *)base64Data options:(NSDataBase64DecodingOptions)options;
- /* Create a Base-64, UTF-8 encoded NSData from the receiver's contents using the given options.
- */
- - (NSData *)base64EncodedDataWithOptions:(NSDataBase64EncodingOptions)options;
- NSData* sampleData = [@"Some sample data" dataUsingEncoding:NSUTF8StringEncoding];
- NSString * base64String = [sampleData base64EncodedStringWithOptions:0];
- NSLog(@"Base64-encoded string is %@", base64String); // prints "U29tZSBzYW1wbGUgZGF0YQ=="
- NSData* dataFromString = [[NSData alloc] initWithBase64EncodedString:base64String options:0];
- NSLog(@"String is %@",[NSString stringWithUTF8String:[dataFromString bytes]]); // prints "String is Some sample data"
- /* These methods first appeared in NSData.h on OS X 10.9 and iOS 7.0. They are deprecated in the same releases in favor of
the methods in the <code>NSDataBase64Encoding</code> category. However, these methods have existed for several releases, so- they may be used for applications targeting releases prior to OS X 10.9 and iOS 7.0.
- */
- - (id)initWithBase64Encoding:(NSString *)base64String;
- - (NSString *)base64Encoding;
- AVSpeechSynthesizer *synthesizer = [[AVSpeechSynthesizer alloc] init];
- AVSpeechUtterance *utterance =
- [AVSpeechUtterance speechUtteranceWithString:@"Wow, I have such a nice voice!"];
- utterance.rate = AVSpeechUtteranceMaximumSpeechRate / 4.0f;
- utterance.voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"en-US"]; // defaults to your system language
- [synthesizer speakUtterance:utterance];
- UIScreenEdgePanGestureRecognizer *recognizer = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:
- @selector(handleScreenEdgeRecognizer:)];
- recognizer.edges = UIRectEdgeLeft; // accept gestures that start from the left; we're probably building another hamburger menu!
- [self.view addGestureRecognizer:recognizer];
- UIScrollViewKeyboardDismissModeNone // the keyboard is not dismissed automatically when scrolling
- UIScrollViewKeyboardDismissModeOnDrag // dismisses the keyboard when a drag begins
- UIScrollViewKeyboardDismissModeInteractive // the keyboard follows the dragging touch off screen, and may be
- pulled upward again to cancel the dismiss
- UIImage *image = [UIImage imageNamed:@"myImage"];
- CIDetector *detector = [CIDetector detectorOfType:CIDetectorTypeFace
- context:nil
- options:@{CIDetectorAccuracy: CIDetectorAccuracyHigh}];
- NSDictionary *options = @{ CIDetectorSmile: @YES, CIDetectorEyeBlink: @YES };
- NSArray *features = [detector featuresInImage:image.CIImage options:options];
- for (CIFaceFeature *feature in features) {
- NSLog(@"Bounds: %@", NSStringFromCGRect(feature.bounds));
- if (feature.hasSmile) {
- NSLog(@"Nice smile!");
- } else {
- NSLog(@"Why so serious?");
- }
- if (feature.leftEyeClosed || feature.rightEyeClosed) {
- NSLog(@"Open your eyes!");
- }
- }
- NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:@"This is an example by @marcelofabri_"];
- [attributedString addAttribute:NSLinkAttributeName
- value:@"username://marcelofabri_"
- range:[[attributedString string] rangeOfString:@"@marcelofabri_"]];
- NSDictionary *linkAttributes = @{NSForegroundColorAttributeName: [UIColor greenColor],
- NSUnderlineColorAttributeName: [UIColor lightGrayColor],
- NSUnderlineStyleAttributeName: @(NSUnderlinePatternSolid)};
- // assume that textView is a UITextView previously created (either by code or Interface Builder)
- textView.linkTextAttributes = linkAttributes; // customizes the appearance of links
- textView.attributedText = attributedString;
- textView.delegate = self;
- - (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange {
- if ([[URL scheme] isEqualToString:@"username"]) {
- NSString *username = [URL host];
- // do something with this username
- // ...
- return NO;
- }
- return YES; // let the system open this URL
- }
联系客服