小编Moh*_*Ali的帖子

Objective-C中的iOS 10 Rich Media推送通知(媒体附件)

我想在iOS 10推送通知中添加媒体,尤其是图像和视频,但图像无法正常推送.如何在Objective-C中做到这一点?我的守则如下:

AppDelegate.h

#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
#import <UserNotifications/UserNotifications.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate,CLLocationManagerDelegate,UNUserNotificationCenterDelegate>

@property (strong, nonatomic) UIWindow *window;
@end
Run Code Online (Sandbox Code Playgroud)

AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    if(SYSTEM_VERSION_LESS_THAN( @"10.0" )) {
        [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
        [[UIApplication sharedApplication] registerForRemoteNotifications];
    } else{
        UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
        center.delegate = self;
        [center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error)
        {
            if( !error ) {
                [[UIApplication sharedApplication] registerForRemoteNotifications];
                // required to get the app to …
Run Code Online (Sandbox Code Playgroud)

objective-c ios ios10

12
推荐指数
2
解决办法
1万
查看次数

如何从NSObject类获取导航控制器并在ios中推送视图控制器

我在静态库项目中工作,我想在iOS项目的导航控制器中推送视图控制器我该怎么办?我这样做如下:

  UIStoryboard * storyboard = [[[UIApplication sharedApplication] keyWindow] rootViewController].storyboard;
UIViewController* pushtoVC = [storyboard instantiateViewControllerWithIdentifier:@"home"];
UINavigationController *navController = [[[[UIApplication sharedApplication] keyWindow]rootViewController] navigationController];
[navController pushViewController:pushtoVC animated:YES];
Run Code Online (Sandbox Code Playgroud)

我也尝试了以下代码,但它不是推动视图控制器.

  UIStoryboard * storyboard = [[[UIApplication sharedApplication] keyWindow] rootViewController].storyboard;
UIViewController* pushtoVC = [storyboard instantiateViewControllerWithIdentifier:@"home"];
UINavigationController *navController = [[[[UIApplication sharedApplication] keyWindow]rootViewController] navigationController];
[navController pushViewController:pushtoVC animated:YES];
Run Code Online (Sandbox Code Playgroud)

但是如果我在模态上使用当前视图控制器它正在工作但导航控制器仅隐藏View控制器已加载.在没有导航控制器的情况下模拟呈现的代码如下.

 UIStoryboard * storyboard = [[[UIApplication sharedApplication] keyWindow] rootViewController].storyboard;
            if ([[storyboard valueForKey:@"identifierToNibNameMap"] objectForKey:@"home"]) {
                // the view controller exists, instantiate it here
                UIViewController* myVC = [storyboard instantiateViewControllerWithIdentifier:@"home"];
                myVC.modalPresentationStyle = UIModalPresentationFullScreen;
                [[[[UIApplication sharedApplication]keyWindow] …
Run Code Online (Sandbox Code Playgroud)

objective-c uinavigationcontroller ios

0
推荐指数
1
解决办法
4395
查看次数

标签 统计

ios ×2

objective-c ×2

ios10 ×1

uinavigationcontroller ×1