zoukankan      html  css  js  c++  java
  • iOS开发经验总结一

    1、使用%zd打印NSInteger ,%tu打印NSUInteger

    2、UIScrollView在iOS7中使用了Autolayout导致不能滚动,方法是添加scrollview的content高度

    3、UICollectionView的数据不够,无法滑动,解决方案:tableview的数据无论多少,它的界面默认都是可以滑动的,和tableview相比collectionview的数据较少不够一个屏幕是它无法滑动collectionview.alwaysBounceVertical=YES;设置总能垂直滑动就行。

    4、直接ios7的连续跳转

    -(void)back

    {

    [self dismissViewControllerAnimated:YES completion:^{

    if([weakself.navigationController popViewControllerAnimated:YES]){

    }

    }];
    }

    5、ios8以后用WKWebView代替UIWebView,ios8之前使用UIWebView进行html的展示,使用UIWebView存在内存占用过大并不释放问题。WKWebView解决内存占用过大问题

    6、企业证书下载版本可在APP中直接打开,在APP中有H5的页面,可以直接点击进行其他应用的下载

    7、URL转码问题,

    stringByAddingPercentEscapesUsingEncoding,ios9版本中需要使用

    stringByAddingPercentEncodingWithAllowedCharacters替代之前stringByAddingPercentEscapesUsingEncoding。

    8、iOS 开发,工程中混合使用 ARC 和非ARC

    Xcode 项目中我们可以使用 ARC 和非 ARC 的混合模式。

    如果你的项目使用的非 ARC 模式,则为 ARC 模式的代码文件加入 -fobjc-arc 标签。

    如果你的项目使用的是 ARC 模式,则为非 ARC 模式的代码文件加入 -fno-objc-arc 标签。

    添加标签的方法:打开:你的target -> Build Phases -> Compile Sources 2、双击对应的 *.m 文件 3、在弹出窗口中输入上面提到的标签 -fobjc-arc / -fno-objc-arc 4、点击 done 保存

    9、

    微信分享的时候注意大小

    text 的大小必须 大于0 小于 10k

    image 必须 小于 64k

    url 必须 大于 0k

    10、APNS推送

    推送的 pem 文件的生成:

    pem 证书是服务器向苹果服务器做推送时候需要的文件。

    • 打开 Keychain Access,在 Certificates 里面找到推送的证书。

    • 分别将 certificate 和 private key 导出得到.p12 文件。例如:

    Apple Development Push Services > Export “Apple Development Push Services ID123”,保存为 apns-dev-cert.p12。 对“Private Key”做同样操作,保存为 apns-dev-key.p12 文件。

    • 需要通过终端命令将这些文件转换为 PEM 格式:
    openssl pkcs12 -clcerts -nokeys -out apns-dev-cert.pem -in apns-dev-cert.p12
    openssl pkcs12 -nocerts -out apns-dev-key.pem -in apns-dev-key.p12
    此处要求输入一个密码,输入 123456.

    • 移除密码(上面的 123456)
      openssl rsa -in apns-dev-key.pem -out apns-dev-key.pem

    • 最后,你需要将键和许可文件合成为 apns-dev.pem 文件,此文 件在连接到 APNS 时需要使用:
      cat apns-dev-cert.pem apns-dev-key.pem > apns-dev.pem

      同样 Distribution Certificate 的 pem 文件生成方式一样。
      openssl pkcs12 -clcerts -nokeys -out apns-dis-cert.pem -in apns-dis-cert.p12
      openssl pkcs12 -nocerts -out apns-dis-key.pem -in apns-dis-key.p12 openssl rsa -in apns-dis-key.pem -out apns-dis-key.pem
      cat apns-dis-cert.pem apns-dis-key.pem > apns-dis.pem 

    // IOS8 新系统需要使用新的代码咯

    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)

    {

        [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings 

         settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge)      

    categories:nil]];

     

     

        [[UIApplication sharedApplication] registerForRemoteNotifications];

    }

    else

    {

    //这里还是原来的代码

        [[UIApplication sharedApplication] registerForRemoteNotificationTypes:

         (UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)];

    }

    原本在IOS7当中 判断PUSH是否打开的方法是:

    UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];

    return (types & UIRemoteNotificationTypeAlert);

     

     

    如果将这段代码使用在 IOS当中,虽然不会出现crash的现象,但是基本没什么作用。

    在IOS8中,我们使用如下的新代码来取代以上的代码

     

     

    {

    UIRemoteNotificationType types;

    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)

       {

     types = [[UIApplication sharedApplication] currentUserNotificationSettings].types;

        }

    else

       {

     types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];

        }

     

     

    return (types & UIRemoteNotificationTypeAlert);

    }

  • 相关阅读:
    浅析C#中的Thread ThreadPool Task和async/await
    C#中的集合类型
    WPF: StaticResource vs DynamicResource
    .NET程序员需要了解的概念、名词、术语--持续更新
    VisualStudio常见问题
    一些有用的.NET开源库--持续更新
    在MSBuild中使用Task实现自动引用指定版本的NuGet包
    C#与JMS的连接问题
    EventLog学习记录
    windows app设计原则总结-持续更新...
  • 原文地址:https://www.cnblogs.com/y16879w/p/6434468.html
Copyright © 2011-2022 走看看