如何在应用扩展中获取设备的当前方向,我尝试了以下两种方法但未成功。
It always return UIDeviceOrientationUnknown
[[UIDevice currentDevice] orientation]
It shows red message that ‘sharedApplication’ is not available on iOS (App Extension)
[[UIApplication sharedApplication] statusBarOrientation];
I also add an observer but it not getting called.
[[NSNotificationCenter defaultCenter] addObserver:self.view selector:@selector(notification_OrientationWillChange:) name:UIApplicationWillChangeStatusBarOrientationNotification object:nil]; - (void)notification_OrientationWillChange:(NSNotification*)n { UIInterfaceOrientation orientation = (UIInterfaceOrientation)[[n.userInfo objectForKey:UIApplicationStatusBarOrientationUserInfoKey] intValue]; if (orientation == UIInterfaceOrientationLandscapeLeft) [self.textDocumentProxy insertText:@"Left"]; if (orientation == UIInterfaceOrientationLandscapeRight) [self.textDocumentProxy insertText:@"Right"]; }
那么现在如何获取当前设备方向呢?