iOS_Pass iOS10适配:权限访问、MiPush小米推送(更新中)

iOS10官方文档原版

翻译

Pass_1

iOS10 相册,相机内的提示文字变成了英文,比如,取消(cancel),完成(complete)等,解决方法

在项目的info.plist里面添加Localized resources can be mixed
值为 YES

Pass_2

iOS10 权限设置,相机、相册、地理位置、蓝牙等获取权限崩溃,解决方法

在项目的info.plist里边添加相关的权限key及其提示语言如图所示,左侧是权限key,右侧填写需要的提示语言。

Pass_3

iOS10 MiPush 小米推送适配

截止2016-09-18 18:03发文小米推送没有针对iOS10作出更新,(极光更新了),只能手动适配
如下:

*1,在工程中添加UserNotifications.framework

![这里写图片描述](https://img-blog.csdn.net/20160918181012196)

*2,在AppDelegate中引入头文件,并遵守协议

#import <UserNotifications/UserNotifications.h>
@interface AppDelegate () <MiPushSDKDelegate, UNUserNotificationCenterDelegate>

3,添加新的注册代码

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    if ([[UIDevice currentDevice].systemVersion floatValue] >= 10.0) {
        UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
        [center requestAuthorizationWithOptions:(UNAuthorizationOptionAlert | UNAuthorizationOptionBadge | UNAuthorizationOptionSound) completionHandler:^(BOOL granted, NSError * _Nullable error) {
            if (granted) {
                //点击允许
                NSLog(@"注册通知成功");
                [center getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {
                    NSLog(@"%@", settings);
                }];
            } else {
                //点击不允许
                NSLog(@"注册通知失败");
            }
        }];

        [MiPushSDK registerMiPush:self type:0 connect:YES];
        center.delegate = self;

    } else {
        // 注册推送,如果iOS10以下
        [MiPushSDK registerMiPush:self type:0 connect:YES];
    }
}
#pragma mark 注册push服务.
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    // 注册APNS成功, 注册deviceToken
    [MiPushSDK bindDeviceToken:deviceToken];
}

- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err {
    // 注册APNS失败.
    // 自行处理.
}

#pragma mark Local And Push Notification
//自此而下2个方法是iOS新加入的回调方法,这两个是UNUserNotificationCenterDelegate协议中的两个方法。
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
    //应用在前台收到通知 NSLog(@"========%@", notification);
    NSDictionary * userInfo = notification.request.content.userInfo;
    if([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
        [MiPushSDK handleReceiveRemoteNotification:userInfo];
    }
    completionHandler(UNNotificationPresentationOptionAlert);
}

- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler {
    //点击通知进入应用 NSLog(@"response:%@", response);
    NSDictionary * userInfo = response.notification.request.content.userInfo;
    if([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
        [MiPushSDK handleReceiveRemoteNotification:userInfo];
    }
    completionHandler();
}

//iOS10之前的方法,这保留
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
    [MiPushSDK handleReceiveRemoteNotification:userInfo];
    completionHandler(UIBackgroundFetchResultNewData);
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
    // 当同时启动APNs与内部长连接时, 把两处收到的消息合并. 通过miPushReceiveNotification返回
    [MiPushSDK handleReceiveRemoteNotification:userInfo];
}

#pragma mark MiPushSDKDelegate
- (void)miPushRequestSuccWithSelector:(NSString *)selector data:(NSDictionary *)data {
    NSLog(@"==== > %@", data);
}

- (void)miPushRequestErrWithSelector:(NSString *)selector error:(int)error data:(NSDictionary *)data {
    NSLog(@"==== > %@", data);
}

- (void)miPushReceiveNotification:(NSDictionary*)data {
    // 1.当启动长连接时, 收到消息会回调此处
    // 2.[MiPushSDK handleReceiveRemoteNotification]
    //   当使用此方法后会把APNs消息导入到此
}

虽然这个可以解决收发push的问题,但是还是希望MiPush可以更新。

Pass_4

UIApplication对象中openUrl被废弃

在iOS 10全新的推出了[UIApplication sharedApplication] openURL:nil options:nil completionHandler:^(BOOL success);有一个成功的回调block 可以进行监视。目前来说,以前的openUrl方法还能用。最好来说是要根据版本做适配

Pass_5

iOS版本检查

下边的方法不可以再继续使用了

 [[[UIDevice currentDevice] systemVersion] substringToIndex:1]

因为substringToIndex:1 in SDK ‘iOS 10.0’(Xcode 8) means SDK ‘iOS 1.0’
可以换成

[UIDevice currentDevice].systemVersion.floatValue
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值