Today Extension / widget programming

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/sinat_30657013/article/details/61195807

Today Extension is a new feature introduced in iOS8, if needed to obtain information in real time, you can create an extension implemented in Today's Today view of Notification Center, also known as Extended Today Widget. Based XCode8 introduced.

If the need to expand the program and the main program to exchange information directly, it is necessary to apply the group ID (group id), i.e. in the main application App ID Bundle ID Bundle ID and expansion program to set, as in FIG.


Then create Today in XCode in:



Once created the directory structure is as follows:


Then Target - Capabilities App Groups will open, and the corresponding ID added


Then modify Xib or can be constructed with the code Today, the final effect is as follows:


Traditional values ​​to the main program:

[self.extensionContext openURL:[NSURL URLWithString:@"Test://Test=open"] completionHandler:^(BOOL success) {

    }];


Test: // with the parameters can be back in Appdelegate

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation

Acquired by url



important point:

Self . preferredContentSize = CGSizeMake ( 0 , 110 ); // set the height 110


// indent   iOS10 invalid after

- (UIEdgeInsets)widgetMarginInsetsForProposedMarginInsets:(UIEdgeInsets)defaultMarginInsets{

    return  UIEdgeInsetsZero;

}









Guess you like

Origin blog.csdn.net/sinat_30657013/article/details/61195807