| iOS7通知中心插件框架从逆向到实现 (By飘云)
 https://www.chinapyg.com
 
 问题来源
 看到很多消息中心插件非常酷,假设我们现在完全不知道怎么写这样的越狱插件程序,只能通过其他的方法来挖掘他 
 参考实例
 通过观察我们看到通知中心有个“股票”插件存在 通过搜索引擎我们学习到: /System/Library/WeeAppPlugins/ 存放的是通知中心的一些插件,并且为*.bundle “股票”软件存在于: /System/Library/WeeAppPlugins/StocksWeeApp.bundle 
 分析过程
 我们将StocksWeeApp 主程序和 info.plist 配置文件导出来 
 
 现在打开plist来观察下: 
 <?xml version="1.0"encoding="UTF-8"?> <!DOCTYPE plist PUBLIC"-//Apple//DTD PLIST 1.0//EN""http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict>          <key>AppBundleID</key>          <string>com.apple.stocks</string>     // 这里用来显示图标,目前只能是系统自带的          <key>BuildMachineOSBuild</key>          <string>12C54</string>          <key>CFBundleDevelopmentRegion</key>          <string>English</string>          <key>CFBundleDisplayName</key>          <string>Stock_Widget</string> // 这里用来显示 设置à通知中心 开关项的名称,股票程序是多国语言的,所以这里默认用了英文          <key>CFBundleExecutable</key>          <string>StocksWeeApp</string>          <key>CFBundleIdentifier</key>          <string>com.apple.stocksweeapp.bundle</string>          <key>CFBundleInfoDictionaryVersion</key>          <string>6.0</string>          <key>CFBundleName</key>          <string>StocksWee App</string>          <key>CFBundlePackageType</key>          <string>BNDL</string>          <key>CFBundleShortVersionString</key>          <string>1.0</string>          <key>CFBundleSignature</key>          <string>????</string>          <key>CFBundleSupportedPlatforms</key>          <array>                    <string>iPhoneOS</string>          </array>          <key>CFBundleVersion</key>          <string>1</string>          <key>DTCompiler</key>          <string>com.apple.compilers.llvm.clang.1_0</string>          <key>DTPlatformBuild</key>          <string>11D201c</string>          <key>DTPlatformName</key>          <string>iphoneos</string>          <key>DTPlatformVersion</key>          <string>7.1</string>          <key>DTSDKBuild</key>          <string>11D201c</string>          <key>DTSDKName</key>          <string>iphoneos7.1.internal</string>          <key>DTXcode</key>          <string>0501</string>          <key>DTXcodeBuild</key>          <string>5A2053</string>          <key>MinimumOSVersion</key>          <string>7.1</string>          <key>SBUIWidgetViewControllers</key>          <dict>                    <key>SBUIWidgetIdiomNotificationCenterToday</key>                    <string>StocksWeeAppController</string>          </dict>  // 这一段表示显示在“今日”列表下,主类为StocksWeeAppController          <key>UIDeviceFamily</key>          <array>                    <integer>1</integer>                    <integer>2</integer>          </array> </dict> </plist> 
 上面关键地方我已经用红色标记了 
 
 OK了,现在我们class-dump来导出StocksWeeApp 
 用法: Class-dump –a –A -H StocksWeeApp –o Headers 
 得到以下文件: 
 
 现在我们打开StocksWeeAppController 看个究竟: 
 OK啦,豁然开朗了,知道消息中心要用到 _SBUIWidgetViewController类。 
 而且看到熟悉的初始化方法: -(id)initWithNibName:(id)nibNamebundle:(id)bundle;   // 0x2599 
 这个属于私有库:SpringBoardUIServices/_SBUIWidgetViewController.h 
 国外大神已经导出头文件了,详见: 
 
 OK了,现在我们从私有库里面看到下面几个文件 
 打开_SBUIWidgetViewController.h 
 可以看到: 1. _SBUIWidgetViewController  基于UIViewController 2.“股票”软件都是实现/覆盖上面的某些方法 
 然而初级阶段我们要实现的就是: @property(readonly, nonatomic) structCGSize preferredViewSize; 这个从意思来说,应该是控制区域大小的 梳理流程
 好了,现在为止分析完毕了,我们来梳理一下流程: 
 我们要编写一个程序来实现私有库 SpringBoardUIServices/_SBUIWidgetViewController.h 中 - (CGSize) preferredViewSize; -(id)initWithNibName:(id)nibNamebundle:(id)bundle;    
 从而在消息中心显示“www.chinapyg.com” 字样,并且在设置中可控 编码过程
 现在我们把私用库中下面三个文件保存到一个目录 _SBUIWidgetViewController.h _SBUIWidgetViewController_Host_IPC-Protocol.h _SBUIWidgetViewController_Remote_IPC-Protocol.h 
 改名为: _SBUIWidgetViewController.h _SBUIWidgetViewController_Host_IPC.h _SBUIWidgetViewController_Remote_IPC.h 创建工程
 现在Xcode 选择NotificationCenterWidget模板,新建一工程,命名为ShowIP(为下节课做准备啊) 
 删除自动生成的代码、并且删除BBWeeAppController.h文件、导入上面三个头文件到工程 编写代码
 并且导入私有SpringBoardUIServices库 私有库提取
 
 Plist内容
 
 现在build,然后安装到手机测试!怎么真机直接安装可以搜索论坛帖子! 效果测试
 
 
 |