簡單實現淘口令

利用系統的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記錄下來?



?

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容