传感器

/// 

很简单, 只需要在AppDelegate中写上一下代码, 就可以实现摇一摇功能.

#import "AppDelegate.h"

@interface AppDelegate ()

@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    // Override point for customization after application launch.

    return YES;

}

/**

 *  开始摇一摇就会调用

 */

- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event{

    NSLog(@"%s",__func__);

}

/**

 *  摇晃被取消就会调用

 */

- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event{

    NSLog(@"%s",__func__);

}

/**

 *  摇晃结束 就会调用

 */

- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event{

    NSLog(@"%s",__func__);

}

原文地址:https://www.cnblogs.com/guangleijia/p/4834628.html