利用系統的UIPasteboard可以檢測到系統剪切板是上的內容
首先在Appdelegate中
-(void)applicationWillEnterForeground:(UIApplication*)application {
NSLog(@”程序重新加載”);
[self getInvitationPush];
}
//[self getInvitationPush] 這個方法也要在- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 中調用
接下來:
- (void)getInvitationPush
{
UIPasteboard* pasteboard= [UIPasteboard generalPasteboard];
if(STRING_IS_NIL(pasteboard.string) ) {
return;
}
NSString* pasteUserDefaultStr = [[NSUserDefaults standardUserDefaults]objectForKey:@"pasteboardString"];
if(![pasteboard.stringrangeOfString:@"設定的標識符"].location!=NSNotFound)
{
return;
}
if(pasteUserDefaultStr ==nil|| [pasteUserDefaultStr isEqualToString:@""] || ![pasteUserDefaultStr isEqualToString:pasteboard.string]) {
//彈出添加
UIAlertView* alert = [[UIAlertView alloc]initWithTitle:@"提示"message:@"是否使用XXX"delegate:self cancelButtonTitle:@"添加"otherButtonTitles:@"取消",nil];
alert.tag=3001;
[alertshow];
[[NSUserDefaults standardUserDefaults]setObject:pasteboard.string forKey:@"pasteboardString"];
}}
?然后在Alert中用戶點擊查看 跳入相應的頁面? 用 componentsSeparatedByString取到最后的code就可以
InvitationCodeViewController* VC = [[InvitationCodeViewControlleralloc]init]; //這是你想要跳入的界面
UINavigationController* Nav = [[UINavigationControlleralloc]initWithRootViewController:VC];
[self.window.rootViewControllerpresentViewController:Navanimated:YEScompletion:nil];
?最后建立一個單例 將code記錄下來?
?